From ff8206323dc1b88c9373a3ee5cf5cb8e86ef60d0 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期六, 30 七月 2022 14:00:32 +0800
Subject: [PATCH] 支持配置密码最大错误次数/锁定时间

---
 src/main/java/com/ruoyi/project/common/CaptchaController.java |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/ruoyi/project/common/CaptchaController.java b/src/main/java/com/ruoyi/project/common/CaptchaController.java
index 68823fc..13dd70f 100644
--- a/src/main/java/com/ruoyi/project/common/CaptchaController.java
+++ b/src/main/java/com/ruoyi/project/common/CaptchaController.java
@@ -12,11 +12,13 @@
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
 import com.google.code.kaptcha.Producer;
+import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.constant.Constants;
-import com.ruoyi.common.utils.IdUtils;
 import com.ruoyi.common.utils.sign.Base64;
+import com.ruoyi.common.utils.uuid.IdUtils;
 import com.ruoyi.framework.redis.RedisCache;
 import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.project.system.service.ISysConfigService;
 
 /**
  * 楠岃瘉鐮佹搷浣滃鐞�
@@ -26,7 +28,6 @@
 @RestController
 public class CaptchaController
 {
-
     @Resource(name = "captchaProducer")
     private Producer captchaProducer;
 
@@ -39,6 +40,9 @@
     // 楠岃瘉鐮佺被鍨�
     @Value("${ruoyi.captchaType}")
     private String captchaType;
+    
+    @Autowired
+    private ISysConfigService configService;
 
     /**
      * 鐢熸垚楠岃瘉鐮�
@@ -46,9 +50,17 @@
     @GetMapping("/captchaImage")
     public AjaxResult getCode(HttpServletResponse response) throws IOException
     {
+        AjaxResult ajax = AjaxResult.success();
+        boolean captchaEnabled = configService.selectCaptchaEnabled();
+        ajax.put("captchaEnabled", captchaEnabled);
+        if (!captchaEnabled)
+        {
+            return ajax;
+        }
+
         // 淇濆瓨楠岃瘉鐮佷俊鎭�
         String uuid = IdUtils.simpleUUID();
-        String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
+        String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
 
         String capStr = null, code = null;
         BufferedImage image = null;
@@ -79,7 +91,6 @@
             return AjaxResult.error(e.getMessage());
         }
 
-        AjaxResult ajax = AjaxResult.success();
         ajax.put("uuid", uuid);
         ajax.put("img", Base64.encode(os.toByteArray()));
         return ajax;

--
Gitblit v1.9.3