예제 #1
0
파일: UserDao.java 프로젝트: dsonti/deal70
  /**
   * @param user
   * @param rst
   * @throws SQLException
   */
  public DataModel loadUserVO(UserData user, ResultSet rst) throws TMException, SQLException {
    if (!rst.next()) {
      return null;
    }

    if (user == null) {
      user = new UserData();
    }
    try {
      user.setId(rst.getLong(ID));
    } catch (FixedValueException e) {
      // TODO Auto-generated catch block
      logger.error(e.getMessage(), e);
    }
    user.setUserName(rst.getString(USER_NAME));
    user.setPassword(rst.getString(PASSWORD));
    user.setFirstName(rst.getString(FIRST_NAME));
    user.setMiddleName(rst.getString(MIDDLE_NAME));
    user.setLastName(rst.getString(LAST_NAME));
    user.setUserName(rst.getString(EMAIL_ID));
    user.setDob(rst.getString(DOB));
    user.setSex(rst.getInt(SEX));
    user.setAddressId(rst.getLong(ADDRESS_ID));
    user.setMaritalStatus(rst.getString(MARITAL_STATUS));
    user.setNationality(rst.getString(NATIONALITY));
    user.setImage(rst.getObject(IMAGE));
    user.setActive(rst.getBoolean(IS_ACTIVE));
    user.setActivationKey(rst.getString(ACTIVATION_KEY));
    return user;
  }
예제 #2
0
  private String handleLogin() throws Exception {
    String userName = addToContext("lusername", false);
    String password = request.getParameter("password");
    String rememberUserNameString = request.getParameter("rememberUserName");
    boolean rememberUserName = rememberUserNameString != null;

    HttpSession session = request.getSession();
    int loginFailureCount = getLoginFailureCount(session);

    if (loginFailureCount > 3) {
      if (verifyReCaptcha()) {
        log.debug("Answer was entered correctly!");
      } else {
        throw new Exception("ReCaptcha answer is incorrect!");
      }
    }

    // This is to signin user after signup
    userName = (String) ((userName == null) ? request.getParameter("suserName") : userName);
    password = (String) ((password == null) ? request.getParameter("spassword") : password);

    log.debug("User " + userName + " rememberUserName " + rememberUserName);
    UserData user = new UserData();
    try {
      log.debug("logging in: handleLogin");
      // TODO: Verify User Credentials
      user.setUserName(userName);
      if (userName == null
          || userName.trim().length() == 0
          || password == null
          || password.trim().length() == 0) {
        throw new LoginException("Invalid Credentials!");
      }
      user.setPassword(AuthenticationUtils.createPassword(password));

      UserDao userDao = (UserDao) ModelFactory.getImplementation(user);
      user = (UserData) userDao.read();

      if (user == null) {
        throw new LoginException("Invalid Credentials!");
      }
      log.debug("login attributes set");
    } catch (Exception e) {
      // request.getSession().invalidate();
      System.setProperty("loginName", "");
      log.info("Login failed. Username="******"Invalid username or password");
      log.debug(e);
      throw e;
    }

    int timeOut = ClientConstants.COOKIE_AGE;
    String uuid = UUID.randomUUID().toString();
    if (rememberUserName) {
      // String encryptedUuid = Encryption.encrypt(uuid);
      Utilities.addCookie(response, ClientConstants.COOKIE_NAME, uuid, ClientConstants.COOKIE_AGE);
      // ClientConstants.sessions.put(uuid, user);
      timeOut = ClientConstants.PERSISTANCE_COOKIE_AGE;
    }
    setLoginAttributes(
        request.getSession(), request, user, uuid, LoginType.FULL_AUTHENTICATION.toString());
    SessionHelper.createUserSession(request, uuid, user.getId(), timeOut);
    log.debug("After Login UUID ::" + uuid);

    redirectToPrevUrl(ClientConstants.servletPageWithDefaultAction);
    return null;
  }