Commit def699a0 authored by tangtuo's avatar tangtuo

修改登录失败的异常处理

parent 52816adc
package com.fzm.admin.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.fzm.admin.auth.StpAdminUtil;
import com.fzm.common.utils.StpAdminUtil;
import com.fzm.admin.params.LoginParam;
import com.fzm.common.constant.TokenConstant;
import com.fzm.common.entity.Admin;
......
package com.fzm.admin.controller;
import cn.dev33.satoken.annotation.SaCheckLogin;
import com.fzm.admin.auth.StpAdminUtil;
import com.fzm.common.utils.StpAdminUtil;
import com.fzm.common.entity.Category;
import com.fzm.common.model.ResponseModel;
import com.fzm.common.service.CategoryService;
......
package com.fzm.admin.controller;
import cn.dev33.satoken.annotation.SaCheckLogin;
import com.fzm.admin.auth.StpAdminUtil;
import com.fzm.common.utils.StpAdminUtil;
import com.fzm.common.entity.Label;
import com.fzm.common.model.ResponseModel;
import com.fzm.common.service.LabelService;
......
package com.fzm.admin.controller;
import cn.dev33.satoken.annotation.SaCheckLogin;
import com.fzm.admin.auth.StpAdminUtil;
import com.fzm.common.utils.StpAdminUtil;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.vo.NftListVo;
import com.fzm.common.model.ResponseModel;
......
package com.fzm.admin.controller;
import cn.dev33.satoken.annotation.SaCheckLogin;
import com.fzm.admin.auth.StpAdminUtil;
import com.fzm.common.utils.StpAdminUtil;
import com.fzm.common.entity.vo.UserListVo;
import com.fzm.common.entity.vo.UserStatisticVo;
import com.fzm.common.model.ResponseModel;
import com.fzm.common.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
......
......@@ -4,10 +4,12 @@ import cn.dev33.satoken.exception.*;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpStatus;
import com.fzm.common.constant.TokenConstant;
import com.fzm.common.enums.ResultCode;
import com.fzm.common.exception.GlobalException;
import com.fzm.common.model.ResponseModel;
import com.fzm.common.utils.JwtUtil;
import com.fzm.common.utils.StpAdminUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.validation.ObjectError;
......@@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
......@@ -32,6 +35,9 @@ public class GlobalExceptionHandler {
@Resource
private HttpServletResponse response;
@Resource
private HttpServletRequest request;
@ExceptionHandler(value = GlobalException.class)
public ResponseModel<String> handlerGlobalException(GlobalException globalException) {
log.error(globalException.getMessage(), globalException);
......@@ -53,12 +59,18 @@ public class GlobalExceptionHandler {
if (exception instanceof NotLoginException) {
if (exception.getMessage().contains("token已被顶下线")) {
// 获取已过期的token
String expireToken = StpUtil.getTokenValue();
String expireToken = request.getHeader(TokenConstant.TOKEN_HEADER);
String appId = JwtUtil.getAppIdFromToken(expireToken);
// 从已过期的token中获取用户id
Integer userId = JwtUtil.getUserIdFromToken(expireToken);
// 获取最新的token
String tokenValue = StpUtil.getTokenValueByLoginId(userId);
String tokenValue;
if (TokenConstant.TOKEN_APP_ID_PORTAL.equals(appId)) {
tokenValue = StpUtil.getTokenValueByLoginId(userId);
} else {
tokenValue = StpAdminUtil.getTokenValueByLoginId(userId);
}
Date createTime = JwtUtil.getCreateTimeFromToken(tokenValue);
// 获取最新的token
String format = DateUtil.format(createTime, "yyyy-MM-dd HH:mm:ss");
return ResponseModel.fail(ResultCode.UNAUTHORIZED,
String.format("您的账号于 %s 登录另外一台设备,如非您本人所为,请立即修改密码", format));
......
package com.fzm.admin.auth;
package com.fzm.common.utils;
import cn.dev33.satoken.fun.SaFunction;
import cn.dev33.satoken.session.SaSession;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment