From 30c1a9293ac0e35583abc61f538f79023464b63a Mon Sep 17 00:00:00 2001 From: "MSI\\letre" Date: Thu, 10 Jul 2025 18:02:15 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E7=AE=A1=E7=90=86=E5=91=98=E5=AF=86=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E7=99=BB=E5=87=BA=E6=8C=87=E5=AE=9A=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/auth/AuthController.java | 25 +++++++++++++++++-- .../controller/admin/auth/vo/LoginoutVo.java | 11 ++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/vo/LoginoutVo.java diff --git a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/AuthController.java b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/AuthController.java index 08b5006d..9d717d28 100644 --- a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/AuthController.java +++ b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/AuthController.java @@ -108,7 +108,7 @@ public class AuthController { // 判断账号是否登录过 if (oAuth2AccessTokenDO.getUserInfo().get("username").equals(reqVO.getUsername())) { // 说明登录了,别的地方登录了,请重新登录 - return CommonResult.error(900001, "该账号已经登录"); + return CommonResult.error(900001, "该账号已经登录!"); } } return success(authService.login(reqVO)); @@ -125,7 +125,28 @@ public class AuthController { } return success(true); } - + @PostMapping("/refreshLogout") + @PermitAll + @TenantIgnore + @Operation(summary = "使用管理员密码强制登出用户") + public CommonResult refreshLoginout(@RequestBody LoginoutVo loginoutVo) { + // 先判断管理员密码 + ConfigDO config = configService.getConfigByKey("system_username_logout"); + if (!config.getValue().equals(loginoutVo.getLoginOutPassword())) { + return CommonResult.error(900002, "系统管理员密码错误!"); + } + Set 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(loginoutVo.getUsername())) { + // 说明登录了,别的地方登录了,请重新登录 + stringRedisTemplate.opsForValue().getAndDelete(oauth2_access_token); + break; + } + } + return success("退出成功,请重新输入用户名密码登录!"); + } @PostMapping("/refresh-token") @PermitAll @Operation(summary = "刷新令牌") diff --git a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/vo/LoginoutVo.java b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/vo/LoginoutVo.java new file mode 100644 index 00000000..3c9d1e7b --- /dev/null +++ b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/controller/admin/auth/vo/LoginoutVo.java @@ -0,0 +1,11 @@ +package pc.exam.pp.module.system.controller.admin.auth.vo; + +import lombok.Data; + +@Data +public class LoginoutVo { + + private String loginOutPassword; + + private String username; +}