From 0f18736aa1bbabc28e7647e675b1c1592aa71a55 Mon Sep 17 00:00:00 2001 From: XinYi Song <2037158277@qq.com> Date: Fri, 24 Dec 2021 11:30:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B4=A6=E5=8F=B7=E5=AF=86=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/SysUserController.java | 32 +++++++++++++++++++ src/main/java/com/xkrs/dao/SysUserDao.java | 10 ++++++ .../java/com/xkrs/service/SysUserService.java | 11 +++++++ .../xkrs/service/impl/SysUserServiceImpl.java | 25 +++++++++++++++ 4 files changed, 78 insertions(+) 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); + } + }