From 1f26d2950d241dc46a89c7d717754fbe4da4e5c4 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Fri, 9 Oct 2020 15:34:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B9=B3=E5=8F=B0=E8=B6=85?= =?UTF-8?q?=E7=AE=A1=E5=91=98=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hrauth/UserLoginControllerApi.java | 3 ++ .../controller/UserLoginController.java | 8 +++ .../hrauth/service/UserLoginService.java | 3 ++ .../service/impl/UserLoginServiceImpl.java | 52 +++++++++++++------ .../mapper/hrmsauth/UserLoginMapper.xml | 2 +- .../domain/hrms/request/UpdatePwdRequest.java | 40 ++++++++++++++ .../domain/hrms/request/UserLoginRequest.java | 5 ++ .../domain/hrms/response/HrmsCode.java | 2 + 8 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UpdatePwdRequest.java diff --git a/dq-financial-api/src/main/java/com/daqing/financial/hrauth/UserLoginControllerApi.java b/dq-financial-api/src/main/java/com/daqing/financial/hrauth/UserLoginControllerApi.java index 5a32c03c..570e1f8a 100644 --- a/dq-financial-api/src/main/java/com/daqing/financial/hrauth/UserLoginControllerApi.java +++ b/dq-financial-api/src/main/java/com/daqing/financial/hrauth/UserLoginControllerApi.java @@ -1,6 +1,7 @@ package com.daqing.financial.hrauth; import com.daqing.framework.domain.hrms.request.LoginRequest; +import com.daqing.framework.domain.hrms.request.UpdatePwdRequest; import com.daqing.framework.domain.hrms.request.UserLoginRequest; import com.daqing.framework.model.response.ResponseResult; import io.swagger.annotations.Api; @@ -26,5 +27,7 @@ public interface UserLoginControllerApi { @ApiOperation(value = "登录") ResponseResult login(LoginRequest loginRequest); + @ApiOperation(value = "修改超管员密码") + ResponseResult updatePwd(UpdatePwdRequest user); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java index 0ca25e14..2c258c50 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java @@ -3,6 +3,7 @@ package com.daqing.financial.hrauth.controller; import com.daqing.financial.hrauth.UserLoginControllerApi; import com.daqing.financial.hrauth.service.UserLoginService; import com.daqing.framework.domain.hrms.request.LoginRequest; +import com.daqing.framework.domain.hrms.request.UpdatePwdRequest; import com.daqing.framework.domain.hrms.request.UserLoginRequest; import com.daqing.framework.model.response.ResponseResult; import io.swagger.annotations.Api; @@ -68,4 +69,11 @@ public class UserLoginController implements UserLoginControllerApi { loginRequest.setPhone(phone);*/ return userLoginService.login(loginRequest); } + + @PostMapping("/updatePwd") + @ApiOperation(value = "修改平台超管员密码") + public ResponseResult updatePwd(@RequestBody @Valid UpdatePwdRequest user){ + boolean result = userLoginService.updatePwd(user); + return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); + } } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserLoginService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserLoginService.java index 47481c74..23e2d2b4 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserLoginService.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserLoginService.java @@ -3,6 +3,7 @@ package com.daqing.financial.hrauth.service; import com.baomidou.mybatisplus.extension.service.IService; import com.daqing.framework.domain.hrms.UserEntity; import com.daqing.framework.domain.hrms.request.LoginRequest; +import com.daqing.framework.domain.hrms.request.UpdatePwdRequest; import com.daqing.framework.domain.hrms.request.UserLoginRequest; import com.daqing.framework.model.response.ResponseResult; @@ -16,4 +17,6 @@ public interface UserLoginService extends IService { //登录 ResponseResult login(LoginRequest loginRequest); + + Boolean updatePwd(UpdatePwdRequest user); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java index bff1c7fc..2f52e38f 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java @@ -10,6 +10,7 @@ import com.daqing.framework.domain.hrms.LoginLog; import com.daqing.framework.domain.hrms.Token; import com.daqing.framework.domain.hrms.UserEntity; import com.daqing.framework.domain.hrms.request.LoginRequest; +import com.daqing.framework.domain.hrms.request.UpdatePwdRequest; import com.daqing.framework.domain.hrms.request.UserLoginRequest; import com.daqing.framework.domain.hrms.response.HrmsCode; import com.daqing.framework.domain.hrms.response.LoginResponse; @@ -62,14 +63,6 @@ public class UserLoginServiceImpl extends ServiceImpl */ @Override public UserLoginRequest verifyMobile(UserLoginRequest user){ - //判断重置密码参数是否为空 - if(StringUtils.isEmpty(user.getPhoneAccount())){ - ExceptionCast.cast(HrmsCode.PHNOE_ACCOUNT_NOT_EMPTY); - } - if(StringUtils.isEmpty(user.getVerifyCode())){ - ExceptionCast.cast(HrmsCode.VERIFY_CODE_ILLEGAL); - } - //校验手机账号是否存在 /* int count = this.count(new QueryWrapper() .eq("phone_account", user.getPhoneAccount()));*/ @@ -92,13 +85,6 @@ public class UserLoginServiceImpl extends ServiceImpl */ @Override public Boolean getBackPwd(UserLoginRequest user){ - //判断重置密码参数是否为空 - if(StringUtils.isEmpty(user.getNewPwd())){ - ExceptionCast.cast(HrmsCode.NEW_PASSWORD_NOT_EMPTY); - } - if(StringUtils.isEmpty(user.getConfirmPwd())){ - ExceptionCast.cast(HrmsCode.CONFIRM_PWD_NOT_EMPTY); - } if(!user.getConfirmPwd().equals(user.getNewPwd())){ ExceptionCast.cast(HrmsCode.TWICE_PWD_DIFFERENT); } @@ -186,4 +172,40 @@ public class UserLoginServiceImpl extends ServiceImpl return ResponseResult.SUCCESS(loginResponse); } + + /** + * 修改平台超管员密码 + */ + @Override + public Boolean updatePwd(UpdatePwdRequest user){ + if(!user.getConfirmPwd().equals(user.getNewPwd())){ + ExceptionCast.cast(HrmsCode.TWICE_PWD_DIFFERENT); + } + + //根据手机号查询相关信息 + UserEntity userEntity = baseMapper.selectByPhoneAccount(user.getPhoneAccount()); + if(userEntity == null){ + ExceptionCast.cast(HrmsCode.PHNOE_ACCOUNT_NOT_EXIST); + } + + //新密码不能与账号相同 + if(user.getNewPwd().equals(userEntity.getAccount())){ + ExceptionCast.cast(HrmsCode.NEW_PASSWORD_DIFFERENT); + } + + //检测当前密码是否输入正确 + if(!Md5Util.md5(user.getPassword()+userEntity.getId()).equals(userEntity.getPassword())){ + ExceptionCast.cast(HrmsCode.PASSWORD_ERROR); + } + + //新密码不能与当前密码保持一致 + if(Md5Util.md5(user.getNewPwd()+userEntity.getId()).equals(userEntity.getPassword())){ + ExceptionCast.cast(HrmsCode.NEWPWD_PASSWORD_SAME); + } + + String newMD5 = Md5Util.md5(user.getNewPwd()+userEntity.getId()); + //根据手机号码修改密码 + int i = userLoginDao.updatePasswordByPhoneAccount(user.getPhoneAccount(),newMD5); + return i > 0; + } } diff --git a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml index 9a66957d..fd2d7237 100644 --- a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml +++ b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml @@ -35,7 +35,7 @@ \ No newline at end of file diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UpdatePwdRequest.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UpdatePwdRequest.java new file mode 100644 index 00000000..d131986c --- /dev/null +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UpdatePwdRequest.java @@ -0,0 +1,40 @@ +package com.daqing.framework.domain.hrms.request; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; +import java.io.Serializable; + +/** + * 修改平台超管员密码请求体对象 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-09-07 17:12:14 + */ +@Data +public class UpdatePwdRequest implements Serializable { + + /** + * 手机账号 + */ + @Pattern(regexp = "^1(3([0-35-9]\\d|4[1-8])|4[14-9]\\d|5([0125689]\\d|7[1-79])|66\\d|7[2-35-8]\\d|8\\d{2}|9[13589]\\d)\\d{7}$",message = "手机号格式不正确!") + private String phoneAccount; + + /** + * 新密码 + */ + @Pattern(regexp = "^(?=.*[0-9].*)(?=.*[A-Z].*)(?=.*[a-z].*).{6,20}$",message = "密码格式不正确!") + private String newPwd; + /** + * 确认密码 + */ + private String confirmPwd; + + /** + * 原密码 + */ + @NotBlank(message = "当前密码不能为空!") + private String password; +} diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UserLoginRequest.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UserLoginRequest.java index c6428064..68dfb88f 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UserLoginRequest.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UserLoginRequest.java @@ -2,6 +2,7 @@ package com.daqing.framework.domain.hrms.request; import lombok.Data; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; import java.io.Serializable; @@ -18,20 +19,24 @@ public class UserLoginRequest implements Serializable { /** * 手机账号 */ + @NotBlank(message = "手机号码不能为空!") @Pattern(regexp = "^1(3([0-35-9]\\d|4[1-8])|4[14-9]\\d|5([0125689]\\d|7[1-79])|66\\d|7[2-35-8]\\d|8\\d{2}|9[13589]\\d)\\d{7}$",message = "手机号格式不正确!") private String phoneAccount; /** * 验证码 */ + @NotBlank(message = "验证码不能为空!") private String verifyCode; /** * 新密码 */ @Pattern(regexp = "^(?=.*[0-9].*)(?=.*[A-Z].*)(?=.*[a-z].*).{6,20}$",message = "密码格式不正确!") + @NotBlank(message = "新密码不能为空!") private String newPwd; /** * 确认密码 */ + @NotBlank(message = "确认密码不能为空!") private String confirmPwd; } diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java index cbfea710..6287f554 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java @@ -30,6 +30,8 @@ public enum HrmsCode implements ResultCode { CONFIRM_PWD_NOT_EMPTY(false,33007,"确认密码不能为空!"), TWICE_PWD_DIFFERENT(false,33008,"两次输入密码不一致!"), NEW_PASSWORD_DIFFERENT(false,33008,"输入的新密码不能与账号相同!"), + PASSWORD_ERROR(false,33009,"当前密码输入不正确!"), + NEWPWD_PASSWORD_SAME(false,33010,"新密码不能与当前密码一致!"), EMP_POSITION_EXSIT(false, 22006, "该职位下已关联员工!");