Commit c6481e69 authored by ma's avatar ma

修改token错误提示信息

parent 39998aee
...@@ -4,6 +4,7 @@ import io.swagger.annotations.Api; ...@@ -4,6 +4,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.consts.ResultCode;
import iot.sixiang.license.entity.User; import iot.sixiang.license.entity.User;
import iot.sixiang.license.jwt.JwtUtil; import iot.sixiang.license.jwt.JwtUtil;
import iot.sixiang.license.jwt.LoginUser; import iot.sixiang.license.jwt.LoginUser;
...@@ -24,6 +25,8 @@ import org.springframework.web.bind.annotation.*; ...@@ -24,6 +25,8 @@ import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -136,9 +139,9 @@ public class LoginController { ...@@ -136,9 +139,9 @@ public class LoginController {
@RequestMapping(value = "fail", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "fail", method = {RequestMethod.GET, RequestMethod.POST})
@ApiIgnore @ApiIgnore
public BaseResult fail() { public BaseResult fail(ServletRequest servletRequest) {
String msg = servletRequest.getAttribute("msg").toString();
return BaseResult.unauthorized(); return BaseResult.failed().setCodeValue(ResultCode.UNAUTHORIZED.getCode()).setMsgValue(msg);
} }
@ApiOperation(value = "发送验证码", notes = "发送验证码到邮箱") @ApiOperation(value = "发送验证码", notes = "发送验证码到邮箱")
......
...@@ -62,23 +62,28 @@ public class JwtFilter implements Filter { ...@@ -62,23 +62,28 @@ public class JwtFilter implements Filter {
} }
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
request.setAttribute("msg", "认证信息不能为空"); request.setAttribute("msg", "token不能为空");
request.getRequestDispatcher("/iot_license/fail").forward(request, response); request.getRequestDispatcher("/iot_license/fail").forward(request, response);
} else { } else {
DecodedJWT jwt = JwtUtil.verifyToken(token); DecodedJWT jwt = JwtUtil.verifyToken(token);
if (jwt == null) { if (jwt == null) {
request.setAttribute("msg", "认证信息非法"); request.setAttribute("msg", "非法token");
request.getRequestDispatcher("/iot_license/fail").forward(request, response); request.getRequestDispatcher("/iot_license/fail").forward(request, response);
} else { } else {
Map<String, Claim> userData = jwt.getClaims(); Map<String, Claim> userData = jwt.getClaims();
if (userData == null) { if (userData == null) {
request.setAttribute("msg", "认证信息非法"); request.setAttribute("msg", "非法token");
request.getRequestDispatcher("/iot_license/fail").forward(request, response); request.getRequestDispatcher("/iot_license/fail").forward(request, response);
return; return;
} }
String userId = userData.get("userId").asString(); String userId = userData.get("userId").asString();
String userName = userData.get("userName").asString(); String userName = userData.get("userName").asString();
String password = ""; String password = "";
if (!token.equals(UserUtils.getToken(userId))) {
request.setAttribute("msg", "账户已在别处登录,请重新登录");
request.getRequestDispatcher("/iot_license/fail").forward(request, response);
return;
}
LoginUser loginUser = new LoginUser(userId, userName, password); LoginUser loginUser = new LoginUser(userId, userName, password);
Date curDate = new Date(); Date curDate = new Date();
Date tokenExp = UserUtils.getTokenExp(userId); Date tokenExp = UserUtils.getTokenExp(userId);
...@@ -89,7 +94,7 @@ public class JwtFilter implements Filter { ...@@ -89,7 +94,7 @@ public class JwtFilter implements Filter {
} else { } else {
UserUtils.removeToken(userId); UserUtils.removeToken(userId);
UserUtils.removeTokenExp(userId); UserUtils.removeTokenExp(userId);
request.setAttribute("msg", "token已失效"); request.setAttribute("msg", "token已过期");
request.getRequestDispatcher("/iot_license/fail").forward(request, response); request.getRequestDispatcher("/iot_license/fail").forward(request, response);
} }
} }
......
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