diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java index 399d131..2b86dff 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -314,4 +314,36 @@ public class SysUserController { return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); } + /** + * 用户修改密码 + * @param map + * @param token + * @return + */ + @PostMapping("/updatePassword") + public String updatePassword(@RequestBody Map map,@RequestHeader(value="Authorization") String token){ + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + String userName = (String) map.get("userName"); + String oldPassword = (String) map.get("oldPassword"); + String newPassword = (String) map.get("newPassword"); + String confirmPassword = (String) map.get("confirmPassword"); + // 验证token + String tokenUserName = TokenUtil.getTokenUserName(token); + SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName); + if(sysUserEntity == null){ + return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale); + } + if(oldPassword == null || "".equals(oldPassword)){ + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"旧密码不能为空!",locale); + } + if(newPassword == null || "".equals(newPassword)){ + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"新密码不能为空!",locale); + } + if(userName == null || "".equals(userName)){ + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"账号不能为空!",locale); + } + return sysUserService.updatePassword(oldPassword,newPassword,confirmPassword,userName,sysUserEntity); + } + } diff --git a/src/main/java/com/xkrs/dao/SysUserDao.java b/src/main/java/com/xkrs/dao/SysUserDao.java index aea5e06..fb7cf90 100644 --- a/src/main/java/com/xkrs/dao/SysUserDao.java +++ b/src/main/java/com/xkrs/dao/SysUserDao.java @@ -153,4 +153,14 @@ public interface SysUserDao extends JpaRepository { "last_entry_time lastentrytime,add_time addtime from sys_user",nativeQuery = true) List> selectAllUser(); + /** + * 用户修改账号密码 + * @param userId + * @param newPassword + * @param userName + */ + @Query(value = "update sys_user set password = ?2,user_name = ?3 where id = ?1",nativeQuery = true) + @Modifying(clearAutomatically=true) + void updatePassword(Integer userId,String newPassword,String userName); + } diff --git a/src/main/java/com/xkrs/service/SysUserService.java b/src/main/java/com/xkrs/service/SysUserService.java index 550d754..3cea935 100644 --- a/src/main/java/com/xkrs/service/SysUserService.java +++ b/src/main/java/com/xkrs/service/SysUserService.java @@ -105,4 +105,15 @@ public interface SysUserService { * @param userId */ void updateDisable(Integer userId); + + /** + * 用户修改密码 + * @param oldPassword + * @param newPassword + * @param confirmPassword + * @param userName + * @param sysUserEntity + * @return + */ + String updatePassword(String oldPassword,String newPassword,String confirmPassword,String userName,SysUserEntity sysUserEntity); } diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index 209f1eb..e947c95 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -268,4 +268,29 @@ public class SysUserServiceImpl implements SysUserService { sysUserDao.updateDisable(userId); } + /** + * 用户修改账号密码 + * @param oldPassword + * @param newPassword + * @param confirmPassword + * @param userName + * @param sysUserEntity + * @return + */ + @Transactional(rollbackFor=Exception.class) + @Override + public String updatePassword(String oldPassword, String newPassword, String confirmPassword, String userName, SysUserEntity sysUserEntity) { + Locale locale = LocaleContextHolder.getLocale(); + String oldFrontPassword = encry256(oldPassword + sysUserEntity.getSalt()); + if(!oldFrontPassword.equals(sysUserEntity.getPassword())){ + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"旧密码输入错误",locale); + } + if(!newPassword.equals(confirmPassword)){ + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"两次密码输入不一致",locale); + } + String newAfterPassword = encry256(newPassword + sysUserEntity.getSalt()); + sysUserDao.updatePassword(sysUserEntity.getId(),newAfterPassword,userName); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"密码修改成功",locale); + } + }