|
|
@@ -9,6 +9,7 @@ import com.xunmei.common.core.web.domain.AjaxResult;
|
|
|
import com.xunmei.common.log.annotation.Log;
|
|
|
import com.xunmei.common.log.enums.BusinessType;
|
|
|
import com.xunmei.common.security.service.TokenService;
|
|
|
+import com.xunmei.common.security.utils.SaltHelper;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
import com.xunmei.system.api.RemoteFileService;
|
|
|
import com.xunmei.system.api.domain.SysFile;
|
|
|
@@ -95,22 +96,24 @@ public class SysProfileController extends BaseController
|
|
|
@PutMapping("/updatePwd")
|
|
|
public AjaxResult updatePwd(String oldPassword, String newPassword)
|
|
|
{
|
|
|
- String username = SecurityUtils.getUsername();
|
|
|
- SysUser user = userService.selectUserByUserName(username);
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ SysUser user = userService.selectUserById(userId);
|
|
|
String password = user.getPassword();
|
|
|
- if (!SecurityUtils.matchesPassword(oldPassword, password))
|
|
|
+ if (!SecurityUtils.isEquals(password, oldPassword,user.getSalt()))
|
|
|
{
|
|
|
return error("修改密码失败,旧密码错误");
|
|
|
}
|
|
|
- if (SecurityUtils.matchesPassword(newPassword, password))
|
|
|
+ if (SecurityUtils.isEquals(password, newPassword,user.getSalt()))
|
|
|
{
|
|
|
return error("新密码不能与旧密码相同");
|
|
|
}
|
|
|
- if (userService.resetUserPwd(username, SecurityUtils.encryptPassword(newPassword)) > 0)
|
|
|
+ String salt = user.getSalt();
|
|
|
+ String nPassword = SaltHelper.exec(newPassword, salt);
|
|
|
+ if (userService.resetUserPwd(user.getUsername(),nPassword ) > 0)
|
|
|
{
|
|
|
// 更新缓存用户密码
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- loginUser.getSysUser().setPassword(SecurityUtils.encryptPassword(newPassword));
|
|
|
+ loginUser.getSysUser().setPassword(nPassword);
|
|
|
tokenService.setLoginUser(loginUser);
|
|
|
return success();
|
|
|
}
|