|
@@ -1,8 +1,10 @@
|
|
package com.huimv.manager.interceptor;
|
|
package com.huimv.manager.interceptor;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.huimv.manager.enums.AdminTypeEnum;
|
|
import com.huimv.manager.enums.AdminTypeEnum;
|
|
import com.huimv.manager.modular.entity.MobileUser;
|
|
import com.huimv.manager.modular.entity.MobileUser;
|
|
import com.huimv.manager.modular.service.MobileUserService;
|
|
import com.huimv.manager.modular.service.MobileUserService;
|
|
|
|
+import com.huimv.manager.result.R;
|
|
import com.huimv.manager.util.JwtUtils;
|
|
import com.huimv.manager.util.JwtUtils;
|
|
import io.jsonwebtoken.Claims;
|
|
import io.jsonwebtoken.Claims;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -34,41 +36,49 @@ public class JWTInterceptor implements HandlerInterceptor {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ response.setContentType("application/json;charset=utf-8");
|
|
// 获取token
|
|
// 获取token
|
|
String token = request.getHeader("token");
|
|
String token = request.getHeader("token");
|
|
if (StringUtils.isEmpty(token)) {
|
|
if (StringUtils.isEmpty(token)) {
|
|
- response.sendError(419,"无token,请先登录!");
|
|
|
|
|
|
+
|
|
|
|
+ response.getWriter().write(JSONObject.toJSONString(R.error(419,"无token,请先登录!")));
|
|
|
|
+// response.sendError(419,"无token,请先登录!");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
Claims claims = JwtUtils.getClaims(token);
|
|
Claims claims = JwtUtils.getClaims(token);
|
|
Integer id = claims.get("id", Integer.class);
|
|
Integer id = claims.get("id", Integer.class);
|
|
if (mobileUserService == null) {
|
|
if (mobileUserService == null) {
|
|
- response.sendError(500,"服务器发送错误!");
|
|
|
|
|
|
+
|
|
|
|
+ response.getWriter().write(JSONObject.toJSONString(R.error(500,"服务器发送错误!")));
|
|
|
|
+// response.sendError(500,"服务器发送错误!");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
MobileUser mobileUser = mobileUserService.findById(id);
|
|
MobileUser mobileUser = mobileUserService.findById(id);
|
|
if (mobileUser == null) {
|
|
if (mobileUser == null) {
|
|
- response.sendError(401,"用户不存在,请先注册!");
|
|
|
|
|
|
+ response.getWriter().write(JSONObject.toJSONString(R.error(401,"用户不存在,请先注册!")));
|
|
|
|
+// response.sendError(401,"用户不存在,请先注册!");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
if (!mobileUser.getGrantClass().equals(AdminTypeEnum.ADMIN.getCode())) {
|
|
if (!mobileUser.getGrantClass().equals(AdminTypeEnum.ADMIN.getCode())) {
|
|
- response.sendError(401,"你不是管理员,不能进行该操作!");
|
|
|
|
|
|
+ response.getWriter().write(JSONObject.toJSONString(R.error(401,"你不是管理员,不能进行该操作!")));
|
|
|
|
+// response.sendError(401,"你不是管理员,不能进行该操作!");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
int result = JwtUtils.verifyToken(claims);
|
|
int result = JwtUtils.verifyToken(claims);
|
|
if (result >= 1) {
|
|
if (result >= 1) {
|
|
- response.sendError(419,"token已失效,请重新登录!");
|
|
|
|
|
|
+ response.getWriter().write(JSONObject.toJSONString(R.error(419,"token已失效,请重新登录!")));
|
|
|
|
+// response.sendError(419,"token已失效,请重新登录!");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- if (result == -1) {
|
|
|
|
- String jwtToken = JwtUtils.getJwtToken(id);
|
|
|
|
- request.setAttribute("token",jwtToken);
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
|
|
+// if (result == -1) {
|
|
|
|
+// String jwtToken = JwtUtils.getJwtToken(id);
|
|
|
|
+//// response.getWriter().write(JSONObject.toJSONString(R.ok("token需要刷新").put("code",30000).put("token",jwtToken)));
|
|
|
|
+// return true;
|
|
|
|
+// }
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|