feat(auth): 添加邮箱验证码校验接口
- 在EmailCaptchaParam中新增验证码字段code,用于验证码校验 - 新增/verifyEmailCaptcha接口,支持邮箱验证码的校验逻辑 - 实现邮箱格式和验证码非空校验,提供错误反馈 - 验证通过后删除Redis中对应验证码,防止重复使用 - 支持开发环境验证码验证,方便调试验证流程
This commit is contained in:
@@ -877,6 +877,31 @@ public class MainController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "校验邮箱验证码")
|
||||
@PostMapping("/verifyEmailCaptcha")
|
||||
public ApiResult<?> verifyEmailCaptcha(@RequestBody EmailCaptchaParam param) {
|
||||
if (param == null || StrUtil.isBlank(param.getEmail())) {
|
||||
return fail("邮箱不能为空");
|
||||
}
|
||||
if (!CommonUtil.isValidEmail(param.getEmail())) {
|
||||
return fail("请输入有效的邮箱地址");
|
||||
}
|
||||
if (StrUtil.isBlank(param.getCode())) {
|
||||
return fail("验证码不能为空");
|
||||
}
|
||||
// 与 sendEmailCaptcha 写入的 key 保持一致:emailCode:邮箱
|
||||
String key = RedisConstants.EMAIL_CODE_KEY + ":" + param.getEmail();
|
||||
String cachedCode = redisUtil.get(key);
|
||||
String devCode = redisUtil.get(CACHE_KEY_VERIFICATION_CODE_BY_DEV_SMS);
|
||||
if (cachedCode == null
|
||||
|| (!param.getCode().equals(cachedCode) && !param.getCode().equals(devCode))) {
|
||||
return fail("邮箱验证码不正确");
|
||||
}
|
||||
// 校验通过即删除,防止重复使用
|
||||
redisUtil.delete(key);
|
||||
return success("邮箱验证通过");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@Operation(summary = "重置密码")
|
||||
@PutMapping("/password")
|
||||
|
||||
@@ -21,6 +21,9 @@ public class EmailCaptchaParam implements Serializable {
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "邮箱验证码(校验时使用)")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "租户ID")
|
||||
private String tenantId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user