Пример #1
0
 @RequestMapping(value = "/enterThirdParty", method = RequestMethod.GET)
 public String thirdPartyEnter(
     @RequestParam(value = "acc") String acc,
     Model model,
     HttpSession session,
     HttpServletRequest request,
     HttpServletResponse response) {
   logger.info("#### enter 3pp usr ####");
   User user;
   user = service.findUserBy3pp("sina", acc);
   if (user != null) {
     if (user.getEmail() != null && !user.getEmail().trim().equals("")) {
       login(user, session, response);
       return "redirect:/";
     } else {
       model.addAttribute("thirdParty", "sina");
       model.addAttribute("thirdPartyName", acc);
       return "home";
     }
   } else {
     user = new User();
     user.setThirdParty("sina");
     user.setThirdPartyName(acc);
     user = service.createUser(user);
     model.addAttribute("thirdParty", "sina");
     model.addAttribute("thirdPartyName", acc);
     return "home";
   }
 }
Пример #2
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:/";
      }
    }
  }
Пример #3
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();
  }
  @RequestMapping(value = "/mail/{randomUrl}/{idString}", method = RequestMethod.GET)
  public String commonRegister(
      @PathVariable String randomUrl,
      @PathVariable String idString,
      HttpSession session,
      HttpServletResponse response) {
    logger.info("#### into ConfirmUserRegisterController ####");
    Integer id = Integer.parseInt(idString);
    User result = userService.findOne(id.longValue());
    boolean userConfirmed = (result != null) && randomUrl.equals(result.getRandomUrl());
    if (userConfirmed) {

      logger.info("#### into result not null #### " + result.getName());
      result.setRandomUrl("pass");
      result.setRegister_date(new Date());
      userService.updateUser(result);

      UserInfo userInfo = new UserInfo(result);

      session.setAttribute(GlobalDefs.SESSION_USER_INFO, userInfo);
      logger.info("Confirm user email successful.");
      String email = userInfo.getEmail();
      String encodedEmail =
          new String(Base64.encode(email.getBytes()), Charset.forName("US-ASCII"));
      Cookie cookie = new Cookie(GlobalDefs.COOKIE_IDENTITY, encodedEmail);
      cookie.setPath("/");
      response.addCookie(cookie);

      String type = result.getRole();
      if (type != null && type.equals("enterprise")) {
        return "redirect:/enterprise/dispatcher";
      } else if (type != null && type.equals("user")) {
        return "redirect:/user/dispatcher";
      } else {
        return "redirect:/teacher/dispatcher";
      }
    } else {
      logger.info("#### user confirm failed ####");
      return "home";
    }
  }