【新增】 账号只能登录一个学生端或者后台管理

This commit is contained in:
DESKTOP-932OMT8\REN
2025-06-16 21:40:09 +08:00
parent ad0a4229eb
commit 70ad20151a

View File

@@ -2,9 +2,11 @@ package pc.exam.pp.module.system.controller.admin.auth;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.data.redis.core.StringRedisTemplate;
import pc.exam.pp.framework.common.enums.CommonStatusEnum;
import pc.exam.pp.framework.common.enums.UserTypeEnum;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.framework.common.util.json.JsonUtils;
import pc.exam.pp.framework.security.config.SecurityProperties;
import pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils;
import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
@@ -12,6 +14,7 @@ import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
import pc.exam.pp.module.infra.service.config.ConfigService;
import pc.exam.pp.module.system.controller.admin.auth.vo.*;
import pc.exam.pp.module.system.convert.auth.AuthConvert;
import pc.exam.pp.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
import pc.exam.pp.module.system.dal.dataobject.permission.MenuDO;
import pc.exam.pp.module.system.dal.dataobject.permission.RoleDO;
import pc.exam.pp.module.system.dal.dataobject.user.AdminUserDO;
@@ -36,6 +39,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static pc.exam.pp.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -72,6 +76,8 @@ public class AuthController {
@Resource
private ConfigService configService;
@Resource
private StringRedisTemplate stringRedisTemplate;
@GetMapping("/login_config")
@PermitAll
@@ -96,6 +102,15 @@ public class AuthController {
if (Integer.parseInt(reqVO.getUserType()) == 2) {
if (Integer.parseInt(adminUserDO.getUserType()) <= 1) return error(STUDENT_USERNAME_NOTLOGIN);
}
Set<String> oauth2_access_token_set = stringRedisTemplate.keys("oauth2_access_token:*");
for (String oauth2_access_token : oauth2_access_token_set) {
OAuth2AccessTokenDO oAuth2AccessTokenDO = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(oauth2_access_token), OAuth2AccessTokenDO.class);
// 判断账号是否登录过
if (oAuth2AccessTokenDO.getUserInfo().get("username").equals(reqVO.getUsername())) {
// 说明登录了,别的地方登录了,请重新登录
return CommonResult.error(900001, "该账号已经登录");
}
}
return success(authService.login(reqVO));
}