Esempio n. 1
1
  @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);
    }
  }
Esempio n. 2
0
  @Override
  public DataModel read() throws DataModelException, TMException, SQLException {
    UserData user = (UserData) datamodel;

    ResultSet rst = null;
    try {
      String sql = READ_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()));
      }
      if (user.getPassword() != null) {
        sql += AND + "`PASSWORD` = ? ";
        bindVars.add(SQLValue.String(user.getPassword()));
      }
      logger.debug("QUERY - Loading Address :" + sql);
      rst = executeQuery(sql, bindVars);

      return loadUserVO(user, rst);
    } catch (SQLException sql) {
      logger.error("SQL-Exception", sql);
      throw new TMException("SQL-Exception", sql.getLocalizedMessage());
    } finally {
      close(null, rst);
    }
  }
Esempio n. 3
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;
  }