From 9bddc3dd3c4c21043c38f444390a420b0cb76924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Mon, 23 Dec 2024 14:51:42 +0800 Subject: [PATCH] fix(upms): regiser user can set roleId BREAKING CHANGE: security important --- .../pig/admin/api/dto/RegisterUserDTO.java | 28 +++++++++++++++++++ .../controller/SysRegisterController.java | 11 ++++---- .../pig/admin/service/SysUserService.java | 3 +- .../service/impl/SysUserServiceImpl.java | 8 ++++-- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/dto/RegisterUserDTO.java diff --git a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/dto/RegisterUserDTO.java b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/dto/RegisterUserDTO.java new file mode 100644 index 00000000..05c00746 --- /dev/null +++ b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/dto/RegisterUserDTO.java @@ -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; +} diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/SysRegisterController.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/SysRegisterController.java index a73d66be..3967d3bf 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/SysRegisterController.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/SysRegisterController.java @@ -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 registerUser(@RequestBody UserDTO userDto) { - return userService.registerUser(userDto); + public R registerUser(@RequestBody RegisterUserDTO registerUserDTO) { + return userService.registerUser(registerUserDTO); } } diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/SysUserService.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/SysUserService.java index cfcdfa0a..92c7311f 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/SysUserService.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/SysUserService.java @@ -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 { * @param userDto 用户信息 * @return success/false */ - R registerUser(UserDTO userDto); + R registerUser(RegisterUserDTO userDto); /** * 锁定用户 diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java index c416e17d..cbe47097 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java @@ -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 impl */ @Override @Transactional(rollbackFor = Exception.class) - public R registerUser(UserDTO userDto) { + public R registerUser(RegisterUserDTO userDto) { // 判断用户名是否存在 SysUser sysUser = this.getOne(Wrappers.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)); } /**