mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-31 00:57:13 +08:00
feat: 新增验证码配置开关
This commit is contained in:
@@ -18,7 +18,9 @@ package top.continew.admin.auth.model.req;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.checkerframework.checker.units.qual.N;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -50,17 +52,20 @@ public class AccountLoginReq implements Serializable {
|
|||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@Schema(description = "是否开启验证码", example = "true")
|
||||||
|
private Boolean unCaptcha;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码
|
* 验证码
|
||||||
*/
|
*/
|
||||||
@Schema(description = "验证码", example = "ABCD")
|
@Schema(description = "验证码", example = "ABCD")
|
||||||
@NotBlank(message = "验证码不能为空")
|
// @NotBlank(message = "验证码不能为空")
|
||||||
private String captcha;
|
private String captcha;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码标识
|
* 验证码标识
|
||||||
*/
|
*/
|
||||||
@Schema(description = "验证码标识", example = "090b9a2c-1691-4fca-99db-e4ed0cff362f")
|
@Schema(description = "验证码标识", example = "090b9a2c-1691-4fca-99db-e4ed0cff362f")
|
||||||
@NotBlank(message = "验证码标识不能为空")
|
// @NotBlank(message = "验证码标识不能为空")
|
||||||
private String uuid;
|
private String uuid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,4 +38,9 @@ public enum OptionCategoryEnum {
|
|||||||
* 邮箱配置
|
* 邮箱配置
|
||||||
*/
|
*/
|
||||||
MAIL,
|
MAIL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码配置
|
||||||
|
*/
|
||||||
|
CAPTCHA,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,11 +69,13 @@ public class AuthController {
|
|||||||
@Operation(summary = "账号登录", description = "根据账号和密码进行登录认证")
|
@Operation(summary = "账号登录", description = "根据账号和密码进行登录认证")
|
||||||
@PostMapping("/account")
|
@PostMapping("/account")
|
||||||
public LoginResp accountLogin(@Validated @RequestBody AccountLoginReq loginReq, HttpServletRequest request) {
|
public LoginResp accountLogin(@Validated @RequestBody AccountLoginReq loginReq, HttpServletRequest request) {
|
||||||
|
if (!loginReq.getUnCaptcha()) {
|
||||||
String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + loginReq.getUuid();
|
String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + loginReq.getUuid();
|
||||||
String captcha = RedisUtils.get(captchaKey);
|
String captcha = RedisUtils.get(captchaKey);
|
||||||
ValidationUtils.throwIfBlank(captcha, CAPTCHA_EXPIRED);
|
ValidationUtils.throwIfBlank(captcha, CAPTCHA_EXPIRED);
|
||||||
RedisUtils.delete(captchaKey);
|
RedisUtils.delete(captchaKey);
|
||||||
ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, CAPTCHA_ERROR);
|
ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, CAPTCHA_ERROR);
|
||||||
|
}
|
||||||
// 用户登录
|
// 用户登录
|
||||||
String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(loginReq.getPassword()));
|
String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(loginReq.getPassword()));
|
||||||
ValidationUtils.throwIfBlank(rawPassword, "密码解密失败");
|
ValidationUtils.throwIfBlank(rawPassword, "密码解密失败");
|
||||||
|
|||||||
@@ -88,6 +88,15 @@ public class CaptchaController {
|
|||||||
private final GraphicCaptchaService graphicCaptchaService;
|
private final GraphicCaptchaService graphicCaptchaService;
|
||||||
private final OptionService optionService;
|
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)
|
@Log(ignore = true)
|
||||||
@Operation(summary = "获取行为验证码", description = "获取行为验证码(Base64编码)")
|
@Operation(summary = "获取行为验证码", description = "获取行为验证码(Base64编码)")
|
||||||
@GetMapping("/behavior")
|
@GetMapping("/behavior")
|
||||||
|
|||||||
@@ -143,6 +143,8 @@ VALUES
|
|||||||
(19, 'MAIL', '密码', 'MAIL_PASSWORD', NULL, NULL, NULL, NULL, NULL),
|
(19, 'MAIL', '密码', 'MAIL_PASSWORD', NULL, NULL, NULL, NULL, NULL),
|
||||||
(20, 'MAIL', '是否启用SSL', 'MAIL_SSL_ENABLED', NULL, '1', 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);
|
(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`
|
INSERT INTO `sys_dict`
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ VALUES
|
|||||||
(19, 'MAIL', '密码', 'MAIL_PASSWORD', NULL, NULL, NULL, NULL, NULL),
|
(19, 'MAIL', '密码', 'MAIL_PASSWORD', NULL, NULL, NULL, NULL, NULL),
|
||||||
(20, 'MAIL', '是否启用SSL', 'MAIL_SSL_ENABLED', NULL, '1', 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);
|
(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"
|
INSERT INTO "sys_dict"
|
||||||
|
|||||||
Reference in New Issue
Block a user