Skip to content

Commit

Permalink
fix(upms): regiser user can set roleId
Browse files Browse the repository at this point in the history
BREAKING CHANGE: security  important
  • Loading branch information
lltx committed Dec 23, 2024
1 parent fe8436f commit 9bddc3d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -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);

/**
* 锁定用户
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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.*;
Expand Down Expand Up @@ -385,14 +386,17 @@ private void insertExcelUser(UserExcelVO excel, Optional<SysDept> deptOptional,
*/
@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));
}

/**
Expand Down

0 comments on commit 9bddc3d

Please sign in to comment.