mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-16 05:13:41 +00:00
[fix][feat](chat): 添加会话中SaToken-token值传递和使用;修复“自动注入警告 => 用户未登录”
- 新增 BaseContext 类,用于保存和获取当前登录用户的 token - 在 OpenAIServiceImpl 和 imageServiceImpl 中获取当前会话 token - 将 token 作为参数传递给 SSEEventSourceListener - 在 SSEEventSourceListener 中使用 token 进行用户身份验证和权限控制 - 修改 LoginHelper,增加根据 token 获取登录用户信息的方法 - 更新 InjectionMetaObjectHandler,使用 BaseContext 获取当前 token - 修复对话时出先”自动注入警告 => 用户未登录“
This commit is contained in:
@@ -9,12 +9,16 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.ruoyi.common.core.constant.TenantConstants;
|
||||
import org.ruoyi.common.core.constant.UserConstants;
|
||||
import org.ruoyi.common.core.domain.model.LoginUser;
|
||||
import org.ruoyi.common.core.enums.DeviceType;
|
||||
import org.ruoyi.common.core.enums.UserType;
|
||||
import org.ruoyi.common.redis.utils.RedisUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -29,6 +33,7 @@ import java.util.Set;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class LoginHelper {
|
||||
|
||||
@@ -82,6 +87,15 @@ public class LoginHelper {
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
|
||||
public static <T extends LoginUser> T getLoginUser(String token) {
|
||||
SaSession session = StpUtil.getTokenSessionByToken(token);
|
||||
if (ObjectUtil.isNull(session)) {
|
||||
return null;
|
||||
}
|
||||
return (T) session.get(LOGIN_USER_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户id
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user