diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java index 35bc207..9257330 100644 --- a/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java +++ b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java @@ -294,7 +294,6 @@ public interface UserApi { * @param username 用户名 * @return ResultWrapper */ - //@GetMapping("/getUserByUsername") ResultWrapper getUserByUsername(String username); /** @@ -311,6 +310,11 @@ public interface UserApi { */ ResultWrapper getUserByEmail(String email); - + /** + * 用户信息 查一条 + * @param id ID + * @return ResultWrapper + */ + ResultWrapper getById(String id); } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserUtil.java index a3dbfae..1b716af 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserUtil.java @@ -174,16 +174,7 @@ public class UserUtil { Object cache = SecurityCache.get(redisTemplate, cacheKey, (k) -> { // 查询数据库 - UserModel userModelTemp = new UserModel(); - userModelTemp.setId(userId); - // 设置为系统内部调用 否则 会拿到 空值 - userModelTemp.setIzApi(true); - - // 查询数据库 - ResultWrapper resultVo = userApi.get(userModelTemp); - if(!ResultWrapper.isSuccess(resultVo)){ - return null; - } + ResultWrapper resultVo = userApi.getById(userId); return resultVo.getData(); }, true); diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java index ee2b9aa..705f34f 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java @@ -404,11 +404,15 @@ public class UserRestController extends BaseRestController get(UserModel model) { model = IService.get(model); + + // 防止密码泄露 + model.setPassword(null); + model.setPasswordLevel(null); + return ResultWrapper.getSuccessResultWrapper(model); } @@ -635,51 +639,6 @@ public class UserRestController extends BaseRestController getUserByUsername(String username) { - UserModel userModel = IService.queryByUserName(username); - if(userModel == null){ - // 暂无该用户 - throw new ServiceException(SystemMsg.EXCEPTION_USER_NULL.getCode(), - StrUtil.format(SystemMsg.EXCEPTION_USER_NULL.getMessage(), username) - ); - } - return ResultWrapper.getSuccessResultWrapper(userModel); - } - - @ApiOperation(value = "根据 手机号 获得用户", notes = "根据 手机号 获得用户") - @Override - public ResultWrapper getUserByMobile(String mobile) { - UserModel userModel = IService.queryByMobile(mobile); - if(userModel == null){ - // 暂无该用户 - throw new ServiceException(SystemMsg.EXCEPTION_USER_NULL.getCode(), - StrUtil.format(SystemMsg.EXCEPTION_USER_NULL.getMessage(), mobile) - ); - } - return ResultWrapper.getSuccessResultWrapper(userModel); - } - - @ApiOperation(value = "根据 邮箱 获得用户", notes = "根据 邮箱 获得用户") - @Override - public ResultWrapper getUserByEmail(String email) { - UserModel userModel = IService.queryByEmail(email); - if(userModel == null){ - // 暂无该用户 - throw new ServiceException(SystemMsg.EXCEPTION_USER_NULL.getCode(), - StrUtil.format(SystemMsg.EXCEPTION_USER_NULL.getMessage(), email) - ); - } - return ResultWrapper.getSuccessResultWrapper(userModel); - } - /** * 切换租户 * @param tenantId 租户ID @@ -765,4 +724,61 @@ public class UserRestController extends BaseRestController getUserByUsername(String username) { + UserModel userModel = IService.queryByUserName(username); + if(userModel == null){ + // 暂无该用户 + throw new ServiceException(SystemMsg.EXCEPTION_USER_NULL.getCode(), + StrUtil.format(SystemMsg.EXCEPTION_USER_NULL.getMessage(), username) + ); + } + return ResultWrapper.getSuccessResultWrapper(userModel); + } + + @ApiOperation(value = "根据 手机号 获得用户", notes = "根据 手机号 获得用户") + @Override + public ResultWrapper getUserByMobile(String mobile) { + UserModel userModel = IService.queryByMobile(mobile); + if(userModel == null){ + // 暂无该用户 + throw new ServiceException(SystemMsg.EXCEPTION_USER_NULL.getCode(), + StrUtil.format(SystemMsg.EXCEPTION_USER_NULL.getMessage(), mobile) + ); + } + return ResultWrapper.getSuccessResultWrapper(userModel); + } + + @ApiOperation(value = "根据 邮箱 获得用户", notes = "根据 邮箱 获得用户") + @Override + public ResultWrapper getUserByEmail(String email) { + UserModel userModel = IService.queryByEmail(email); + if(userModel == null){ + // 暂无该用户 + throw new ServiceException(SystemMsg.EXCEPTION_USER_NULL.getCode(), + StrUtil.format(SystemMsg.EXCEPTION_USER_NULL.getMessage(), email) + ); + } + return ResultWrapper.getSuccessResultWrapper(userModel); + } + + /** + * 用户信息 查一条 + * @param id 模型 + * @return ResultWrapper + */ + @ApiOperation(value = "根据 ID 获得用户", notes = "根据 ID 获得用户") + @Override + public ResultWrapper getById(String id) { + UserModel userModel = IService.get(id); + return ResultWrapper.getSuccessResultWrapper(userModel); + } + }