1、重置密码改为生成随机密码
2、新增手动重置密码
This commit is contained in:
@@ -188,9 +188,8 @@ public class UserController {
|
||||
@PostMapping("/reset-password")
|
||||
@ApiOperationSupport(order = 9)
|
||||
@Operation(summary = "初始化密码", description = "传入userId集合")
|
||||
public R resetPassword(@Parameter(description = "userId集合", required = true) @RequestParam String userIds) {
|
||||
boolean temp = userService.resetPassword(userIds);
|
||||
return R.status(temp);
|
||||
public R<Map<String, String>> resetPassword(@Parameter(description = "userId集合", required = true) @RequestParam String userIds) {
|
||||
return R.data(userService.resetPassword(userIds));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,11 +205,24 @@ public class UserController {
|
||||
return R.status(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员修改密码
|
||||
*/
|
||||
@IsAdmin
|
||||
@PostMapping("/set-password")
|
||||
@ApiOperationSupport(order = 11)
|
||||
@Operation(summary = "管理员修改密码", description = "传入用户ID与新密码")
|
||||
public R setPassword(@Parameter(description = "用户ID", required = true) @RequestParam Long userId,
|
||||
@Parameter(description = "新密码", required = true) @RequestParam String password,
|
||||
@Parameter(description = "确认密码", required = true) @RequestParam String password2) {
|
||||
return R.status(userService.setPassword(userId, password, password2));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改基本信息
|
||||
*/
|
||||
@PostMapping("/update-info")
|
||||
@ApiOperationSupport(order = 11)
|
||||
@ApiOperationSupport(order = 12)
|
||||
@Operation(summary = "修改基本信息", description = "传入User")
|
||||
public R updateInfo(@Valid @RequestBody User user) {
|
||||
return R.status(userService.updateUserInfo(user));
|
||||
@@ -221,7 +233,7 @@ public class UserController {
|
||||
*/
|
||||
@GetMapping("/user-list")
|
||||
@BladeView(Views.Admin.class)
|
||||
@ApiOperationSupport(order = 12)
|
||||
@ApiOperationSupport(order = 13)
|
||||
@Operation(summary = "用户列表", description = "传入user")
|
||||
public R<List<UserVO>> userList(User user, BladeUser bladeUser) {
|
||||
QueryWrapper<User> queryWrapper = Condition.getQueryWrapper(user);
|
||||
@@ -234,7 +246,7 @@ public class UserController {
|
||||
*/
|
||||
@GetMapping("/user-page")
|
||||
@BladeView(Views.Admin.class)
|
||||
@ApiOperationSupport(order = 13)
|
||||
@ApiOperationSupport(order = 14)
|
||||
@Operation(summary = "用户分页(排除管理员)", description = "分页查询非管理员角色用户")
|
||||
public R<IPage<UserVO>> userPage(Query query, @RequestParam(required = false) String account, @RequestParam(required = false) String name) {
|
||||
return R.data(userService.userPage(Condition.getPage(query), account, name));
|
||||
@@ -245,7 +257,7 @@ public class UserController {
|
||||
*/
|
||||
@IsAdmin
|
||||
@PostMapping("import-user")
|
||||
@ApiOperationSupport(order = 14)
|
||||
@ApiOperationSupport(order = 15)
|
||||
@Operation(summary = "导入用户", description = "传入excel")
|
||||
public R importUser(MultipartFile file, Integer isCovered) {
|
||||
UserImporter userImporter = new UserImporter(userService, isCovered == 1);
|
||||
@@ -258,7 +270,7 @@ public class UserController {
|
||||
*/
|
||||
@IsAdmin
|
||||
@GetMapping("export-user")
|
||||
@ApiOperationSupport(order = 15)
|
||||
@ApiOperationSupport(order = 16)
|
||||
@Operation(summary = "导出用户", description = "传入user")
|
||||
public void exportUser(@Parameter(hidden = true) @RequestParam Map<String, Object> user, HttpServletResponse response) {
|
||||
List<UserExcel> list = userService.exportUser(user);
|
||||
@@ -269,7 +281,7 @@ public class UserController {
|
||||
* 导出模板
|
||||
*/
|
||||
@GetMapping("export-template")
|
||||
@ApiOperationSupport(order = 16)
|
||||
@ApiOperationSupport(order = 17)
|
||||
@Operation(summary = "导出模板")
|
||||
public void exportUser(HttpServletResponse response) {
|
||||
List<UserExcel> list = new ArrayList<>();
|
||||
@@ -281,7 +293,7 @@ public class UserController {
|
||||
* 第三方注册用户
|
||||
*/
|
||||
@PostMapping("/register-guest")
|
||||
@ApiOperationSupport(order = 17)
|
||||
@ApiOperationSupport(order = 18)
|
||||
@Operation(summary = "第三方注册用户", description = "传入user")
|
||||
public R registerGuest(User user, Long oauthId) {
|
||||
return R.status(userService.registerGuest(user, oauthId));
|
||||
@@ -292,7 +304,7 @@ public class UserController {
|
||||
* 配置用户平台信息
|
||||
*/
|
||||
@PostMapping("/update-platform")
|
||||
@ApiOperationSupport(order = 18)
|
||||
@ApiOperationSupport(order = 19)
|
||||
@Operation(summary = "配置用户平台信息", description = "传入user")
|
||||
public R updatePlatform(Long userId, Integer userType, String userExt) {
|
||||
return R.status(userService.updatePlatform(userId, userType, userExt));
|
||||
@@ -303,7 +315,7 @@ public class UserController {
|
||||
*/
|
||||
@IsAdmin
|
||||
@BladeView(Views.Admin.class)
|
||||
@ApiOperationSupport(order = 19)
|
||||
@ApiOperationSupport(order = 20)
|
||||
@Operation(summary = "查看平台详情", description = "传入id")
|
||||
@GetMapping("/platform-detail")
|
||||
public R<UserVO> platformDetail(User user) {
|
||||
@@ -315,7 +327,7 @@ public class UserController {
|
||||
*/
|
||||
@IsAdmin
|
||||
@PostMapping("/audit-pass")
|
||||
@ApiOperationSupport(order = 20)
|
||||
@ApiOperationSupport(order = 21)
|
||||
@Operation(summary = "审核通过", description = "传入id集合")
|
||||
public R auditPass(String userIds) {
|
||||
return R.status(userService.auditPass(userIds));
|
||||
@@ -326,7 +338,7 @@ public class UserController {
|
||||
*/
|
||||
@IsAdmin
|
||||
@PostMapping("/audit-refuse")
|
||||
@ApiOperationSupport(order = 21)
|
||||
@ApiOperationSupport(order = 22)
|
||||
@Operation(summary = "审核拒绝", description = "传入id集合")
|
||||
public R auditRefuse(String userIds) {
|
||||
return R.status(userService.auditRefuse(userIds));
|
||||
@@ -337,7 +349,7 @@ public class UserController {
|
||||
*/
|
||||
@IsAdmin
|
||||
@PostMapping("/set-leader")
|
||||
@ApiOperationSupport(order = 22)
|
||||
@ApiOperationSupport(order = 23)
|
||||
@Operation(summary = "设置用户为主管", description = "传入userId")
|
||||
public R setLeader(@Parameter(description = "userId", required = true) @RequestParam Long userId) {
|
||||
return R.status(userService.setLeader(userId));
|
||||
@@ -349,7 +361,7 @@ public class UserController {
|
||||
@IsAdmin
|
||||
@GetMapping("/leader-info")
|
||||
@BladeView(Views.Admin.class)
|
||||
@ApiOperationSupport(order = 23)
|
||||
@ApiOperationSupport(order = 24)
|
||||
@Operation(summary = "获取用户的主管信息", description = "传入userId")
|
||||
public R<List<UserVO>> leaderInfo(@Parameter(description = "userId", required = true) @RequestParam Long userId) {
|
||||
List<UserVO> list = userService.leaderInfo(userId);
|
||||
@@ -362,7 +374,7 @@ public class UserController {
|
||||
@IsAdmin
|
||||
@GetMapping("/leader-list")
|
||||
@BladeView(Views.Admin.class)
|
||||
@ApiOperationSupport(order = 24)
|
||||
@ApiOperationSupport(order = 25)
|
||||
@Operation(summary = "获取主管列表", description = "获取所有主管用户列表")
|
||||
public R<List<UserVO>> leaderList(@Parameter(description = "租户编号") String tenantId, @Parameter(description = "用户姓名") String realName) {
|
||||
List<UserVO> list = userService.leaderList(tenantId, realName);
|
||||
|
||||
@@ -196,12 +196,22 @@ public interface IUserService extends BaseService<User> {
|
||||
boolean grant(String userIds, String roleIds);
|
||||
|
||||
/**
|
||||
* 重置用户密码为系统默认密码(批量租户守卫校验)
|
||||
* 重置用户密码为随机密码(批量租户守卫校验)
|
||||
*
|
||||
* @param userIds 用户ID集合(逗号分隔)
|
||||
* @return 账号与随机密码映射
|
||||
*/
|
||||
Map<String, String> resetPassword(String userIds);
|
||||
|
||||
/**
|
||||
* 管理员修改用户密码(租户守卫校验)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param password 新密码
|
||||
* @param password2 确认新密码
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean resetPassword(String userIds);
|
||||
boolean setPassword(Long userId, String password, String password2);
|
||||
|
||||
/**
|
||||
* 修改当前用户密码
|
||||
|
||||
@@ -66,8 +66,10 @@ import org.springblade.system.wrapper.UserWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -85,6 +87,9 @@ import static org.springblade.core.tenant.TenantGuard.EntityType.USER;
|
||||
@AllArgsConstructor
|
||||
public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements IUserService {
|
||||
private static final String GUEST_NAME = "guest";
|
||||
private static final String PASSWORD_CHARS = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789";
|
||||
private static final int RANDOM_PASSWORD_LENGTH = 8;
|
||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
||||
|
||||
private final IUserDeptService userDeptService;
|
||||
private final IUserOauthService userOauthService;
|
||||
@@ -339,15 +344,33 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean resetPassword(String userIds) {
|
||||
public Map<String, String> resetPassword(String userIds) {
|
||||
List<Long> idList = Func.toLongList(userIds);
|
||||
// 租户守卫:批量校验目标用户全部归属当前会话租户
|
||||
TenantGuard.verifyBatch(this, idList, USER);
|
||||
User user = new User();
|
||||
String initPassword = ParamCache.getValue(DEFAULT_PARAM_PASSWORD);// 获取默认密码配置
|
||||
user.setPassword(DigestUtil.encrypt(Func.toStr(initPassword, ParamConstant.DEFAULT_PASSWORD)));
|
||||
user.setUpdateTime(DateUtil.now());
|
||||
return this.update(user, Wrappers.<User>update().lambda().in(User::getId, idList));
|
||||
List<User> userList = TenantGuard.verifyBatch(this, idList, USER);
|
||||
Map<String, String> passwordMap = new LinkedHashMap<>();
|
||||
for (User user : userList) {
|
||||
String password = randomPassword();
|
||||
User updateUser = new User();
|
||||
updateUser.setPassword(DigestUtil.encrypt(password));
|
||||
updateUser.setUpdateTime(DateUtil.now());
|
||||
this.update(updateUser, Wrappers.<User>update().lambda().eq(User::getId, user.getId()));
|
||||
passwordMap.put(user.getAccount(), password);
|
||||
}
|
||||
return passwordMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean setPassword(Long userId, String password, String password2) {
|
||||
if (!Objects.equals(password, password2)) {
|
||||
throw new ServiceException("两次输入密码不一致!");
|
||||
}
|
||||
User user = TenantGuard.verify(this, userId, USER);
|
||||
User updateUser = new User();
|
||||
updateUser.setPassword(DigestUtil.encrypt(password));
|
||||
updateUser.setUpdateTime(DateUtil.now());
|
||||
return this.update(updateUser, Wrappers.<User>update().lambda().eq(User::getId, user.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -751,4 +774,12 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
||||
}
|
||||
}
|
||||
|
||||
private String randomPassword() {
|
||||
StringBuilder password = new StringBuilder(RANDOM_PASSWORD_LENGTH);
|
||||
for (int index = 0; index < RANDOM_PASSWORD_LENGTH; index++) {
|
||||
password.append(PASSWORD_CHARS.charAt(SECURE_RANDOM.nextInt(PASSWORD_CHARS.length())));
|
||||
}
|
||||
return password.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -119,11 +119,11 @@ blade:
|
||||
#oauth2配置
|
||||
oauth2:
|
||||
#启用 oauth2
|
||||
enabled: false
|
||||
enabled: true
|
||||
#使用 @org.springblade.test.Sm2KeyGenerator 获取,用于国密sm2验签,需和前端保持一致
|
||||
public-key: ${BLADE_OAUTH2_PUBLIC_KEY}
|
||||
public-key: 04db3266e1a3bc32d590911a68a1c14f833c2f93edf19f23114bbb6072792d0dd40c1b25316690255d8cf5db1784995f8ade67f66e436d56913cc739c64a780d71
|
||||
#使用 @org.springblade.test.Sm2KeyGenerator 获取,用于国密sm2解密,前端无需配置
|
||||
private-key: ${BLADE_OAUTH2_PRIVATE_KEY}
|
||||
private-key: 00897f10300150fd497008574b06f1c8de315beb9ca5af531fc51f2426ae116a80
|
||||
#token配置
|
||||
token:
|
||||
#是否有状态
|
||||
|
||||
Reference in New Issue
Block a user