From bfe1b2ae508df731c43f25a286da252ed24cc0a0 Mon Sep 17 00:00:00 2001 From: bleachtred Date: Mon, 25 Sep 2023 15:21:29 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81=E6=8E=A5=E5=8F=A3=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E6=96=B0=E6=97=A7=E5=AF=86=E7=A0=81=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=98=8E=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/SysProfileController.java | 13 ++++---- .../system/domain/bo/SysUserPasswordBo.java | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysUserPasswordBo.java diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java index 60d16829..36411b7b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java @@ -6,11 +6,13 @@ import cn.hutool.core.io.FileUtil; import org.dromara.common.core.domain.R; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.file.MimeTypeUtils; +import org.dromara.common.core.validate.auth.PasswordGroup; import org.dromara.common.log.annotation.Log; import org.dromara.common.log.enums.BusinessType; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.web.core.BaseController; import org.dromara.system.domain.bo.SysUserBo; +import org.dromara.system.domain.bo.SysUserPasswordBo; import org.dromara.system.domain.bo.SysUserProfileBo; import org.dromara.system.domain.vo.AvatarVo; import org.dromara.system.domain.vo.ProfileVo; @@ -76,22 +78,21 @@ public class SysProfileController extends BaseController { /** * 重置密码 * - * @param newPassword 旧密码 - * @param oldPassword 新密码 + * @param bo 新旧密码 */ @Log(title = "个人信息", businessType = BusinessType.UPDATE) @PutMapping("/updatePwd") - public R updatePwd(String oldPassword, String newPassword) { + public R updatePwd(@Validated(PasswordGroup.class) @RequestBody SysUserPasswordBo bo) { SysUserVo user = userService.selectUserById(LoginHelper.getUserId()); String password = user.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("新密码不能与旧密码相同"); } - if (userService.resetUserPwd(user.getUserId(), BCrypt.hashpw(newPassword)) > 0) { + if (userService.resetUserPwd(user.getUserId(), BCrypt.hashpw(bo.getNewPassword())) > 0) { return R.ok(); } return R.fail("修改密码异常,请联系管理员"); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysUserPasswordBo.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysUserPasswordBo.java new file mode 100644 index 00000000..298ea3a3 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysUserPasswordBo.java @@ -0,0 +1,30 @@ +package org.dromara.system.domain.bo; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import org.dromara.common.core.validate.auth.PasswordGroup; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 用户密码修改bo + */ +@Data +public class SysUserPasswordBo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 旧密码 + */ + @NotBlank(message = "旧密码不能为空", groups = { PasswordGroup.class }) + private String oldPassword; + + /** + * 新密码 + */ + @NotBlank(message = "新密码不能为空", groups = { PasswordGroup.class }) + private String newPassword; +}