From 52ea5f2e2ab2be4a66e4def4b643b178ccf5bcf9 Mon Sep 17 00:00:00 2001 From: dataprince Date: Tue, 16 Jan 2024 10:17:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E4=BD=BF=E7=94=A8=E5=AF=86=E6=96=87?= =?UTF-8?q?=E4=BC=A0=E8=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/SysProfileController.java | 14 ++++----- .../system/domain/bo/SysUserPasswordBo.java | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysUserPasswordBo.java diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysProfileController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysProfileController.java index bc61dcd..3c89384 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysProfileController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysProfileController.java @@ -7,8 +7,8 @@ import com.ruoyi.common.encrypt.annotation.ApiEncrypt; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; 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.SysUserPasswordBo; import com.ruoyi.system.domain.bo.SysUserProfileBo; import com.ruoyi.system.domain.vo.AvatarVo; 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 jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import com.ruoyi.common.core.config.RuoYiConfig; 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.utils.StringUtils; -import com.ruoyi.common.core.utils.file.FileUploadUtils; import com.ruoyi.common.core.utils.file.MimeTypeUtils; import cn.dev33.satoken.secure.BCrypt; import com.ruoyi.system.service.ISysUserService; @@ -102,19 +98,19 @@ public class SysProfileController extends BaseController @ApiEncrypt @Log(title = "个人信息", businessType = BusinessType.UPDATE) @PutMapping("/updatePwd") - public R updatePwd(String oldPassword, String newPassword) + public R updatePwd(@Validated @RequestBody SysUserPasswordBo bo) { SysUserVo sysUser = userService.selectUserById(LoginHelper.getUserId()); String password = sysUser.getPassword(); - if (!BCrypt.checkpw(oldPassword, password)) { + if (!BCrypt.checkpw(bo.getOldPassword(), password)) { return R.fail("修改密码失败,旧密码错误"); } - if (BCrypt.checkpw(newPassword, password)) { + if (BCrypt.checkpw(bo.getNewPassword(), password)) { return R.fail("新密码不能与旧密码相同"); } SysUserBo sysUserBo=new SysUserBo(); sysUserBo.setUserId(sysUser.getUserId()); - sysUserBo.setPassword(BCrypt.hashpw(newPassword)); + sysUserBo.setPassword(BCrypt.hashpw(bo.getNewPassword())); sysUserBo.setVersion(sysUser.getVersion()); if (userService.resetPwd(sysUserBo)) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysUserPasswordBo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysUserPasswordBo.java new file mode 100644 index 0000000..fde586c --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysUserPasswordBo.java @@ -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; +}