示例#1
0
  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    Customer customer = null;

    if (username == null || username.length() <= 0 || password == null || password.length() <= 0) {
      log.warn("Empty username and/or password used for login");
      return ViewUtil.createErrorView("error.empty.username.or.password");
    }

    // login function is handled by the appropriate access mode handler
    customer = accessModeController.login(username, password);

    if (customer == null) {
      log.warn("Invalid login attempt with username = "******" and password = "******"error.invalid.username.or.password");
    }

    UserSession userSession = new UserSession(customer);
    request.getSession().setAttribute("userSession", userSession);
    String forwardAction = request.getParameter("forwardAction");

    if (forwardAction != null) {
      log.info("Forwarding response to original request url: " + forwardAction);
      response.sendRedirect(forwardAction);
      return null;
    } else {
      response.sendRedirect("overview.htm");
      return null;
    }
  }