@RequestParam("password") String password, @RequestParam("authCode") String authCode,
@RequestParam(value = "remember", required = false) boolean remember,
HttpServletRequest request,
HttpServletResponse response) {
ModelAndView view = new ModelAndView();
User user = userService.userValidation(userName, password);
if (user == null) {//用户不存在
view.setViewName(KeyConstant.ERROR_PAGE);
} else {
JCMSProperties propertiy = JCMSProperties.getInstance();
HttpSession session = request.getSession();
if (authCode.equals(session.getAttribute(KeyConstant.SESSION_KEY_AUTH_CODE))) {
if (BooleanUtils.isTrue(remember)) {//保存记住用户名的cookie
Cookie cookie = new Cookie(KeyConstant.COOKIE_KEY_USERNAME, userName);
cookie.setMaxAge(3600 * 24 * 7);
cookie.setPath(propertiy.getHost());
response.addCookie(cookie);
}
session.removeAttribute(KeyConstant.SESSION_KEY_AUTH_CODE);
session.setAttribute(KeyConstant.SESSION_KEY_USER, user);
view.setViewName("redirect:/admin/common/index.do");
logger.info("user:" + user.getUserName() + " 登录");
} else {//验证码错误
errorMav.setErrorInfo("验证码错误");
logger.warn("user:" + user.getUserName() + "验证码错误");
return errorMav;
}
}
return view;
}