fix(system): 优化用户修改邮箱和手机号功能
- 在 EmailUpdateForm 和 MobileUpdateForm 中添加了 @NotBlank 注解,确保邮箱和手机号不能为空 - 在 UserServiceImpl 中增加了验证码过期检查和验证完成后删除验证码的逻辑 - 优化了错误提示信息,提高用户体验
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.youlai.boot.system.model.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -9,14 +10,16 @@ import lombok.Data;
|
||||
* @author Ray.Hao
|
||||
* @since 2024/8/19
|
||||
*/
|
||||
@Schema(description = "修改邮箱表单")
|
||||
@Data
|
||||
@Schema(description = "修改邮箱表单")
|
||||
public class EmailUpdateForm {
|
||||
|
||||
@Schema(description = "邮箱")
|
||||
@NotBlank(message = "邮箱不能为空")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "验证码")
|
||||
@NotBlank(message = "验证码不能为空")
|
||||
private String code;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.youlai.boot.system.model.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -14,9 +15,11 @@ import lombok.Data;
|
||||
public class MobileUpdateForm {
|
||||
|
||||
@Schema(description = "手机号码")
|
||||
@NotBlank(message = "手机号码不能为空")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "验证码")
|
||||
@NotBlank(message = "验证码不能为空")
|
||||
private String code;
|
||||
|
||||
}
|
||||
|
||||
@@ -451,9 +451,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
String redisCacheKey = RedisConstants.SMS_CHANGE_CODE_PREFIX + mobile;
|
||||
String cachedVerifyCode = redisTemplate.opsForValue().get(redisCacheKey);
|
||||
|
||||
if (StrUtil.isBlank(cachedVerifyCode)) {
|
||||
throw new BusinessException("验证码已过期");
|
||||
}
|
||||
if (!inputVerifyCode.equals(cachedVerifyCode)) {
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
// 验证完成删除验证码
|
||||
redisTemplate.delete(redisCacheKey);
|
||||
|
||||
// 更新手机号码
|
||||
return this.update(
|
||||
@@ -505,9 +510,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
String redisCacheKey = RedisConstants.EMAIL_CHANGE_CODE_PREFIX + email;
|
||||
String cachedVerifyCode = redisTemplate.opsForValue().get(redisCacheKey);
|
||||
|
||||
if (StrUtil.isBlank(cachedVerifyCode)) {
|
||||
throw new BusinessException("验证码已过期");
|
||||
}
|
||||
|
||||
if (!inputVerifyCode.equals(cachedVerifyCode)) {
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
// 验证完成删除验证码
|
||||
redisTemplate.delete(redisCacheKey);
|
||||
|
||||
// 更新邮箱地址
|
||||
return this.update(
|
||||
|
||||
Reference in New Issue
Block a user