Commit 83623800 authored by Quxl's avatar Quxl

后台登陆

parent 1f1e1c3d
...@@ -9,12 +9,12 @@ import javax.servlet.http.HttpSession; ...@@ -9,12 +9,12 @@ import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.api.admin.service.AdminTokenService; import com.egolm.film.api.admin.service.AdminTokenService;
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.model.LoginToken; import com.egolm.film.model.LoginToken;
import com.egolm.film.util.Common;
@Service @Service
public class AdminTokenServiceImpl implements AdminTokenService { public class AdminTokenServiceImpl implements AdminTokenService {
...@@ -25,27 +25,33 @@ public class AdminTokenServiceImpl implements AdminTokenService { ...@@ -25,27 +25,33 @@ public class AdminTokenServiceImpl implements AdminTokenService {
@Override @Override
public LoginToken doLogin(String username, String password) { public LoginToken doLogin(String username, String password) {
HttpSession session = WebMvcConfig.getSession(); HttpSession session = WebMvcConfig.getSession();
String md5String = StringUtil.toMD5HexString(password).toLowerCase(); String loginSql = "select * from fc_admin where username = ?";
String loginSql = "select * from fc_admin where username = ? and password = ?"; List<Map<String, Object>> list = this.jdbcTemplate.queryForList(loginSql, username);
List<Map<String, Object>> list = this.jdbcTemplate.queryForList(loginSql, username, md5String);
if(list != null) { if(list != null) {
if(list.size() == 1) { if(list.size() == 1) {
Map<String,Object> map = list.get(0); Map<String,Object> map = list.get(0);
Integer state = (Integer)map.get("state"); Integer state = (Integer)map.get("state");
if(state == 1) { String salt = (String)map.get("salt");
Integer adminid = (Integer)map.get("adminid"); String pwd = (String)map.get("password");
LoginToken token = new LoginToken(adminid); String encodePassword = Common.encodePassword(password, salt);
session.setAttribute(TOKEN_NAME, token); if(encodePassword.equals(pwd)) {
Cookie cookie = WebMvcConfig.getCookie(JSESSIONID); if(state == 1) {
if(cookie != null) { Integer adminid = (Integer)map.get("adminid");
String sql = "update fc_admin set token = ? where id = ?"; LoginToken token = new LoginToken(adminid);
jdbcTemplate.executeUpdate(sql, cookie.getValue(), adminid); session.setAttribute(TOKEN_NAME, token);
Cookie cookie = WebMvcConfig.getCookie(JSESSIONID);
if(cookie != null) {
String sql = "update fc_admin set token = ? where id = ?";
jdbcTemplate.executeUpdate(sql, cookie.getValue(), adminid);
}
return token;
} else if(state == 2) {
throw new XException("用户已禁用");
} else {
throw new XException("用户状态未知");
} }
return token;
} else if(state == 2) {
throw new XException("用户已禁用");
} else { } else {
throw new XException("用户状态未知"); throw new XException("用户名或密码错误");
} }
} else if(list.size() == 0) { } else if(list.size() == 0) {
throw new XException("用户名或密码错误"); throw new XException("用户名或密码错误");
......
...@@ -22,7 +22,7 @@ public class Common { ...@@ -22,7 +22,7 @@ public class Common {
} }
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(encodePassword("123456", "5e0vt0")); System.out.println(encodePassword("123456", "78hzar"));
System.out.println(getGenerateString(6)); System.out.println(getGenerateString(6));
} }
......
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