feat: ASW-82 新增 user profile 接口
This commit is contained in:
@@ -28,6 +28,7 @@ public enum RCode {
|
||||
SYS_USER_BUILT_IN(100016, "Built-in user are not allowed to delete or update"),
|
||||
SYS_ROLE_BUILT_IN(100017, "Built-in role are not allowed to delete or update"),
|
||||
SYS_ROLE_NOT_DELETE(100018, "Used role cannot be deleted"),
|
||||
SYS_USER_OLDPWD_INCORRECT(100019, "Incorrect old password. Please try again."),
|
||||
|
||||
|
||||
// Application
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package net.geedge.asw.module.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.log.Log;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import net.geedge.asw.common.util.*;
|
||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||
@@ -81,4 +83,49 @@ public class SysUserController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/profile")
|
||||
public R profile() {
|
||||
return this.detail(StpUtil.getLoginIdAsString());
|
||||
}
|
||||
|
||||
@PutMapping("/profile")
|
||||
public R profile(@RequestBody SysUserEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
|
||||
.and(entity.getAccessLevel()).notEmpty(RCode.SYS_ACCESS_LEVEL_CANNOT_EMPTY);
|
||||
|
||||
SysUserEntity loginUser = userService.getById(StpUtil.getLoginIdAsString());
|
||||
T.VerifyUtil.is(loginUser).notNull(RCode.USER_NO_LOGIN);
|
||||
|
||||
// update fields
|
||||
String name = entity.getName();
|
||||
String accessLevel = entity.getAccessLevel();
|
||||
String pwd = entity.getPwd();
|
||||
String oldPwd = entity.getOldPwd();
|
||||
String language = entity.getLanguage();
|
||||
|
||||
// pwd
|
||||
if (T.StrUtil.isAllNotEmpty(pwd, oldPwd)) {
|
||||
// validate
|
||||
String encrypt = T.AesUtil.decrypt(loginUser.getPwd(), Constants.AES_KEY);
|
||||
if (!T.StrUtil.equals(encrypt, oldPwd)) {
|
||||
throw new ASWException(RCode.SYS_USER_OLDPWD_INCORRECT);
|
||||
}
|
||||
// encrypt pwd
|
||||
pwd = T.AesUtil.encrypt(pwd, Constants.AES_KEY);
|
||||
}
|
||||
|
||||
userService.update(
|
||||
new LambdaUpdateWrapper<SysUserEntity>()
|
||||
.set(SysUserEntity::getName, name)
|
||||
.set(SysUserEntity::getAccessLevel, accessLevel)
|
||||
.set(T.StrUtil.isAllNotEmpty(pwd, oldPwd), SysUserEntity::getPwd, pwd)
|
||||
.set(T.StrUtil.isNotEmpty(language), SysUserEntity::getLanguage, language)
|
||||
.set(SysUserEntity::getUpdateTimestamp, System.currentTimeMillis())
|
||||
.set(SysUserEntity::getUpdateUserId, loginUser.getId())
|
||||
.eq(SysUserEntity::getId, loginUser.getId())
|
||||
);
|
||||
return R.ok().putData("id", loginUser.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package net.geedge.asw.module.sys.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import lombok.Data;
|
||||
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@TableName("sys_user")
|
||||
public class SysUserEntity {
|
||||
@@ -24,6 +23,9 @@ public class SysUserEntity {
|
||||
|
||||
private String pwd;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String oldPwd;
|
||||
|
||||
private String accessLevel;
|
||||
|
||||
private String language;
|
||||
|
||||
@@ -133,6 +133,8 @@ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (223, '601003', 'ENVIRONMENT_USED', '环境已在使用中', 'zh', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (225, '601004', 'ENVIRONMENT_STATUS_ERROR', 'The environment status is unavailable', 'en', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (227, '601004', 'ENVIRONMENT_STATUS_ERROR', '环境状态不可用', 'zh', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (228, '100019', 'SYS_USER_OLDPWD_INCORRECT', 'Incorrect old password. Please try again.', 'en', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (229, '100019', 'SYS_USER_OLDPWD_INCORRECT', '旧密码不正确,请重新输入', 'zh', '', 'admin', 1724030366000);
|
||||
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
Reference in New Issue
Block a user