Java tutorial
/* * Copyright (c) 2013 ????www.hrbesd.com. All rights reserved. * * HRBESD PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.esd.ps; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.support.RedirectAttributes; /** * * ? * * @author zhangjianzong * */ @Controller public class IndexController { private static final Logger logger = LoggerFactory.getLogger(IndexController.class); /** * ? * * @return */ @RequestMapping(value = "/quit1", method = RequestMethod.GET) public ModelAndView quitGet(HttpSession session) { session.removeAttribute(Constants.USER_ID); return new ModelAndView("login"); } /** * ? * * @return */ @RequestMapping(value = "/login1", method = RequestMethod.GET) public ModelAndView loginGet1() { return new ModelAndView("login"); } /** * ??? * * @param request * @param redirectAttributes * @param session * @return */ @SuppressWarnings("unused") @RequestMapping(value = "/login1", method = RequestMethod.POST) public ModelAndView loginPost1(HttpServletRequest request, RedirectAttributes redirectAttributes, HttpSession session) { String userName = request.getParameter("username"); String passWord = request.getParameter("password"); logger.debug("?"); // String checkCode = request.getParameter("checkCode"); // logger.debug("userName:{},passWord:{},checkCode:{}", userName, passWord, checkCode); // // CaptchaService captchaService = new CaptchaService(); // Boolean b = captchaService.checkCode(checkCode, request); // logger.debug("checkcode status:{}", b); // if (b == false) { // redirectAttributes.addFlashAttribute("username", userName); // redirectAttributes.addFlashAttribute("password", passWord); // redirectAttributes.addFlashAttribute("message", "??"); // return new ModelAndView("redirect:/login"); // } // User user = userService.getUserByUserName(userName); // if (user != null && user.getUserName().equals(userName)) { // UsernameAndPasswordMd5 md5 = new UsernameAndPasswordMd5(); // String pwd = md5.getMd5(userName, passWord); // logger.debug("pwd:", pwd); // if (pwd.equals(user.getUserPassword())) { // session.setAttribute(Constants.USER_ID, user.getId()); // session.setAttribute(Constants.USER_NAME, user.getUserName()); // session.setAttribute(Constants.USER_REAL_NAME, user.getUserRealName()); // session.setAttribute(Constants.USER_GROUP_ID, user.getUserGroup().getId()); // // ? // String year = auditParameterService.getLastestYear(); // session.setAttribute(Constants.YEAR, year); // //, ? // if(user.getUserGroup().getId().equals(5)){ // return new ModelAndView("redirect:/security/query/audit/listforcompany"); // } // return new ModelAndView("redirect:/security/index"); // } else { // redirectAttributes.addFlashAttribute("username", userName); // redirectAttributes.addFlashAttribute("password", passWord); // redirectAttributes.addFlashAttribute("message", "???"); // } // } else { // redirectAttributes.addFlashAttribute("username", userName); // redirectAttributes.addFlashAttribute("password", passWord); // redirectAttributes.addFlashAttribute("message", "???"); // return new ModelAndView("redirect:/login"); // } return new ModelAndView("redirect:/login"); } /** * * * @return */ @RequestMapping(value = "/security/index", method = RequestMethod.GET) public ModelAndView index() { return new ModelAndView("index"); } /** * ?? * * @return */ @RequestMapping(value = "/security/main", method = RequestMethod.GET) public ModelAndView main() { return new ModelAndView("main"); } }