fix
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.starry.admin.modules.platform.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
@@ -77,7 +78,17 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
public SysTenantEntity selectByTenantKey(String tenantKey) {
|
||||
LambdaQueryWrapper<SysTenantEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(SysTenantEntity::getTenantKey, tenantKey);
|
||||
return this.baseMapper.selectOne(lambdaQueryWrapper);
|
||||
SysTenantEntity tenant = this.baseMapper.selectOne(lambdaQueryWrapper);
|
||||
if (Objects.isNull(tenant)) {
|
||||
throw new RuntimeException("租户信息异常");
|
||||
}
|
||||
if (DateUtil.compare(tenant.getTenantTime(), new Date()) < 0) {
|
||||
throw new RuntimeException("当前租户已过期,无法继续使用");
|
||||
}
|
||||
if (tenant.getTenantStatus().equals("1")) {
|
||||
throw new RuntimeException("当前租户已被禁用");
|
||||
}
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.starry.admin.modules.system.service.LoginService;
|
||||
import com.starry.admin.modules.system.service.SysMenuService;
|
||||
import com.starry.admin.modules.system.vo.LoginVo;
|
||||
import com.starry.admin.modules.system.vo.RouterVo;
|
||||
import com.starry.admin.modules.system.vo.TenantLoginVo;
|
||||
import com.starry.admin.utils.SecurityUtils;
|
||||
import com.starry.common.redis.CaptchaService;
|
||||
import com.starry.common.result.R;
|
||||
@@ -107,25 +106,25 @@ public class LoginController {
|
||||
}
|
||||
}
|
||||
// 用户登录
|
||||
LoginUser userInfo = loginService.newLogin(loginVo.getUserName(), loginVo.getPassWord());
|
||||
LoginUser userInfo = loginService.newLogin(loginVo.getUserName(), loginVo.getPassWord(), loginVo.getTenantKey());
|
||||
Map<String, Object> tokenMap = jwtToken.createToken(userInfo);
|
||||
return R.ok(tokenMap);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "租户登录")
|
||||
@PostMapping(value = "tenant/login")
|
||||
public R TenantLoginVo(@RequestBody TenantLoginVo loginVo) {
|
||||
// 只有开启了验证码功能才需要验证
|
||||
if (needAuthCode) {
|
||||
String msg = captchaService.checkImageCode(loginVo.getNonceStr(), loginVo.getValue());
|
||||
if (StringUtils.isNotBlank(msg)) {
|
||||
return R.error(msg);
|
||||
}
|
||||
}
|
||||
// 用户登录
|
||||
LoginUser userInfo = loginService.tenantLogin(loginVo.getTenantkey(), loginVo.getUserName(), loginVo.getPassWord());
|
||||
Map<String, Object> tokenMap = jwtToken.createToken(userInfo);
|
||||
return R.ok(tokenMap);
|
||||
}
|
||||
//@ApiOperation(value = "租户登录")
|
||||
//@PostMapping(value = "tenant/login")
|
||||
//public R TenantLoginVo(@RequestBody TenantLoginVo loginVo) {
|
||||
// // 只有开启了验证码功能才需要验证
|
||||
// if (needAuthCode) {
|
||||
// String msg = captchaService.checkImageCode(loginVo.getNonceStr(), loginVo.getValue());
|
||||
// if (StringUtils.isNotBlank(msg)) {
|
||||
// return R.error(msg);
|
||||
// }
|
||||
// }
|
||||
// // 用户登录
|
||||
// LoginUser userInfo = loginService.tenantLogin(loginVo.getTenantkey(), loginVo.getUserName(), loginVo.getPassWord());
|
||||
// Map<String, Object> tokenMap = jwtToken.createToken(userInfo);
|
||||
// return R.ok(tokenMap);
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -82,4 +82,7 @@ public interface SysUserMapper extends MPJBaseMapper<SysUserEntity> {
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
IPage<RoleUserResultVo> selectUnallocatedList(Page<RoleUserResultVo> page, @Param("query") SysUserQueryVo user);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "1")
|
||||
SysUserEntity selectUserByUserNameAndTenantId(@Param("userName") String userName, @Param("tenantId")String tenantId);
|
||||
}
|
||||
|
||||
@@ -52,15 +52,17 @@ public interface LoginService {
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @param tenantKey
|
||||
* @return 生成的JWT的token
|
||||
*/
|
||||
LoginUser newLogin(String username, String password);
|
||||
LoginUser newLogin(String username, String password, String tenantKey);
|
||||
|
||||
/**
|
||||
* 新登录功能,增加租户相关
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param tenantId
|
||||
* @return 获取信息
|
||||
*/
|
||||
LoginUser getLoginUserInfo( String userName);
|
||||
LoginUser getLoginUserInfo(String userName, String tenantId);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ public interface SysUserService extends IService<SysUserEntity> {
|
||||
*/
|
||||
SysUserEntity selectUserByUserName(String userName);
|
||||
|
||||
SysUserEntity selectUserByUserNameAndTenantId(String userName, String tenantId);
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有账户
|
||||
@@ -50,6 +52,7 @@ public interface SysUserService extends IService<SysUserEntity> {
|
||||
* @return 查询所有账户
|
||||
*/
|
||||
List<SysUserEntity> selectAll();
|
||||
|
||||
/**
|
||||
* 分页查询用户
|
||||
*
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.starry.admin.manager.AsyncManager;
|
||||
import com.starry.admin.manager.factory.AsyncFactory;
|
||||
import com.starry.admin.modules.platform.entity.SysTenantEntity;
|
||||
import com.starry.admin.modules.platform.service.ISysTenantService;
|
||||
import com.starry.admin.modules.play.service.IPlayUserInfoService;
|
||||
import com.starry.admin.modules.system.entity.SysUserEntity;
|
||||
import com.starry.admin.modules.system.service.LoginService;
|
||||
import com.starry.admin.modules.system.service.SysMenuService;
|
||||
@@ -57,8 +56,6 @@ public class LoginServiceImpl implements LoginService {
|
||||
@Resource
|
||||
private ISysTenantService SysTenantService;
|
||||
|
||||
@Resource
|
||||
private IPlayUserInfoService playUserInfoService;
|
||||
|
||||
@Override
|
||||
public String login(String username, String password) {
|
||||
@@ -108,14 +105,14 @@ public class LoginServiceImpl implements LoginService {
|
||||
|
||||
@Override
|
||||
public LoginUser tenantLogin(String tenantId, String username, String password) {
|
||||
LoginUser userInfo = this.getLoginUserInfo(username);
|
||||
//LoginUser userInfo = this.getLoginUserInfo(username);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser newLogin(String username, String password) {
|
||||
public LoginUser newLogin(String username, String password, String tenantKey) {
|
||||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isAnyBlank(username, password)) {
|
||||
if (StringUtils.isAnyBlank(username, password, tenantKey)) {
|
||||
// 登录记录日志
|
||||
AsyncManager.me().execute(AsyncFactory.recordLoginLog(username, Constants.LOGIN_FAIL, "用户名/密码必须填写"));
|
||||
throw new ServiceException("用户/密码必须填写");
|
||||
@@ -132,7 +129,8 @@ public class LoginServiceImpl implements LoginService {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLoginLog(username, Constants.LOGIN_FAIL, "用户名不在指定范围"));
|
||||
throw new ServiceException("用户名不在指定范围");
|
||||
}
|
||||
LoginUser userInfo = this.getLoginUserInfo(username);
|
||||
SysTenantEntity tenant = SysTenantService.selectByTenantKey(tenantKey);
|
||||
LoginUser userInfo = this.getLoginUserInfo(username, tenant.getTenantId());
|
||||
if (userInfo == null) {
|
||||
// 登录记录日志
|
||||
AsyncManager.me().execute(AsyncFactory.recordLoginLog(username, Constants.LOGIN_FAIL, "用户名不存在"));
|
||||
@@ -167,8 +165,14 @@ public class LoginServiceImpl implements LoginService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser getLoginUserInfo(String userName) {
|
||||
SysUserEntity sysUser = sysUserService.selectUserByUserName(userName);
|
||||
public LoginUser getLoginUserInfo(String userName, String tenantId) {
|
||||
SysUserEntity sysUser;
|
||||
if (userName.equals("sysadmin")) {
|
||||
sysUser = sysUserService.selectUserByUserNameAndTenantId(userName, tenantId);
|
||||
} else {
|
||||
sysUser = sysUserService.selectUserByUserNameAndTenantId(userName, tenantId);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotNull(sysUser)) {
|
||||
// SecurityUtils.setTenantId(sysUser.getTenantId());
|
||||
// 角色集合
|
||||
|
||||
@@ -142,6 +142,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
||||
return baseMapper.selectUserByUserName(userName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserEntity selectUserByUserNameAndTenantId(String userName, String tenantId) {
|
||||
return baseMapper.selectUserByUserNameAndTenantId(userName, tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<SysUserEntity> listMemberPage(UserQueryVo queryVo) {
|
||||
Page<SysUserEntity> page = new Page<>(queryVo.getPageNum(), queryVo.getPageSize());
|
||||
@@ -345,7 +350,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
||||
public void logoutUser(String uid) {
|
||||
String key = "login:resource:" + uid;
|
||||
Object object = redisCache.getCacheObject(key);
|
||||
if(Objects.isNull(object)) return;
|
||||
if (Objects.isNull(object)) return;
|
||||
|
||||
String key2 = object.toString();
|
||||
redisCache.deleteObject(key2);
|
||||
|
||||
@@ -23,4 +23,6 @@ public class LoginVo implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "验证值")
|
||||
private String value;
|
||||
|
||||
private String tenantKey;
|
||||
}
|
||||
|
||||
@@ -107,6 +107,11 @@
|
||||
where u.user_code = #{userName} and u.deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectUserByUserNameAndTenantId" resultMap="BaseResultMap">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.user_code = #{userName} and u.deleted = 0 and u.tenant_id = #{tenantId}
|
||||
</select>
|
||||
|
||||
<select id="checkUserNameUnique" parameterType="String" resultType="int">
|
||||
select count(1) from sys_user where user_code = #{userName} and deleted = 0 limit 1
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user