From b52c250cd4039263364d8ef3683b61b994bdac84 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Tue, 31 Mar 2026 19:49:48 +0800
Subject: [PATCH] 支持表格列显隐状态记忆
---
ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java | 97 ++++++++++++++++++++++++++++++------------------
1 files changed, 61 insertions(+), 36 deletions(-)
diff --git a/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java b/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java
index 4058f75..beb8615 100644
--- a/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java
+++ b/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java
@@ -1,20 +1,22 @@
package com.ruoyi.auth.controller;
-import java.util.Map;
+import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpHeaders;
-import org.springframework.security.oauth2.common.OAuth2AccessToken;
-import org.springframework.security.oauth2.common.OAuth2RefreshToken;
-import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
-import com.ruoyi.common.core.constant.Constants;
-import com.ruoyi.common.core.constant.SecurityConstants;
+import com.ruoyi.auth.form.LoginBody;
+import com.ruoyi.auth.form.RegisterBody;
+import com.ruoyi.auth.form.UnLockBody;
+import com.ruoyi.auth.service.SysLoginService;
import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.JwtUtils;
import com.ruoyi.common.core.utils.StringUtils;
-import com.ruoyi.system.api.RemoteLogService;
+import com.ruoyi.common.security.auth.AuthUtil;
+import com.ruoyi.common.security.service.TokenService;
+import com.ruoyi.common.security.utils.SecurityUtils;
+import com.ruoyi.system.api.model.LoginUser;
/**
* token 控制
@@ -22,43 +24,66 @@
* @author ruoyi
*/
@RestController
-@RequestMapping("/token")
public class TokenController
{
@Autowired
- private TokenStore tokenStore;
+ private TokenService tokenService;
@Autowired
- private RemoteLogService remoteLogService;
+ private SysLoginService sysLoginService;
- @DeleteMapping("/logout")
- public R<?> logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader)
+ @PostMapping("login")
+ public R<?> login(@RequestBody LoginBody form)
{
- if (StringUtils.isEmpty(authHeader))
- {
- return R.ok();
- }
+ // 用户登录
+ LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
+ // 获取登录token
+ return R.ok(tokenService.createToken(userInfo));
+ }
- String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE, StringUtils.EMPTY).trim();
- OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
- if (accessToken == null || StringUtils.isEmpty(accessToken.getValue()))
+ @DeleteMapping("logout")
+ public R<?> logout(HttpServletRequest request)
+ {
+ String token = SecurityUtils.getToken(request);
+ if (StringUtils.isNotEmpty(token))
{
- return R.ok();
- }
-
- // 清空 access token
- tokenStore.removeAccessToken(accessToken);
-
- // 清空 refresh token
- OAuth2RefreshToken refreshToken = accessToken.getRefreshToken();
- tokenStore.removeRefreshToken(refreshToken);
- Map<String, ?> map = accessToken.getAdditionalInformation();
- if (map.containsKey(SecurityConstants.DETAILS_USERNAME))
- {
- String username = (String) map.get(SecurityConstants.DETAILS_USERNAME);
+ String username = JwtUtils.getUserName(token);
+ // 删除用户缓存记录
+ AuthUtil.logoutByToken(token);
// 记录用户退出日志
- remoteLogService.saveLogininfor(username, Constants.LOGOUT, "退出成功");
+ sysLoginService.logout(username);
}
return R.ok();
}
+
+ @PostMapping("refresh")
+ public R<?> refresh(HttpServletRequest request)
+ {
+ LoginUser loginUser = tokenService.getLoginUser(request);
+ if (StringUtils.isNotNull(loginUser))
+ {
+ // 刷新令牌有效期
+ tokenService.refreshToken(loginUser);
+ return R.ok();
+ }
+ return R.ok();
+ }
+
+ @PostMapping("register")
+ public R<?> register(@RequestBody RegisterBody registerBody)
+ {
+ // 用户注册
+ sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
+ return R.ok();
+ }
+
+ /**
+ * 解锁屏幕
+ */
+ @PostMapping("/unlockscreen")
+ public R<?> unlockScreen(@RequestBody UnLockBody unLockBody)
+ {
+ sysLoginService.unlock(unLockBody.getPassword());
+ return R.ok();
+ }
}
--
Gitblit v1.9.3