コード例 #1
0
ファイル: Users.java プロジェクト: mastermind1981/Oobbit
  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.");
  }
コード例 #2
0
ファイル: Users.java プロジェクト: mastermind1981/Oobbit
  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();
  }