mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-31 08:14:18 +08:00
fix(upms): regiser user can set roleId
BREAKING CHANGE: security important
This commit is contained in:
parent
fe8436f56c
commit
9bddc3dd3c
@ -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;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
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.common.core.util.R;
|
||||
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)
|
||||
@SysLog("注册用户")
|
||||
@PostMapping("/user")
|
||||
public R<Boolean> registerUser(@RequestBody UserDTO userDto) {
|
||||
return userService.registerUser(userDto);
|
||||
public R<Boolean> registerUser(@RequestBody RegisterUserDTO registerUserDTO) {
|
||||
return userService.registerUser(registerUserDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.pig4cloud.pig.admin.service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.UserInfo;
|
||||
import com.pig4cloud.pig.admin.api.entity.SysUser;
|
||||
@ -108,7 +109,7 @@ public interface SysUserService extends IService<SysUser> {
|
||||
* @param userDto 用户信息
|
||||
* @return success/false
|
||||
*/
|
||||
R<Boolean> registerUser(UserDTO userDto);
|
||||
R<Boolean> registerUser(RegisterUserDTO userDto);
|
||||
|
||||
/**
|
||||
* 锁定用户
|
||||
|
@ -26,6 +26,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.UserInfo;
|
||||
import com.pig4cloud.pig.admin.api.entity.*;
|
||||
@ -385,14 +386,17 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
*/
|
||||
@Override
|
||||
@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()));
|
||||
if (sysUser != null) {
|
||||
String message = MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, userDto.getUsername());
|
||||
return R.failed(message);
|
||||
}
|
||||
return R.ok(saveUser(userDto));
|
||||
|
||||
UserDTO user = new UserDTO();
|
||||
BeanUtils.copyProperties(userDto, user);
|
||||
return R.ok(saveUser(user));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user