Commit 9e266d40 authored by Quxl's avatar Quxl

优化代码结构

parent 0d1226fc
package com.egolm.film.login.service;
import javax.servlet.http.HttpSession;
import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.model.LoginToken;
public abstract class AbstractTokenService implements UserTokenService {
@Override
public LoginToken getToken() {
HttpSession session = WebMvcConfig.getSession();
LoginToken token = (LoginToken)session.getAttribute(TOKEN_NAME);
return token;
}
@Override
abstract public LoginToken doLogin(String username, String password);
@Override
public void doLogout() {
HttpSession session = WebMvcConfig.getSession();
session.removeAttribute(TOKEN_NAME);
session.invalidate();
}
@Override
public boolean isLogin() {
return this.getToken() != null;
}
}
...@@ -12,11 +12,11 @@ import com.egolm.common.StringUtil; ...@@ -12,11 +12,11 @@ import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.config.WebMvcConfig; import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.config.XException; import com.egolm.film.config.XException;
import com.egolm.film.login.service.AbstractTokenService; import com.egolm.film.login.service.AdminTokenService;
import com.egolm.film.model.LoginToken; import com.egolm.film.model.LoginToken;
@Service @Service
public class AdminTokenServiceImpl extends AbstractTokenService { public class AdminTokenServiceImpl implements AdminTokenService {
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
...@@ -51,5 +51,22 @@ public class AdminTokenServiceImpl extends AbstractTokenService { ...@@ -51,5 +51,22 @@ public class AdminTokenServiceImpl extends AbstractTokenService {
} }
} }
@Override
public LoginToken getToken() {
HttpSession session = WebMvcConfig.getSession();
LoginToken token = (LoginToken)session.getAttribute(TOKEN_NAME);
return token;
}
@Override
public void doLogout() {
HttpSession session = WebMvcConfig.getSession();
session.removeAttribute(TOKEN_NAME);
session.invalidate();
}
@Override
public boolean isLogin() {
return this.getToken() != null;
}
} }
...@@ -12,11 +12,11 @@ import com.egolm.common.StringUtil; ...@@ -12,11 +12,11 @@ import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.config.WebMvcConfig; import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.config.XException; import com.egolm.film.config.XException;
import com.egolm.film.login.service.AbstractTokenService; import com.egolm.film.login.service.MemberTokenService;
import com.egolm.film.model.LoginToken; import com.egolm.film.model.LoginToken;
@Service @Service
public class MemberTokenServiceImpl extends AbstractTokenService { public class MemberTokenServiceImpl implements MemberTokenService {
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
...@@ -51,4 +51,22 @@ public class MemberTokenServiceImpl extends AbstractTokenService { ...@@ -51,4 +51,22 @@ public class MemberTokenServiceImpl extends AbstractTokenService {
} }
} }
@Override
public LoginToken getToken() {
HttpSession session = WebMvcConfig.getSession();
LoginToken token = (LoginToken)session.getAttribute(TOKEN_NAME);
return token;
}
@Override
public void doLogout() {
HttpSession session = WebMvcConfig.getSession();
session.removeAttribute(TOKEN_NAME);
session.invalidate();
}
@Override
public boolean isLogin() {
return this.getToken() != null;
}
} }
...@@ -12,11 +12,11 @@ import com.egolm.common.StringUtil; ...@@ -12,11 +12,11 @@ import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.config.WebMvcConfig; import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.config.XException; import com.egolm.film.config.XException;
import com.egolm.film.login.service.AbstractTokenService; import com.egolm.film.login.service.UserTokenService;
import com.egolm.film.model.LoginToken; import com.egolm.film.model.LoginToken;
@Service @Service
public class UserTokenServiceImpl extends AbstractTokenService { public class UserTokenServiceImpl implements UserTokenService {
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
...@@ -51,4 +51,22 @@ public class UserTokenServiceImpl extends AbstractTokenService { ...@@ -51,4 +51,22 @@ public class UserTokenServiceImpl extends AbstractTokenService {
} }
} }
@Override
public LoginToken getToken() {
HttpSession session = WebMvcConfig.getSession();
LoginToken token = (LoginToken)session.getAttribute(TOKEN_NAME);
return token;
}
@Override
public void doLogout() {
HttpSession session = WebMvcConfig.getSession();
session.removeAttribute(TOKEN_NAME);
session.invalidate();
}
@Override
public boolean isLogin() {
return this.getToken() != null;
}
} }
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