fix(upms): regiser user can set roleId
Some checks failed
Docker 镜像 构建 / build (17) (push) Has been cancelled
maven 编译检查 / build (17) (push) Has been cancelled
maven 编译检查 / build (21) (push) Has been cancelled
同步代码 / gitlink (push) Has been cancelled
同步代码 / gitee (push) Has been cancelled

BREAKING CHANGE: security  important
This commit is contained in:
冷冷 2024-12-23 14:51:42 +08:00
parent fe8436f56c
commit 9bddc3dd3c
4 changed files with 42 additions and 8 deletions

View File

@ -0,0 +1,28 @@
package com.pig4cloud.pig.admin.api.dto;
import lombok.Data;
/**
* 注册用户 DTO
*
* @author lengleng
* @date 2024/12/23
*/
@Data
public class RegisterUserDTO {
/**
* 用户名
*/
private String username;
/**
* 新密码
*/
private String password;
/**
* 电话
*/
private String phone;
}

View File

@ -1,6 +1,6 @@
package com.pig4cloud.pig.admin.controller; package com.pig4cloud.pig.admin.controller;
import com.pig4cloud.pig.admin.api.dto.UserDTO; import com.pig4cloud.pig.admin.api.dto.RegisterUserDTO;
import com.pig4cloud.pig.admin.service.SysUserService; import com.pig4cloud.pig.admin.service.SysUserService;
import com.pig4cloud.pig.common.core.util.R; import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog; import com.pig4cloud.pig.common.log.annotation.SysLog;
@ -28,14 +28,15 @@ public class SysRegisterController {
/** /**
* 注册用户 * 注册用户
* @param userDto 用户信息 *
* @return success/false * @param registerUserDTO 注册用户 DTO
* @return {@link R }<{@link Boolean }>
*/ */
@Inner(value = false) @Inner(value = false)
@SysLog("注册用户") @SysLog("注册用户")
@PostMapping("/user") @PostMapping("/user")
public R<Boolean> registerUser(@RequestBody UserDTO userDto) { public R<Boolean> registerUser(@RequestBody RegisterUserDTO registerUserDTO) {
return userService.registerUser(userDto); return userService.registerUser(registerUserDTO);
} }
} }

View File

@ -22,6 +22,7 @@ package com.pig4cloud.pig.admin.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pig.admin.api.dto.RegisterUserDTO;
import com.pig4cloud.pig.admin.api.dto.UserDTO; import com.pig4cloud.pig.admin.api.dto.UserDTO;
import com.pig4cloud.pig.admin.api.dto.UserInfo; import com.pig4cloud.pig.admin.api.dto.UserInfo;
import com.pig4cloud.pig.admin.api.entity.SysUser; import com.pig4cloud.pig.admin.api.entity.SysUser;
@ -108,7 +109,7 @@ public interface SysUserService extends IService<SysUser> {
* @param userDto 用户信息 * @param userDto 用户信息
* @return success/false * @return success/false
*/ */
R<Boolean> registerUser(UserDTO userDto); R<Boolean> registerUser(RegisterUserDTO userDto);
/** /**
* 锁定用户 * 锁定用户

View File

@ -26,6 +26,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.admin.api.dto.RegisterUserDTO;
import com.pig4cloud.pig.admin.api.dto.UserDTO; import com.pig4cloud.pig.admin.api.dto.UserDTO;
import com.pig4cloud.pig.admin.api.dto.UserInfo; import com.pig4cloud.pig.admin.api.dto.UserInfo;
import com.pig4cloud.pig.admin.api.entity.*; import com.pig4cloud.pig.admin.api.entity.*;
@ -385,14 +386,17 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public R<Boolean> registerUser(UserDTO userDto) { public R<Boolean> registerUser(RegisterUserDTO userDto) {
// 判断用户名是否存在 // 判断用户名是否存在
SysUser sysUser = this.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, userDto.getUsername())); SysUser sysUser = this.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, userDto.getUsername()));
if (sysUser != null) { if (sysUser != null) {
String message = MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, userDto.getUsername()); String message = MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, userDto.getUsername());
return R.failed(message); return R.failed(message);
} }
return R.ok(saveUser(userDto));
UserDTO user = new UserDTO();
BeanUtils.copyProperties(userDto, user);
return R.ok(saveUser(user));
} }
/** /**