@RequestMapping("login.action")
public void doLogin(HttpSession httpSession, HttpServletRequest request, String userName, String remFlag, String passWord, Map<String, Object> model) {
String md5password = "";
if ((userName != null) && (passWord != null)) {
md5password = MD5.str2md5(passWord);
}
try {
if (md5password != null && "" != md5password) {
Map<String, Object> fabaoUserMap = this.faBaoService.getFabaoUser(userName, md5password);
if (fabaoUserMap != null) {
httpSession.setAttribute("username", userName);
httpSession.setAttribute("userid", fabaoUserMap.get("User_ID"));
model.put("code", "SUCCESS");
model.put("msg", "SUCCESS");
String loginInfo = userName + "," + passWord;
Cookie userCookie = new Cookie("loginInfo", loginInfo);
} else {
model.put("code", "FAILURE");
Boolean isExist = this.faBaoService.UserIsExist(userName.trim());
if (userName.trim()==null || passWord.trim()==null ||userName.trim()=="" || passWord.trim()=="" ) {
model.put("msg", "用户名或密码不能为空!");
}else if (isExist) {
model.put("msg", "密码不正确!");
}else if(!isExist){
model.put("msg", "用户名不正确!");
}
}
}else {
model.put("msg", "密码不为空!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 取登录用户
* @param userName
* @param md5password
* @return
*/
public Map<String, Object> getFabaoUser(String userName, String md5password) {
Map<String, Object> fabaoUser=null;
try {
fabaoUser = fabaoDAO.getFabaoUser(userName,md5password);
} catch (SQLException e) {
e.printStackTrace();
}
return fabaoUser;
}
@SuppressWarnings("unchecked")
public Map<String, Object> getFabaoUser(String userName, String md5password) throws SQLException {
Connection conn = ConnectionUtil.getConnection();
String loginSQL="select User_ID from CM_CONF_User where Login_Name= ? and Password=? ";
PreparedStatement preState = conn.prepareStatement(loginSQL);
preState.setString(1, userName);
preState.setString(2, md5password);
ResultSet rs = preState.executeQuery();
if (rs.next()) {
String userId = rs.getObject("User_ID").toString();
Map<String, Object> u=new HashMap<String, Object>();
u.put("User_ID", userId);
return u;
}
return null;
}