个人中心修改密码使用密文传输
This commit is contained in:
parent
8f1ce9a5df
commit
52ea5f2e2a
@ -7,8 +7,8 @@ import com.ruoyi.common.encrypt.annotation.ApiEncrypt;
|
|||||||
import com.ruoyi.common.log.annotation.Log;
|
import com.ruoyi.common.log.annotation.Log;
|
||||||
import com.ruoyi.common.log.enums.BusinessType;
|
import com.ruoyi.common.log.enums.BusinessType;
|
||||||
import com.ruoyi.common.security.utils.LoginHelper;
|
import com.ruoyi.common.security.utils.LoginHelper;
|
||||||
import com.ruoyi.system.domain.SysUser;
|
|
||||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||||
|
import com.ruoyi.system.domain.bo.SysUserPasswordBo;
|
||||||
import com.ruoyi.system.domain.bo.SysUserProfileBo;
|
import com.ruoyi.system.domain.bo.SysUserProfileBo;
|
||||||
import com.ruoyi.system.domain.vo.AvatarVo;
|
import com.ruoyi.system.domain.vo.AvatarVo;
|
||||||
import com.ruoyi.system.domain.vo.ProfileVo;
|
import com.ruoyi.system.domain.vo.ProfileVo;
|
||||||
@ -17,17 +17,13 @@ import com.ruoyi.system.domain.vo.SysUserVo;
|
|||||||
import com.ruoyi.system.service.ISysOssService;
|
import com.ruoyi.system.service.ISysOssService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.ruoyi.common.core.config.RuoYiConfig;
|
|
||||||
import com.ruoyi.common.web.core.BaseController;
|
import com.ruoyi.common.web.core.BaseController;
|
||||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
|
||||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.core.utils.file.FileUploadUtils;
|
|
||||||
import com.ruoyi.common.core.utils.file.MimeTypeUtils;
|
import com.ruoyi.common.core.utils.file.MimeTypeUtils;
|
||||||
import cn.dev33.satoken.secure.BCrypt;
|
import cn.dev33.satoken.secure.BCrypt;
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
@ -102,19 +98,19 @@ public class SysProfileController extends BaseController
|
|||||||
@ApiEncrypt
|
@ApiEncrypt
|
||||||
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping("/updatePwd")
|
@PutMapping("/updatePwd")
|
||||||
public R<Void> updatePwd(String oldPassword, String newPassword)
|
public R<Void> updatePwd(@Validated @RequestBody SysUserPasswordBo bo)
|
||||||
{
|
{
|
||||||
SysUserVo sysUser = userService.selectUserById(LoginHelper.getUserId());
|
SysUserVo sysUser = userService.selectUserById(LoginHelper.getUserId());
|
||||||
String password = sysUser.getPassword();
|
String password = sysUser.getPassword();
|
||||||
if (!BCrypt.checkpw(oldPassword, password)) {
|
if (!BCrypt.checkpw(bo.getOldPassword(), password)) {
|
||||||
return R.fail("修改密码失败,旧密码错误");
|
return R.fail("修改密码失败,旧密码错误");
|
||||||
}
|
}
|
||||||
if (BCrypt.checkpw(newPassword, password)) {
|
if (BCrypt.checkpw(bo.getNewPassword(), password)) {
|
||||||
return R.fail("新密码不能与旧密码相同");
|
return R.fail("新密码不能与旧密码相同");
|
||||||
}
|
}
|
||||||
SysUserBo sysUserBo=new SysUserBo();
|
SysUserBo sysUserBo=new SysUserBo();
|
||||||
sysUserBo.setUserId(sysUser.getUserId());
|
sysUserBo.setUserId(sysUser.getUserId());
|
||||||
sysUserBo.setPassword(BCrypt.hashpw(newPassword));
|
sysUserBo.setPassword(BCrypt.hashpw(bo.getNewPassword()));
|
||||||
sysUserBo.setVersion(sysUser.getVersion());
|
sysUserBo.setVersion(sysUser.getVersion());
|
||||||
|
|
||||||
if (userService.resetPwd(sysUserBo))
|
if (userService.resetPwd(sysUserBo))
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.ruoyi.system.domain.bo;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户密码修改bo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SysUserPasswordBo implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 旧密码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "旧密码不能为空")
|
||||||
|
private String oldPassword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新密码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "新密码不能为空")
|
||||||
|
private String newPassword;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user