From ce88adaccfb1d0f28057ccc8fbb13c759102a934 Mon Sep 17 00:00:00 2001
From: yaowanxin <3588231647@qq.com>
Date: 星期二, 23 九月 2025 09:46:36 +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