Commit a81874b8 authored by Quxl's avatar Quxl

xx

parent 9c3e3a80
......@@ -6,7 +6,7 @@ import com.egolm.film.model.LoginToken;
public interface TokenService {
final String JSESSIONID = "JSESSIONID";
final String LOGINID_COOKIE_NAME = "token";
LoginToken getToken();
......
......@@ -43,7 +43,7 @@ public class AdminTokenServiceImpl implements AdminTokenService {
Integer adminid = admin.getAdminid();
LoginToken token = new LoginToken(adminid);
session.setAttribute(TOKEN_NAME, token);
Cookie cookie = WebMvcConfig.getCookie(JSESSIONID);
Cookie cookie = WebMvcConfig.getOrCreateUUIDCookie(LOGINID_COOKIE_NAME, "/", 60*60, true);
if(cookie != null) {
String sql = "update fc_admin set token = ? where adminid = ?";
jdbcTemplate.executeUpdate(sql, cookie.getValue(), adminid);
......
......@@ -51,7 +51,7 @@ public class MemberTokenServiceImpl implements MemberTokenService {
Integer id = member.getId();
LoginToken token = new LoginToken(id);
session.setAttribute(TOKEN_NAME, token);
Cookie cookie = WebMvcConfig.getCookie(JSESSIONID);
Cookie cookie = WebMvcConfig.getCookie(LOGINID_COOKIE_NAME);
if(cookie != null) {
memberService.updateToken(id, cookie.getValue());
}
......
......@@ -47,7 +47,7 @@ public class UserTokenServiceImpl implements UserTokenService {
Long uid = user.getUid();
LoginToken token = new LoginToken(uid);
session.setAttribute(TOKEN_NAME, token);
Cookie cookie = WebMvcConfig.getCookie(JSESSIONID);
Cookie cookie = WebMvcConfig.getCookie(LOGINID_COOKIE_NAME);
if(cookie != null) {
jdbcTemplate.executeUpdate("update fc_user set token = ? where uid = ?", cookie.getValue(), uid);
}
......
......@@ -18,6 +18,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.egolm.common.StringUtil;
import com.egolm.film.config.interceptor.AdminLoginInterceptor;
import com.egolm.film.config.interceptor.LocaleInterceptor;
import com.egolm.film.config.interceptor.MemberLoginInterceptor;
......@@ -98,6 +99,26 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
return null;
}
public static Cookie getOrCreateUUIDCookie(String name, String path, int expiry, boolean httpOnly) {
HttpServletRequest request = WebMvcConfig.getRequest();
if(request != null) {
Cookie[] cookies = request.getCookies();
if(cookies != null) {
for(Cookie cookie : cookies) {
if(cookie.getName().equals(name)) {
return cookie;
}
}
}
}
Cookie cookie = new Cookie(name, StringUtil.getUid().toLowerCase());
cookie.setPath(path);
cookie.setHttpOnly(httpOnly);
cookie.setMaxAge(expiry);
getResponse().addCookie(cookie);
return cookie;
}
public static String getRemoteIp() {
HttpServletRequest request = WebMvcConfig.getRequest();
String ip = request.getHeader("X-Real_IP");
......
......@@ -28,7 +28,7 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
Cookie[] cookies = req.getCookies();
if(cookies != null) {
for(Cookie cookie : cookies) {
if(cookie.getName().equals(TokenService.JSESSIONID)) {
if(cookie.getName().equals(TokenService.LOGINID_COOKIE_NAME)) {
sessionid = cookie.getValue();
}
}
......
......@@ -27,7 +27,7 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
String sessionid = null;
Cookie[] cookies = req.getCookies();
for(Cookie cookie : cookies) {
if(cookie.getName().equals(TokenService.JSESSIONID)) {
if(cookie.getName().equals(TokenService.LOGINID_COOKIE_NAME)) {
sessionid = cookie.getValue();
}
}
......
......@@ -27,7 +27,7 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
String sessionid = null;
Cookie[] cookies = req.getCookies();
for(Cookie cookie : cookies) {
if(cookie.getName().equals(TokenService.JSESSIONID)) {
if(cookie.getName().equals(TokenService.LOGINID_COOKIE_NAME)) {
sessionid = cookie.getValue();
}
}
......
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