feat(user): 新增邮箱验证码发送接口与校验
- 拆分验证码发送逻辑至独立接口 /sendVerifyMail - 注册时增加验证码校验与 VERIFY_CODE_ERROR 错误码 - 新增 SendMailDTO 封装邮箱地址参数
This commit is contained in:
@@ -34,7 +34,8 @@ public enum ErrorCode {
|
||||
SEND_MAIL_FAILED(50004,"邮件发送失败" ),
|
||||
CONFIRM_PASSWORD_NOT_MATCH(50005,"重复密码不匹配" ),
|
||||
USER_CHARACTER_ADD_ERROR(50006,"添加用户键盘字符失败" ),
|
||||
USER_CHARACTER_DEL_ERROR(50007, "删除用户人设失败");
|
||||
USER_CHARACTER_DEL_ERROR(50007, "删除用户人设失败"),
|
||||
VERIFY_CODE_ERROR(50008, "验证码错误");
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
|
||||
@@ -86,4 +86,12 @@ public class UserController {
|
||||
userService.userRegister(userRegisterDTO);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/sendVerifyMail")
|
||||
@Operation(summary = "发送验证码",description = "发送验证码接口")
|
||||
public BaseResponse<Boolean> sendVerifyMail(@RequestBody UserRegisterDTO userRegisterDTO) {
|
||||
userService.sendVerifyMail(userRegisterDTO);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.yolo.keyborad.model.dto.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/4 17:00
|
||||
*/
|
||||
@Data
|
||||
public class SendMailDTO {
|
||||
|
||||
@Schema(description = "邮箱地址")
|
||||
private String mailAddress;
|
||||
}
|
||||
@@ -21,4 +21,7 @@ public class UserRegisterDTO {
|
||||
|
||||
@Schema(description = "性别")
|
||||
private Integer gender;
|
||||
|
||||
@Schema(description = "验证码")
|
||||
private String verifyCode;
|
||||
}
|
||||
|
||||
@@ -23,4 +23,5 @@ public interface UserService extends IService<KeyboardUser> {
|
||||
|
||||
Boolean userRegister(UserRegisterDTO userRegisterDTO);
|
||||
|
||||
void sendVerifyMail(UserRegisterDTO userRegisterDTO);
|
||||
}
|
||||
|
||||
@@ -118,9 +118,17 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
|
||||
keyboardUser.setEmail(userRegisterDTO.getMailAddress());
|
||||
keyboardUser.setGender(userRegisterDTO.getGender());
|
||||
log.info(keyboardUser.toString());
|
||||
int code = RandomUtil.randomInt(100000, 999999);
|
||||
redisUtil.setEx("user:"+userRegisterDTO.getMailAddress(), String.valueOf(code),600, TimeUnit.SECONDS);
|
||||
sendMailUtils.sendEmail(keyboardUser.getNickName(),userRegisterDTO.getMailAddress(),code);
|
||||
String s = redisUtil.get("user" + userRegisterDTO.getMailAddress());
|
||||
if (!s.equals(userRegisterDTO.getVerifyCode())) {
|
||||
throw new BusinessException(ErrorCode.VERIFY_CODE_ERROR);
|
||||
}
|
||||
return keyboardUserMapper.insert(keyboardUser) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendVerifyMail(UserRegisterDTO userRegisterDTO) {
|
||||
int code = RandomUtil.randomInt(100000, 999999);
|
||||
redisUtil.setEx("user:"+userRegisterDTO.getMailAddress(), String.valueOf(code),600, TimeUnit.SECONDS);
|
||||
sendMailUtils.sendEmail(null,userRegisterDTO.getMailAddress(),code);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user