예제 #1
1
파일: UserDao.java 프로젝트: dsonti/deal70
  @Override
  public long update() throws DataModelException, TMException, SQLException {
    UserData user = (UserData) datamodel;

    ResultSet rst = null;
    try {
      String sql = UPDATE_USER;
      Collection<SQLValue> bindVars = new ArrayList<SQLValue>();

      bindVars.add(SQLValue.String(user.getUserName()));
      bindVars.add(SQLValue.String(user.getFirstName()));
      bindVars.add(SQLValue.String(user.getMiddleName()));
      bindVars.add(SQLValue.String(user.getLastName()));
      bindVars.add(SQLValue.String(user.getMailId()));
      bindVars.add(SQLValue.String(user.getPassword()));
      bindVars.add(SQLValue.Blob((Blob) user.getImage()));
      bindVars.add(SQLValue.String(user.getDob()));
      bindVars.add(SQLValue.Long(user.getSex()));
      bindVars.add(SQLValue.Long(user.getAddressId()));
      bindVars.add(SQLValue.String(user.getMaritalStatus()));
      bindVars.add(SQLValue.String(user.getNationality()));
      bindVars.add(SQLValue.Boolean(user.isActive()));
      bindVars.add(SQLValue.String(user.getActivationKey()));
      bindVars.add(SQLValue.Long(user.getId()));

      logger.debug("QUERY - Loading Address :" + sql);
      return executeUpdate(sql, bindVars);
    } catch (SQLException sql) {
      logger.error("SQL-Exception", sql);
      throw new TMException("SQL-Exception", sql.getLocalizedMessage());
    } finally {
      close(null, rst);
    }
  }
예제 #2
0
파일: UserDao.java 프로젝트: dsonti/deal70
  @Override
  public int delete() throws DataModelException, TMException, SQLException {
    UserData user = (UserData) datamodel;

    ResultSet rst = null;
    try {
      String sql = DELETE_USER;
      Collection<SQLValue> bindVars = new ArrayList<SQLValue>();
      if (user.getId() > 0) {
        sql += AND + "`ID` = ? ";
        bindVars.add(SQLValue.Long(user.getId()));
      }
      if (user.getUserName() != null) {
        sql += AND + "`USER_NAME` = ? ";
        bindVars.add(SQLValue.String(user.getUserName()));
      }
      logger.debug("QUERY - Loading Address :" + sql);
      return executeUpdate(sql, bindVars);
    } catch (SQLException sql) {
      logger.error("SQL-Exception", sql);
      throw new TMException("SQL-Exception", sql.getLocalizedMessage());
    } finally {
      close(null, rst);
    }
  }
예제 #3
0
  public static void setLoginAttributes(
      HttpSession session, HttpServletRequest request, UserData user, String uuid, String loginType)
      throws Exception {

    String userName = user.getUserName();
    session.setAttribute("userName", userName);
    session.setAttribute("user", user);
    session.setAttribute("uuid", uuid);
    session.setAttribute(ClientConstants.LoginType, loginType);
    // session.setAttribute("password", password);

    log.info("User " + userName + " logged in from " + Utilities.getRemoteHostName(request));
    System.setProperty("adminDefaultLoginName", userName);
  }
예제 #4
0
파일: UserDao.java 프로젝트: dsonti/deal70
  @Override
  public long create() throws DataModelException, TMException, SQLException {
    UserData user = (UserData) datamodel;
    if (user == null) throw new TMException("INVALID_VO", "provided User instance is null");

    if (isEmptyOrNull(user.getUserName()))
      throw new TMException("INVALID_KEY", "required key not found");

    if (read() != null) throw new SQLException("USER_EXISTS", "User Name already in use");

    try {
      String sql = CREATE_USER;
      Collection<SQLValue> bindVars = new ArrayList<SQLValue>();

      bindVars.add(SQLValue.String(user.getUserName()));
      bindVars.add(SQLValue.String(user.getFirstName()));
      bindVars.add(SQLValue.String(user.getMiddleName()));
      bindVars.add(SQLValue.String(user.getLastName()));
      bindVars.add(SQLValue.String(user.getMailId()));
      bindVars.add(SQLValue.String(user.getPassword()));
      bindVars.add(SQLValue.Blob((Blob) user.getImage()));
      bindVars.add(SQLValue.String(user.getDob()));
      bindVars.add(SQLValue.Long(user.getSex()));
      bindVars.add(SQLValue.Long(user.getAddressId()));
      bindVars.add(SQLValue.String(user.getMaritalStatus()));
      bindVars.add(SQLValue.String(user.getNationality()));
      bindVars.add(SQLValue.Boolean(user.isActive()));
      bindVars.add(SQLValue.String(user.getActivationKey()));

      logger.debug("QUERY - Loading Address :" + sql);
      return executeUpdate(sql, bindVars);
    } catch (SQLException sql) {
      logger.error("SQL-Exception", sql);
      throw new TMException("SQL-Exception", sql.getLocalizedMessage());
    }
  }
예제 #5
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;
  }
예제 #6
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;
  }