Exemplo n.º 1
0
  public User get(int id) throws SQLException, NothingWasFoundException {
    PreparedStatement statement =
        getConnection()
            .prepareStatement(
                "SELECT user_id, username, email, access_level, create_time FROM oobbit.users WHERE id = ?;");
    statement.setInt(1, id);

    ResultSet query = statement.executeQuery();

    if (query.next()) {
      User user = new User();
      user.parse(query);
      return user;
    }

    throw new NothingWasFoundException("No user found with that id.");
  }
Exemplo n.º 2
0
  public User attemptLogin(String email, String password)
      throws SQLException, FailedLoginException {
    PreparedStatement statement =
        getConnection()
            .prepareStatement("SELECT * FROM `users` WHERE `email` = ? AND `password` = ?;");
    statement.setString(1, email);
    statement.setString(2, hash(password));

    ResultSet query = statement.executeQuery();

    if (query.next()) {
      User user = new User();
      user.parse(query);
      return user;
    }

    throw new FailedLoginException();
  }