Package model

Class User

java.lang.Object
model.User

public class User extends Object
Singleton class for the User Contains methods for retrieving and setting user data, as well as personal scoreboards of the user.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Account
    jpa entity for the account
    private final IAccountDAO
    DAO class for database connection
    private Scoreboard
    Personal scores for easy difficulty
    private Scoreboard
    Personal scores for hard difficulty
    private static User
    Singleton instance of the User class
    private Scoreboard
    Personal scores for medium difficulty
    private Long
    Id of the player, retrieved from the database.
    private String
    Username of the player
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor for the User class Initializes the username, id and personal scores Also initializes AccountDAO for database connection
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addScore(Double time, int points, ModeType difficulty)
    Adds a score to the personal scores
    boolean
    Deletes the account from the database
    void
    fetchScores(ModeType difficulty)
    fetcher for the personal scores from server.
    Getter for the account
    static User
    getInstance method for the User class.
    getScores(ModeType difficulty)
    Getter for the personal scores.
    Getter for the userId
    Getter for the username
    boolean
    Checks if the user is logged in
    boolean
    login(String username, String password)
    Searches username from database and updates the instance variables password is hashed and the hash is compared to the one in the database
    void
    Logs out the user and resets the instance variables
    boolean
    signup(String username, String password)
    Searches username from db, creates it if it does not exist and updates the instance variables also hashes the password before saving it no salt since that's unhealthy
    To string method for the User class

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • instance

      private static User instance
      Singleton instance of the User class
    • username

      private String username
      Username of the player
    • userId

      private Long userId
      Id of the player, retrieved from the database.
    • easyScores

      private Scoreboard easyScores
      Personal scores for easy difficulty
    • mediumScores

      private Scoreboard mediumScores
      Personal scores for medium difficulty
    • hardScores

      private Scoreboard hardScores
      Personal scores for hard difficulty
    • accountdao

      private final IAccountDAO accountdao
      DAO class for database connection
    • account

      private Account account
      jpa entity for the account
  • Constructor Details

    • User

      private User()
      Private constructor for the User class Initializes the username, id and personal scores Also initializes AccountDAO for database connection
  • Method Details

    • getInstance

      public static User getInstance()
      getInstance method for the User class. Returns the singleton instance of the User class. If this does not exist creates it.
      Returns:
      - see instance
    • login

      public boolean login(String username, String password)
      Searches username from database and updates the instance variables password is hashed and the hash is compared to the one in the database
      Parameters:
      username - - see username
      password - user password
      Returns:
      true or false depending on success of the login
    • signup

      public boolean signup(String username, String password)
      Searches username from db, creates it if it does not exist and updates the instance variables also hashes the password before saving it no salt since that's unhealthy
      Parameters:
      username - see username
      password - user password
      Returns:
      true or false depending on success of the signup
    • getUsername

      public String getUsername()
      Getter for the username
      Returns:
      - see username
    • logout

      public void logout()
      Logs out the user and resets the instance variables
    • isLoggedIn

      public boolean isLoggedIn()
      Checks if the user is logged in
      Returns:
      true if logged in, false if not
    • getScores

      public Scoreboard getScores(ModeType difficulty)
      Getter for the personal scores.
      Returns:
      - see easyScores
    • fetchScores

      public void fetchScores(ModeType difficulty)
      fetcher for the personal scores from server. see Scoreboard#fetchUserScores(Long, ModeType)
    • addScore

      public void addScore(Double time, int points, ModeType difficulty)
      Adds a score to the personal scores
      Parameters:
      time - - see Scoreboard.addScore(Double, int, ModeType, boolean)
      difficulty - - see Scoreboard.addScore(Double, int, ModeType, boolean)
    • deleteAccount

      public boolean deleteAccount()
      Deletes the account from the database
      Returns:
      true or false depending success of the deletion
    • getUserId

      public Long getUserId()
      Getter for the userId
      Returns:
      - see userId
    • getAccount

      public Account getAccount()
      Getter for the account
      Returns:
      - see account
    • toString

      public String toString()
      To string method for the User class
      Overrides:
      toString in class Object
      Returns:
      String represenation of the class