public String userLoginPost(
HttpServletRequest request,
@ModelAttribute("userInfoAttribute") UserInfo userInfo,
@RequestParam(value = "rememberme", required = false) Boolean rememberme,
HttpServletResponse response, ModelMap model) throws Exception {
model.addAttribute("userInfoAttribute", new UserInfo());
if (StringUtils.isEmpty(userInfo.getLoginName())
|| StringUtils.isEmpty(userInfo.getPasswd())) {// 如果用户名密码是空.
model.addAttribute("errorMsg",
"\u8bf7\u8f93\u5165\u7528\u6237\u540d\u5bc6\u7801.");
return "/admin/userInfo/userInfoLogin";
}
UserInfo userInfoTemp = userInfoService.getUserInfoByLogin(
userInfo.getLoginName(), userInfo.getPasswd());
System.out.println(rememberme);
if (userInfoTemp == null) {
model.addAttribute("errorMsg",
"\u7528\u6237\u540d\u5bc6\u7801\u9519\u8bef.");
return "/admin/userInfo/userInfoLogin";
} else {
if (rememberme != null && rememberme.booleanValue()) {
// 如果够选记住我.就设置cookie.
String remembermeKey = userInfoService
.updateUserInfoRememberMe(userInfoTemp.getId());
Cookie cookie = new Cookie("rememberme", remembermeKey);
cookie.setMaxAge(60 * 60 * 24 * 30);
response.addCookie(cookie);
cookie = new Cookie("loginName", userInfoTemp.getLoginName());
cookie.setMaxAge(60 * 60 * 24 * 30);
response.addCookie(cookie);
}
request.getSession()
.setAttribute(GlobalConf.USER_SESSION, userInfo);