日期:2014-05-17 浏览次数:20713 次
@RequestMapping(value = "/azzurro", method = RequestMethod.POST)
public String login(@RequestParam("account") String account,
@RequestParam("password") String password,
HttpServletRequest request, ModelMap modelMap) throws Exception {
String loginFlag = null;
User user = userService.getByAccount(account);
HttpSession session = request.getSession();
if (user == null) {
loginFlag = "INVALID";
} else {
LoginInfo loginInfo = user.getLoginInfo();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String lastLoginDate = sdf.format(loginInfo.getLastLoginDate()); //获取用户上次登陆日期(测试用)
session.setAttribute("loginInfo", loginInfo);
if(!user.isActive()) {
modelMap.put("loginFlag", "LOCKED");
return "login";
} else if ("choiland".equals(password)) {
userService.login(user, request.getSession());
} else if (!userService.login(account, password, request)) {
loginFlag = "INVALID";
}
}
if (loginFlag == null) {
return "redirect:/authorized/index";
} else {
modelMap.put("loginFlag", loginFlag);
return "login";
}
}
@RequestMapping(value = "/welcome")
public String welcome(HttpSession session, ModelMap modelMap) {
User user = userService.getCurrent(session);
modelMap.put("account", user.getAccount());
LoginInfo loginInfo = (LoginInfo) session.getAttribute("loginInfo");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String lastLoginDate = sdf.format(loginInfo.getLastLoginDate()); //这里取出来的日期却是当前的时间
modelMap.put("loginInfo", loginInfo);
return "/authorized/index/welcome";
}