|
@@ -1,11 +1,15 @@
|
|
|
package com.ruoyi.app.interceptor;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.ruoyi.app.annotation.PassToken;
|
|
|
import com.ruoyi.app.base.AppLoginUser;
|
|
|
import com.ruoyi.app.base.AppTokenService;
|
|
|
import com.ruoyi.app.domain.TbAppUser;
|
|
|
import com.ruoyi.app.domain.vo.AppMemberVo;
|
|
|
import com.ruoyi.app.service.ITbAppUserService;
|
|
|
+import com.ruoyi.common.constant.HttpStatus;
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.utils.ServletUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.method.HandlerMethod;
|
|
|
import org.springframework.web.servlet.HandlerInterceptor;
|
|
@@ -43,16 +47,22 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
|
|
|
}
|
|
|
// 执行认证
|
|
|
if (token == null) {
|
|
|
- throw new RuntimeException("无token,请重新登录");
|
|
|
+ //throw new RuntimeException("无token,请重新登录");
|
|
|
+ ServletUtils.renderString(httpServletResponse, JSON.toJSONString(AjaxResult.error(HttpStatus.UNAUTHORIZED, "无token,请重新登录")));
|
|
|
+ return false;
|
|
|
}
|
|
|
// 获取 token 中的 loginUser
|
|
|
AppLoginUser loginUser = appTokenService.getLoginUser(token);
|
|
|
if (loginUser == null) {
|
|
|
- throw new RuntimeException("用户不存在,请重新登录");
|
|
|
+ // throw new RuntimeException("用户不存在,请重新登录");
|
|
|
+ ServletUtils.renderString(httpServletResponse, JSON.toJSONString(AjaxResult.error(HttpStatus.UNAUTHORIZED, "用户不存在,请重新登录")));
|
|
|
+ return false;
|
|
|
}
|
|
|
AppMemberVo user = loginUser.getUser();
|
|
|
if (user == null) {
|
|
|
- throw new RuntimeException("用户不存在,请重新登录");
|
|
|
+ ServletUtils.renderString(httpServletResponse, JSON.toJSONString(AjaxResult.error(HttpStatus.UNAUTHORIZED, "用户不存在,请重新登录")));
|
|
|
+ return false;
|
|
|
+ //throw new RuntimeException("用户不存在,请重新登录");
|
|
|
}
|
|
|
// 验证 token
|
|
|
appTokenService.verifyToken(loginUser);
|