|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.ruoyi.common.satoken.utils;
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.context.SaHolder;
|
|
|
|
|
import cn.dev33.satoken.context.model.SaStorage;
|
|
|
|
|
import cn.dev33.satoken.stp.SaLoginModel;
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
@ -46,7 +47,9 @@ public class LoginHelper {
|
|
|
|
|
* @param loginUser 登录用户信息
|
|
|
|
|
*/
|
|
|
|
|
public static void loginByDevice(LoginUser loginUser, DeviceType deviceType) {
|
|
|
|
|
SaHolder.getStorage().set(LOGIN_USER_KEY, loginUser);
|
|
|
|
|
SaStorage storage = SaHolder.getStorage();
|
|
|
|
|
storage.set(LOGIN_USER_KEY, loginUser);
|
|
|
|
|
storage.set(USER_KEY, loginUser.getUserId());
|
|
|
|
|
SaLoginModel model = new SaLoginModel();
|
|
|
|
|
if (ObjectUtil.isNotNull(deviceType)) {
|
|
|
|
|
model.setDevice(deviceType.getDevice());
|
|
|
|
@ -81,7 +84,11 @@ public class LoginHelper {
|
|
|
|
|
public static Long getUserId() {
|
|
|
|
|
Long userId;
|
|
|
|
|
try {
|
|
|
|
|
userId = Convert.toLong(StpUtil.getExtra(USER_KEY));
|
|
|
|
|
userId = Convert.toLong(SaHolder.getStorage().get(USER_KEY));
|
|
|
|
|
if (ObjectUtil.isNull(userId)) {
|
|
|
|
|
userId = Convert.toLong(StpUtil.getExtra(USER_KEY).toString());
|
|
|
|
|
SaHolder.getStorage().set(USER_KEY, userId);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|