mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-02-27 16:50:24 +08:00
新增 StpLogic#getOrCreateLoginSession 方法,获取指定账号 id 的登录会话数据,如果获取不到则创建并返回
This commit is contained in:
@@ -37,7 +37,6 @@ import cn.dev33.satoken.util.SaTokenConsts;
|
||||
import cn.dev33.satoken.util.SaValue2Box;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
@@ -591,6 +590,20 @@ public class StpLogic {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定账号 id 的登录会话数据,如果获取不到则创建并返回
|
||||
*
|
||||
* @param id 账号id,建议的类型:(long | int | String)
|
||||
* @return 返回会话令牌
|
||||
*/
|
||||
public String getOrCreateLoginSession(Object id) {
|
||||
String tokenValue = getTokenValueByLoginId(id);
|
||||
if(tokenValue == null) {
|
||||
tokenValue = createLoginSession(id, new SaLoginModel());
|
||||
}
|
||||
return tokenValue;
|
||||
}
|
||||
|
||||
// --- 注销
|
||||
|
||||
/**
|
||||
|
||||
@@ -224,7 +224,17 @@ public class StpUtil {
|
||||
public static String createLoginSession(Object id, SaLoginModel loginModel) {
|
||||
return stpLogic.createLoginSession(id, loginModel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取指定账号 id 的登录会话数据,如果获取不到则创建并返回
|
||||
*
|
||||
* @param id 账号id,建议的类型:(long | int | String)
|
||||
* @return 返回会话令牌
|
||||
*/
|
||||
public static String getOrCreateLoginSession(Object id) {
|
||||
return stpLogic.getOrCreateLoginSession(id);
|
||||
}
|
||||
|
||||
// --- 注销
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user