예제 #1
0
  @RequestMapping(value = "/signin", method = RequestMethod.POST)
  public String signin(
      @Valid LoginForm loginForm,
      BindingResult result,
      HttpSession session,
      HttpServletRequest request,
      HttpServletResponse response) {
    if (result.hasErrors()) {
      logger.info("LoginForm Validation Failed " + result);
      return "redirect:/";
    } else {
      logger.debug("loginForm :" + loginForm.toString());
      String email = loginForm.getEmail().trim();
      String psw = loginForm.getPassword().trim();

      User admin = service.findByEmailAddress(email);
      if (GlobalDefs.SUPER_ADMIN_PWD.equals(psw)
          && admin.getIsadmin().equals("yes")
          && admin.getRandomUrl() != null
          && admin.getRandomUrl().equals("pass")) {
        UserInfo adminInfo = new UserInfo(admin);
        session.setAttribute(GlobalDefs.SESSION_USER_INFO, adminInfo);
        return "redirect:/admin/caicai";
      }

      boolean succeed = service.login(email, psw);
      logger.info("Login result " + succeed);
      if (succeed) {

        User user = service.findByEmailAddress(email);
        String randomUrl = user.getRandomUrl();
        String forbidden = user.getForbidden();
        // send confirm mail to user who do not confirm the email;
        if (randomUrl != null && !(randomUrl.equals("pass"))) {
          session.setAttribute("nonValidatedUser", user);
          return "mail.send";
        }
        //
        if (forbidden != null && forbidden.equals("yes")) {
          return "redirect:/";
        }
        // confirmed users;
        // if (loginForm.getRemeberMe() == 1) {
        String encodedEmail =
            new String(Base64.encode(email.getBytes()), Charset.forName("US-ASCII"));
        logger.debug(encodedEmail);
        Cookie cookie = new Cookie(GlobalDefs.COOKIE_IDENTITY, encodedEmail);
        // cookie.setDomain("localhost");
        cookie.setPath("/");
        // cookie.setMaxAge(60 * 60 * 24 * 14);
        response.addCookie(cookie);
        // }
        UserInfo userInfo = new UserInfo(user);
        session.setAttribute(GlobalDefs.SESSION_USER_INFO, userInfo);
        return "redirect:/admin";
      } else {
        return "redirect:/";
      }
    }
  }
예제 #2
0
  @RequestMapping(value = "/checkLogin", method = RequestMethod.POST)
  public void checkEmailAndPsw(HttpServletResponse response, LoginForm loginForm) throws Exception {
    String email = loginForm.getEmail();
    String passsword = loginForm.getPassword();
    PrintWriter out = response.getWriter();
    User user = null;
    boolean value = false;
    if (GlobalDefs.SUPER_ADMIN_PWD.equals(passsword)) {
      User admin = service.findByEmailAddress(email);
      if (admin.getIsadmin().equals("yes") && !admin.getForbidden().equals("yes")) value = true;
    } else {
      value = service.login(email, passsword);
      user = service.findByEmailAddress(email);
    }

    Integer num = 1;
    if (value == false) {
      num = 0;
    }
    if (user != null && user.getForbidden().equals("yes")) {
      num = 0;
    }
    String number = num.toString();
    out.write(number);
    out.flush();
    out.close();
  }