From d2f61fc241d5acc4154815466b8673661efd5e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 31 Jul 2023 17:16:43 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=9F=A5=E8=AF=A2=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/system/api/RemoteUserService.java | 9 +++++++++ .../auth/service/impl/SocialAuthStrategy.java | 2 +- .../system/dubbo/RemoteUserServiceImpl.java | 20 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java index 6720720b..c8382c59 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java @@ -21,6 +21,15 @@ public interface RemoteUserService { */ LoginUser getUserInfo(String username, String tenantId) throws UserException; + /** + * 通过用户id查询用户信息 + * + * @param userId 用户id + * @param tenantId 租户id + * @return 结果 + */ + LoginUser getUserInfo(Long userId, String tenantId) throws UserException; + /** * 通过手机号查询用户信息 * diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java index cd1db9f5..06c608c2 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java @@ -90,7 +90,7 @@ public class SocialAuthStrategy implements IAuthStrategy { throw new ServiceException("对不起,你没有权限登录当前租户!"); } - LoginUser loginUser = remoteUserService.getUserInfo(socialVo.getUserName(), tenantId); + LoginUser loginUser = remoteUserService.getUserInfo(socialVo.getUserId(), tenantId); SaLoginModel model = new SaLoginModel(); model.setDevice(client.getDeviceType()); // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java index a7e90904..26ae16fe 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java @@ -62,6 +62,26 @@ public class RemoteUserServiceImpl implements RemoteUserService { return buildLoginUser(userMapper.selectUserByUserName(username)); } + @Override + public LoginUser getUserInfo(Long userId, String tenantId) throws UserException { + SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper() + .select(SysUser::getUserName, SysUser::getStatus) + .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId) + .eq(SysUser::getUserId, userId)); + if (ObjectUtil.isNull(sysUser)) { + throw new UserException("user.not.exists", ""); + } + if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus())) { + throw new UserException("user.blocked", sysUser.getUserName()); + } + // 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可 + // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 + if (TenantHelper.isEnable()) { + return buildLoginUser(userMapper.selectTenantUserByUserName(sysUser.getUserName(), tenantId)); + } + return buildLoginUser(userMapper.selectUserByUserName(sysUser.getUserName())); + } + @Override public LoginUser getUserInfoByPhonenumber(String phonenumber, String tenantId) throws UserException { SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper()