Commit b60b5380 by 黄森林

登录模式改为一个账号只能一个ip登录

parent 9a8ca5e2
......@@ -2,6 +2,9 @@ package com.winsun.item.modular.intercept;
import com.alibaba.fastjson.JSON;
import com.winsun.auth.core.common.model.ResponseData;
import com.winsun.auth.core.shiro.ShiroUser;
import com.winsun.item.core.shiro.ShiroKit;
import com.winsun.item.core.util.IPUtils;
import com.winsun.item.modular.system.service.IUserService;
import com.winsun.item.util.LoginUtils;
import lombok.extern.slf4j.Slf4j;
......@@ -9,6 +12,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
......@@ -33,6 +37,10 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
@Autowired
public StringRedisTemplate stringRedisTemplate;
//登录验证码标识
private static String LOGINFLAG="alreadyLoginFlag";
@Autowired
private IUserService userService;
......@@ -152,5 +160,16 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
ShiroUser shiroUser = ShiroKit.getUser();
if (shiroUser!=null) {
//该用户登录ip
String ipAddr = IPUtils.getIpAddr(request);
stringRedisTemplate.opsForValue().set(shiroUser.getAccount()+LOGINFLAG,ipAddr);
}
super.postHandle(request, response, handler, modelAndView);
}
}
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