调整用户修改密码

This commit is contained in:
TinyAnts 2022-09-16 15:27:48 +08:00
parent 0d5444342d
commit a9e1ff42cc
2 changed files with 2 additions and 2 deletions

View File

@ -73,13 +73,12 @@ public class UserController {
*/ */
@PostMapping("/changePwd") @PostMapping("/changePwd")
public Object changePwd(@RequestBody Map<String, String> params) { public Object changePwd(@RequestBody Map<String, String> params) {
Assert.notNull(params.get("oldPassword"), "oldPassword参数缺失");
Assert.notNull(params.get("password"), "password参数缺失"); Assert.notNull(params.get("password"), "password参数缺失");
if(!Pattern.matches("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$", params.get("password"))){ if(!Pattern.matches("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$", params.get("password"))){
throw new OperateException("密码必须是6-20字母+数字组合!"); throw new OperateException("密码必须是6-20字母+数字组合!");
} }
Integer userId = LikeFrontThreadLocal.getUserId(); Integer userId = LikeFrontThreadLocal.getUserId();
iUserService.changePwd(params.get("password"), params.get("oldPassword"), userId); iUserService.changePwd(params.get("password"), params.getOrDefault("oldPassword", null), userId);
return AjaxResult.success(); return AjaxResult.success();
} }

View File

@ -183,6 +183,7 @@ public class UserServiceImpl implements IUserService {
Assert.notNull(user, "用户不存在"); Assert.notNull(user, "用户不存在");
if (!user.getPassword().equals("")) { if (!user.getPassword().equals("")) {
Assert.notNull(oldPassword, "oldPassword参数缺失");
String oldPwd = ToolsUtil.makeMd5(oldPassword.trim() + user.getSalt()); String oldPwd = ToolsUtil.makeMd5(oldPassword.trim() + user.getSalt());
if (!oldPwd.equals(user.getPassword())) { if (!oldPwd.equals(user.getPassword())) {
throw new OperateException("原密码不正确!"); throw new OperateException("原密码不正确!");