This commit is contained in:
xiangwbs
2018-04-16 21:16:24 +08:00
parent 9806101ee2
commit 597d5da36a
6 changed files with 52 additions and 46 deletions
@@ -2,7 +2,6 @@ package com.xwbing.controller.sys;
import com.alibaba.fastjson.JSONObject;
import com.xwbing.annotation.LogInfo;
import com.xwbing.constant.CommonConstant;
import com.xwbing.constant.CommonEnum;
import com.xwbing.domain.entity.sys.SysAuthority;
import com.xwbing.domain.entity.sys.SysRole;
@@ -16,6 +15,7 @@ import com.xwbing.service.sys.SysUserService;
import com.xwbing.util.CommonDataUtil;
import com.xwbing.util.JsonResult;
import com.xwbing.util.RestMessage;
import com.xwbing.util.ThreadLocalUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
@@ -152,7 +152,9 @@ public class SysUserControl {
@ApiOperation(value = "获取当前登录用户信息")
@GetMapping("getLoginUserInfo")
public JSONObject getLoginUserInfo() {
SysUser sysUser = sysUserService.getById((String) CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID));
String token = ThreadLocalUtil.getToken();
String userName = (String) CommonDataUtil.getToken(token);
SysUser sysUser = sysUserService.getByUserName(userName);
if (sysUser == null) {
return JsonResult.toJSONObj("未获取到当前登录用户信息");
}
@@ -2,9 +2,9 @@ package com.xwbing.handler;
import com.alibaba.fastjson.JSON;
import com.xwbing.configuration.DispatcherServletConfig;
import com.xwbing.constant.CommonConstant;
import com.xwbing.util.CommonDataUtil;
import com.xwbing.util.RestMessage;
import com.xwbing.util.ThreadLocalUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@@ -45,13 +45,9 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String servletPath = request.getServletPath();
if (!set.contains(servletPath) && !servletPath.contains("login") && !servletPath.contains("test")) {
// HttpSession session = request.getSession();
// if (session.getAttribute(CommonConstant.CURRENT_USER)!=null) {
// return true;
// }else {
// return false;
// }
if (CommonDataUtil.getToken(CommonConstant.CURRENT_USER) != null) {
String token = request.getParameter("token");
if (token != null && CommonDataUtil.getToken(token)!=null) {
ThreadLocalUtil.setToken(token);
return true;
} else {
logger.error("用户未登录");