Commit 6a7761313e21182d91096fc1fbe7953c976644a3
1 parent
8e0569ee
[updaate] 拆分修改密码与重置密码请求实体
Showing
7 changed files
with
47 additions
and
32 deletions
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.java
| ... | ... | @@ -80,7 +80,8 @@ public class SysAuthController { |
| 80 | 80 | |
| 81 | 81 | @PostMapping("/reset-password") |
| 82 | 82 | @ApiOperation(value = "重置密码", notes = "用户忘记密码时使用") |
| 83 | - public CommonResult<Boolean> resetPassword(@RequestBody @Validated(MbrAuthResetPasswordReqVO.resetPasswordValidView.class) MbrAuthResetPasswordReqVO reqVO) { | |
| 83 | + @PreAuthenticated | |
| 84 | + public CommonResult<Boolean> resetPassword(@RequestBody @Valid MbrAuthResetPasswordReqVO reqVO) { | |
| 84 | 85 | authService.resetPassword(reqVO); |
| 85 | 86 | return success(true); |
| 86 | 87 | } |
| ... | ... | @@ -88,7 +89,7 @@ public class SysAuthController { |
| 88 | 89 | @PostMapping("/update-password") |
| 89 | 90 | @ApiOperation(value = "修改用户密码",notes = "用户修改密码时使用") |
| 90 | 91 | @PreAuthenticated |
| 91 | - public CommonResult<Boolean> updatePassword(@RequestBody @Validated(MbrAuthResetPasswordReqVO.updatePasswordValidView.class) MbrAuthResetPasswordReqVO reqVO) { | |
| 92 | + public CommonResult<Boolean> updatePassword(@RequestBody @Valid MbrAuthUpdatePasswordReqVO reqVO) { | |
| 92 | 93 | authService.updatePassword(getLoginUserId(), reqVO); |
| 93 | 94 | return success(true); |
| 94 | 95 | } | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthResetPasswordReqVO.java
| ... | ... | @@ -19,30 +19,13 @@ import javax.validation.constraints.Pattern; |
| 19 | 19 | @Builder |
| 20 | 20 | public class MbrAuthResetPasswordReqVO { |
| 21 | 21 | |
| 22 | - /** | |
| 23 | - * 修改密码校验规则 | |
| 24 | - */ | |
| 25 | - public interface updatePasswordValidView { | |
| 26 | - } | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 忘记密码校验规则 | |
| 30 | - */ | |
| 31 | - public interface resetPasswordValidView { | |
| 32 | - } | |
| 33 | - | |
| 34 | - @ApiModelProperty(value = "用户旧密码", required = true, example = "123456") | |
| 35 | - @NotBlank(message = "旧密码不能为空",groups = updatePasswordValidView.class) | |
| 36 | - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | |
| 37 | - private String oldPassword; | |
| 38 | - | |
| 39 | 22 | @ApiModelProperty(value = "新密码", required = true, example = "buzhidao") |
| 40 | - @NotEmpty(message = "新密码不能为空",groups = {updatePasswordValidView.class,resetPasswordValidView.class}) | |
| 23 | + @NotEmpty(message = "新密码不能为空") | |
| 41 | 24 | @Length(min = 4, max = 16, message = "密码长度为 4-16 位") |
| 42 | 25 | private String password; |
| 43 | 26 | |
| 44 | 27 | @ApiModelProperty(value = "手机验证码", required = true, example = "1024") |
| 45 | - @NotEmpty(message = "手机验证码不能为空",groups = resetPasswordValidView.class) | |
| 28 | + @NotEmpty(message = "手机验证码不能为空") | |
| 46 | 29 | @Length(min = 4, max = 6, message = "手机验证码长度为 4-6 位") |
| 47 | 30 | @Pattern(regexp = "^[0-9]+$", message = "手机验证码必须都是数字") |
| 48 | 31 | private String code; | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthUpdatePasswordReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.AllArgsConstructor; | |
| 6 | +import lombok.Builder; | |
| 7 | +import lombok.Data; | |
| 8 | +import lombok.NoArgsConstructor; | |
| 9 | +import org.hibernate.validator.constraints.Length; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.NotBlank; | |
| 12 | +import javax.validation.constraints.NotEmpty; | |
| 13 | + | |
| 14 | +@ApiModel("修改密码 Request VO") | |
| 15 | +@Data | |
| 16 | +@NoArgsConstructor | |
| 17 | +@AllArgsConstructor | |
| 18 | +@Builder | |
| 19 | +public class MbrAuthUpdatePasswordReqVO { | |
| 20 | + | |
| 21 | + @ApiModelProperty(value = "用户旧密码", required = true, example = "123456") | |
| 22 | + @NotBlank(message = "旧密码不能为空") | |
| 23 | + @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | |
| 24 | + private String oldPassword; | |
| 25 | + | |
| 26 | + @ApiModelProperty(value = "新密码", required = true, example = "buzhidao") | |
| 27 | + @NotEmpty(message = "新密码不能为空") | |
| 28 | + @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | |
| 29 | + private String password; | |
| 30 | +} | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/SysAuthService.java
| ... | ... | @@ -68,7 +68,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { |
| 68 | 68 | * @param userId 用户id |
| 69 | 69 | * @param userReqVO 用户请求实体类 |
| 70 | 70 | */ |
| 71 | - void updatePassword(Long userId, MbrAuthResetPasswordReqVO userReqVO); | |
| 71 | + void updatePassword(Long userId, @Valid MbrAuthUpdatePasswordReqVO userReqVO); | |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * 忘记密码 | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java
| ... | ... | @@ -25,7 +25,6 @@ import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; |
| 25 | 25 | import com.google.common.annotations.VisibleForTesting; |
| 26 | 26 | import lombok.extern.slf4j.Slf4j; |
| 27 | 27 | import me.zhyd.oauth.model.AuthUser; |
| 28 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 29 | 28 | import org.springframework.context.annotation.Lazy; |
| 30 | 29 | import org.springframework.data.redis.core.StringRedisTemplate; |
| 31 | 30 | import org.springframework.security.authentication.AuthenticationManager; |
| ... | ... | @@ -41,6 +40,7 @@ import org.springframework.stereotype.Service; |
| 41 | 40 | import org.springframework.transaction.annotation.Transactional; |
| 42 | 41 | |
| 43 | 42 | import javax.annotation.Resource; |
| 43 | +import javax.validation.Valid; | |
| 44 | 44 | import java.util.List; |
| 45 | 45 | import java.util.Objects; |
| 46 | 46 | |
| ... | ... | @@ -280,7 +280,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | @Override |
| 283 | - public void updatePassword(Long userId, MbrAuthResetPasswordReqVO reqVO) { | |
| 283 | + public void updatePassword(Long userId, @Valid MbrAuthUpdatePasswordReqVO reqVO) { | |
| 284 | 284 | // 检验旧密码 |
| 285 | 285 | MbrUserDO userDO = checkOldPassword(userId, reqVO.getOldPassword()); |
| 286 | 286 | ... | ... |
yudao-user-server/src/test/java/cn/iocoder/yudao/userserver/modules/member/service/MbrUserServiceImplTest.java
| ... | ... | @@ -120,7 +120,6 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 120 | 120 | |
| 121 | 121 | // 验证旧手机验证码是否正确 |
| 122 | 122 | sysSmsCodeService.useSmsCode(oldMobile,SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene(),"123","1.1.1.1"); |
| 123 | - | |
| 124 | 123 | // 验证新手机 |
| 125 | 124 | SysAuthSendSmsReqVO smsReqVO = new SysAuthSendSmsReqVO(); |
| 126 | 125 | smsReqVO.setMobile(oldMobile); | ... | ... |
yudao-user-server/src/test/java/cn/iocoder/yudao/userserver/modules/system/service/SysAuthServiceTest.java
| ... | ... | @@ -16,6 +16,7 @@ import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; |
| 16 | 16 | import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; |
| 17 | 17 | import cn.iocoder.yudao.userserver.modules.member.service.user.impl.MbrUserServiceImpl; |
| 18 | 18 | import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.MbrAuthResetPasswordReqVO; |
| 19 | +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.MbrAuthUpdatePasswordReqVO; | |
| 19 | 20 | import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; |
| 20 | 21 | import cn.iocoder.yudao.userserver.modules.system.service.auth.impl.SysAuthServiceImpl; |
| 21 | 22 | import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; |
| ... | ... | @@ -78,9 +79,10 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { |
| 78 | 79 | String newPassword = randomString(); |
| 79 | 80 | |
| 80 | 81 | // 请求实体 |
| 81 | - MbrAuthResetPasswordReqVO reqVO = new MbrAuthResetPasswordReqVO(); | |
| 82 | - reqVO.setOldPassword(userDO.getPassword()); | |
| 83 | - reqVO.setPassword(newPassword); | |
| 82 | + MbrAuthUpdatePasswordReqVO reqVO = MbrAuthUpdatePasswordReqVO.builder() | |
| 83 | + .oldPassword(userDO.getPassword()) | |
| 84 | + .password(newPassword) | |
| 85 | + .build(); | |
| 84 | 86 | |
| 85 | 87 | // 测试桩 |
| 86 | 88 | // 这两个相等是为了返回ture这个结果 |
| ... | ... | @@ -103,10 +105,10 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { |
| 103 | 105 | // 随机验证码 |
| 104 | 106 | String code = randomNumbers(4); |
| 105 | 107 | |
| 106 | - MbrAuthResetPasswordReqVO reqVO = new MbrAuthResetPasswordReqVO(); | |
| 107 | - reqVO.setPassword(password); | |
| 108 | - reqVO.setCode(code); | |
| 109 | - | |
| 108 | + MbrAuthResetPasswordReqVO reqVO = MbrAuthResetPasswordReqVO.builder() | |
| 109 | + .password(password) | |
| 110 | + .code(code) | |
| 111 | + .build(); | |
| 110 | 112 | // 放入code+手机号 |
| 111 | 113 | stringRedisTemplate.opsForValue().set(code,userDO.getMobile(),10, TimeUnit.MINUTES); |
| 112 | 114 | ... | ... |