添加了用户修改账号密码的功能模块

This commit is contained in:
XinYi Song 2021-12-24 11:30:28 +08:00
parent d068e6ea95
commit 0f18736aa1
4 changed files with 78 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -153,4 +153,14 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
"last_entry_time lastentrytime,add_time addtime from sys_user",nativeQuery = true)
List<Map<String,Object>> 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);
}

View File

@ -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);
}

View File

@ -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);
}
}