refactor: 适配 ContiNew Starter 图形验证码

This commit is contained in:
2023-11-24 23:45:15 +08:00
parent b7fc5a5524
commit 8a11a020e0
7 changed files with 22 additions and 152 deletions

View File

@@ -56,6 +56,7 @@ import top.charles7c.cnadmin.common.util.MailUtils;
import top.charles7c.cnadmin.common.util.TemplateUtils;
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
import top.charles7c.continew.starter.cache.redisson.util.RedisUtils;
import top.charles7c.continew.starter.captcha.graphic.autoconfigure.GraphicCaptchaProperties;
/**
* 验证码 API
@@ -73,17 +74,15 @@ public class CaptchaController {
private final CaptchaProperties captchaProperties;
private final ProjectProperties projectProperties;
private final GraphicCaptchaProperties graphicCaptchaProperties;
@Operation(summary = "获取图片验证码", description = "获取图片验证码Base64编码带图片格式data:image/gif;base64")
@GetMapping("/img")
public CaptchaResp getImageCaptcha() {
// 生成验证码
CaptchaProperties.CaptchaImage captchaImage = captchaProperties.getImage();
Captcha captcha = captchaImage.getCaptcha();
// 保存验证码
Captcha captcha = graphicCaptchaProperties.getCaptcha();
String uuid = IdUtil.fastUUID();
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, uuid);
RedisUtils.set(captchaKey, captcha.text(), Duration.ofMinutes(captchaImage.getExpirationInMinutes()));
RedisUtils.set(captchaKey, captcha.text(), Duration.ofMinutes(captchaProperties.getExpirationInMinutes()));
return CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).build();
}

View File

@@ -130,18 +130,15 @@ spring.mail:
--- ### 验证码配置
captcha:
## 图验证码配置
image:
## 图验证码配置
graphic:
enabled: true
# 类型
type: SPEC
# 内容长度
length: 4
# 过期时间
expirationInMinutes: 2
# 宽度
width: 111
# 高度
height: 36
## 邮箱验证码配置
mail:
# 内容长度

View File

@@ -132,18 +132,15 @@ spring.mail:
--- ### 验证码配置
captcha:
## 图验证码配置
image:
## 图验证码配置
graphic:
enabled: true
# 类型
type: SPEC
# 内容长度
length: 4
# 过期时间
expirationInMinutes: 2
# 宽度
width: 111
# 高度
height: 36
## 邮箱验证码配置
mail:
# 内容长度