liusheng
2023-10-19 f80df09d8dee5c731cb42d4e3d18f627e32bdaea
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java
@@ -2,6 +2,7 @@
import java.io.IOException;
import com.ruoyi.common.core.domain.entity.UpdateUserPWD;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -61,7 +62,7 @@
     * 修改用户
     */
    @Log(title = "个人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @PostMapping("/updateProfile")
    public AjaxResult updateProfile(@RequestBody SysUser user)
    {
        if (StringUtils.isNotEmpty(user.getPhonenumber())
@@ -95,27 +96,27 @@
     * 重置密码
     */
    @Log(title = "个人信息", businessType = BusinessType.UPDATE)
    @PutMapping("/updatePwd")
    public AjaxResult updatePwd(String oldPassword, String newPassword)
    @PostMapping("/updatePwd")
    public AjaxResult updatePwd(@RequestBody UpdateUserPWD updateUserPWD)
    {
        LoginUser loginUser = getLoginUser();
        String userName = loginUser.getUsername();
        String password = loginUser.getPassword();
        if (!SecurityUtils.matchesPassword(oldPassword, password))
        if (!SecurityUtils.matchesPassword(updateUserPWD.getOldPassword(), password))
        {
            return AjaxResult.error("修改密码失败,旧密码错误");
        }
        if (SecurityUtils.matchesPassword(newPassword, password))
        if (SecurityUtils.matchesPassword(updateUserPWD.getNewPassword(), password))
        {
            return AjaxResult.error("新密码不能与旧密码相同");
        }
        if(!checkPasswordRule(newPassword)){
        if(!checkPasswordRule(updateUserPWD.getNewPassword())){
            return AjaxResult.error("密码格式: 大小写字母、数字、特殊字符中的至少三种(长度大于等于8位)");
        }
        if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0 && checkPasswordRule(newPassword))
        if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(updateUserPWD.getNewPassword())) > 0 && checkPasswordRule(updateUserPWD.getNewPassword()))
        {
            // 更新缓存用户密码
            loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
            loginUser.getUser().setPassword(SecurityUtils.encryptPassword(updateUserPWD.getNewPassword()));
            tokenService.setLoginUser(loginUser);
            return AjaxResult.success();
        }