新增用户修改个人密码接口,解决首次登录修改密码可能的权限问题

This commit is contained in:
gaoqr
2024-09-10 12:03:09 +08:00
parent 9933d67cae
commit 2aa4c5e642
2 changed files with 20 additions and 0 deletions
@@ -55,6 +55,7 @@ public interface ErrorCodeConstants {
ErrorCode USERNAME_MULTIPLE_ERROR = new ErrorCode(1_002_003_015,"存在【{}】重复用户,请联系系统管理员"); ErrorCode USERNAME_MULTIPLE_ERROR = new ErrorCode(1_002_003_015,"存在【{}】重复用户,请联系系统管理员");
ErrorCode USER_OPERATE_SELF_STATUS_ERROR = new ErrorCode(1_002_003_016, "不允许操作用户自身状态"); ErrorCode USER_OPERATE_SELF_STATUS_ERROR = new ErrorCode(1_002_003_016, "不允许操作用户自身状态");
ErrorCode THE_PASSWORD_MUST_CONTAIN_AT_LEAST_ONE_UPPER_LETTER = new ErrorCode(1_002_003_017, "密码必须包含至少一个大写字母"); ErrorCode THE_PASSWORD_MUST_CONTAIN_AT_LEAST_ONE_UPPER_LETTER = new ErrorCode(1_002_003_017, "密码必须包含至少一个大写字母");
ErrorCode PERSONAL_PASSWORD_PERMISSION_ERROR = new ErrorCode(1_002_003_018, "修改密码权限不足");
// ========== 部门模块 1-002-004-000 ========== // ========== 部门模块 1-002-004-000 ==========
ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1_002_004_000, "已经存在该名字的部门"); ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1_002_004_000, "已经存在该名字的部门");
@@ -1,7 +1,9 @@
package com.cf.imes.module.system.controller.admin.user; package com.cf.imes.module.system.controller.admin.user;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.enums.CommonStatusEnum; import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.CommonResult; import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageParam; import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult; import com.cf.imes.framework.common.pojo.PageResult;
@@ -10,6 +12,8 @@ import com.cf.imes.framework.excel.core.util.ExcelUtils;
import com.cf.imes.framework.mybatis.core.query.MPJLambdaWrapperX; import com.cf.imes.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog; import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import com.cf.imes.framework.organ.core.context.OrganContextHolder; import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.framework.security.core.LoginUser;
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
import com.cf.imes.module.system.controller.admin.user.vo.user.*; import com.cf.imes.module.system.controller.admin.user.vo.user.*;
import com.cf.imes.module.system.controller.admin.user.vo.user.UserImportExcelVO; import com.cf.imes.module.system.controller.admin.user.vo.user.UserImportExcelVO;
import com.cf.imes.module.system.controller.admin.user.vo.user.UserImportRespVO; import com.cf.imes.module.system.controller.admin.user.vo.user.UserImportRespVO;
@@ -45,11 +49,13 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.cf.imes.framework.common.pojo.CommonResult.success; import static com.cf.imes.framework.common.pojo.CommonResult.success;
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertList; import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertList;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.PERSONAL_PASSWORD_PERMISSION_ERROR;
@Tag(name = "管理后台 - 用户") @Tag(name = "管理后台 - 用户")
@RestController @RestController
@@ -101,6 +107,19 @@ public class UserController {
return success(true); return success(true);
} }
@PutMapping("/update-personal-password")
@Operation(summary = "重置用户个人密码")
public CommonResult<Boolean> updateUserPersonalPassword(@Valid @RequestBody UserUpdatePasswordReqVO reqVO) {
// 校验个人
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
if (ObjectUtil.isNotNull(loginUser) && Objects.equals(loginUser.getId(), reqVO.getId())) {
userService.updateUserPassword(reqVO.getId(), reqVO.getPassword());
} else {
throw new ServiceException(PERSONAL_PASSWORD_PERMISSION_ERROR);
}
return success(true);
}
@PutMapping("/reset-password") @PutMapping("/reset-password")
@Operation(summary = "忘记密码重置") @Operation(summary = "忘记密码重置")
@PermitAll @PermitAll