From 3d03a5b3193f98929561ea11a37ef8d8b12a4b06 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期四, 11 一月 2024 23:21:24 +0800 Subject: [PATCH] fix 修复 用户登录查询部门缓存无法获取租户id问题 --- ruoyi-admin/src/main/java/org/dromara/web/controller/CaptchaController.java | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ruoyi-admin/src/main/java/org/dromara/web/controller/CaptchaController.java b/ruoyi-admin/src/main/java/org/dromara/web/controller/CaptchaController.java index 3977e30..ef33f5b 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/controller/CaptchaController.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/controller/CaptchaController.java @@ -13,10 +13,12 @@ import org.dromara.common.core.utils.reflect.ReflectUtils; import org.dromara.common.mail.config.properties.MailProperties; import org.dromara.common.mail.utils.MailUtils; +import org.dromara.common.ratelimiter.annotation.RateLimiter; +import org.dromara.common.ratelimiter.enums.LimitType; import org.dromara.common.redis.utils.RedisUtils; -import org.dromara.common.sms.config.properties.SmsProperties; import org.dromara.common.web.config.properties.CaptchaProperties; import org.dromara.common.web.enums.CaptchaType; +import org.dromara.sms4j.api.SmsBlend; import org.dromara.sms4j.api.entity.SmsResponse; import org.dromara.sms4j.core.factory.SmsFactory; import org.dromara.sms4j.provider.enumerate.SupplierType; @@ -47,7 +49,6 @@ public class CaptchaController { private final CaptchaProperties captchaProperties; - private final SmsProperties smsProperties; private final MailProperties mailProperties; /** @@ -55,19 +56,18 @@ * * @param phonenumber 鐢ㄦ埛鎵嬫満鍙� */ + @RateLimiter(key = "#phonenumber", time = 60, count = 1) @GetMapping("/resource/sms/code") public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) { - if (!smsProperties.getEnabled()) { - return R.fail("褰撳墠绯荤粺娌℃湁寮�鍚煭淇″姛鑳斤紒"); - } String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber; String code = RandomUtil.randomNumbers(4); RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); // 楠岃瘉鐮佹ā鏉縤d 鑷澶勭悊 (鏌ユ暟鎹簱鎴栧啓姝诲潎鍙�) - String templateId = "SMS_460945446"; + String templateId = ""; LinkedHashMap<String, String> map = new LinkedHashMap<>(1); map.put("code", code); - SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ALIBABA).sendMessage(phonenumber, templateId, map); + SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA); + SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map); if (!"OK".equals(smsResponse.getCode())) { log.error("楠岃瘉鐮佺煭淇″彂閫佸紓甯� => {}", smsResponse); return R.fail(smsResponse.getMessage()); @@ -80,6 +80,7 @@ * * @param email 閭 */ + @RateLimiter(key = "#email", time = 60, count = 1) @GetMapping("/resource/email/code") public R<Void> emailCode(@NotBlank(message = "{user.email.not.blank}") String email) { if (!mailProperties.getEnabled()) { @@ -100,7 +101,8 @@ /** * 鐢熸垚楠岃瘉鐮� */ - @GetMapping("/code") + @RateLimiter(time = 60, count = 10, limitType = LimitType.IP) + @GetMapping("/auth/code") public R<CaptchaVo> getCode() { CaptchaVo captchaVo = new CaptchaVo(); boolean captchaEnabled = captchaProperties.getEnable(); -- Gitblit v1.9.3