feat: 新增验证码配置开关

This commit is contained in:
Gyq灬明
2024-12-05 07:57:22 +00:00
committed by Charles7c
parent a6546375f7
commit e31434617e
6 changed files with 53 additions and 29 deletions

View File

@@ -18,7 +18,9 @@ package top.continew.admin.auth.model.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.checkerframework.checker.units.qual.N;
import java.io.Serial;
import java.io.Serializable;
@@ -50,17 +52,20 @@ public class AccountLoginReq implements Serializable {
@NotBlank(message = "密码不能为空")
private String password;
@Schema(description = "是否开启验证码", example = "true")
private Boolean unCaptcha;
/**
* 验证码
*/
@Schema(description = "验证码", example = "ABCD")
@NotBlank(message = "验证码不能为空")
// @NotBlank(message = "验证码不能为空")
private String captcha;
/**
* 验证码标识
*/
@Schema(description = "验证码标识", example = "090b9a2c-1691-4fca-99db-e4ed0cff362f")
@NotBlank(message = "验证码标识不能为空")
// @NotBlank(message = "验证码标识不能为空")
private String uuid;
}

View File

@@ -38,4 +38,9 @@ public enum OptionCategoryEnum {
* 邮箱配置
*/
MAIL,
/**
* 验证码配置
*/
CAPTCHA,
}

View File

@@ -69,11 +69,13 @@ public class AuthController {
@Operation(summary = "账号登录", description = "根据账号和密码进行登录认证")
@PostMapping("/account")
public LoginResp accountLogin(@Validated @RequestBody AccountLoginReq loginReq, HttpServletRequest request) {
if (!loginReq.getUnCaptcha()) {
String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + loginReq.getUuid();
String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, CAPTCHA_EXPIRED);
RedisUtils.delete(captchaKey);
ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, CAPTCHA_ERROR);
}
// 用户登录
String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(loginReq.getPassword()));
ValidationUtils.throwIfBlank(rawPassword, "密码解密失败");

View File

@@ -88,6 +88,15 @@ public class CaptchaController {
private final GraphicCaptchaService graphicCaptchaService;
private final OptionService optionService;
@Log(ignore = true)
@Operation(summary = "获取验证码配置", description = "获取验证码配置(预留后续扩展多种验证码)")
@GetMapping("/config")
public R getCaptchaConfig() {
Map<String, String> captchaConfig = optionService.getByCategory(OptionCategoryEnum.CAPTCHA);
return R.ok(captchaConfig);
}
@Log(ignore = true)
@Operation(summary = "获取行为验证码", description = "获取行为验证码Base64编码")
@GetMapping("/behavior")

View File

@@ -143,6 +143,8 @@ VALUES
(19, 'MAIL', '密码', 'MAIL_PASSWORD', NULL, NULL, NULL, NULL, NULL),
(20, 'MAIL', '是否启用SSL', 'MAIL_SSL_ENABLED', NULL, '1', NULL, NULL, NULL),
(21, 'MAIL', 'SSL端口', 'MAIL_SSL_PORT', NULL, '465', NULL, NULL, NULL);
(22, 'CAPTCHA', '是否开启验证码', 'NEED_CAPTCHA', '1', '1', '是否开启验证码1开启 0关闭', 1, '2024-12-04 16:19:58');
-- 初始化默认字典
INSERT INTO `sys_dict`

View File

@@ -143,6 +143,7 @@ VALUES
(19, 'MAIL', '密码', 'MAIL_PASSWORD', NULL, NULL, NULL, NULL, NULL),
(20, 'MAIL', '是否启用SSL', 'MAIL_SSL_ENABLED', NULL, '1', NULL, NULL, NULL),
(21, 'MAIL', 'SSL端口', 'MAIL_SSL_PORT', NULL, '465', NULL, NULL, NULL);
(22, 'CAPTCHA', '是否开启验证码', 'NEED_CAPTCHA', '1', '1', '是否开启验证码1开启 0关闭', 1, '2024-12-04 16:19:58');
-- 初始化默认字典
INSERT INTO "sys_dict"