Package model
Class User
java.lang.Object
model.User
Singleton class for the User
Contains methods for retrieving and setting user data,
as well as personal scoreboards of the user.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Accountjpa entity for the accountprivate final IAccountDAODAO class for database connectionprivate ScoreboardPersonal scores for easy difficultyprivate ScoreboardPersonal scores for hard difficultyprivate static UserSingleton instance of the User classprivate ScoreboardPersonal scores for medium difficultyprivate LongId of the player, retrieved from the database.private StringUsername of the player -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateUser()Private constructor for the User class Initializes the username, id and personal scores Also initializes AccountDAO for database connection -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a score to the personal scoresbooleanDeletes the account from the databasevoidfetchScores(ModeType difficulty) fetcher for the personal scores from server.Getter for the accountstatic UsergetInstance method for the User class.Getter for the personal scores.Getter for the userIdGetter for the usernamebooleanChecks if the user is logged inbooleanSearches username from database and updates the instance variables password is hashed and the hash is compared to the one in the databasevoidlogout()Logs out the user and resets the instance variablesbooleanSearches 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 unhealthytoString()To string method for the User class
-
Field Details
-
instance
Singleton instance of the User class -
username
Username of the player -
userId
Id of the player, retrieved from the database. -
easyScores
Personal scores for easy difficulty -
mediumScores
Personal scores for medium difficulty -
hardScores
Personal scores for hard difficulty -
accountdao
DAO class for database connection -
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
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
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- - seeusernamepassword- user password- Returns:
- true or false depending on success of the login
-
signup
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- seeusernamepassword- user password- Returns:
- true or false depending on success of the signup
-
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
Getter for the personal scores.- Returns:
- - see
easyScores
-
fetchScores
fetcher for the personal scores from server. see Scoreboard#fetchUserScores(Long, ModeType) -
addScore
Adds a score to the personal scores- Parameters:
time- - seeScoreboard.addScore(Double, int, ModeType, boolean)difficulty- - seeScoreboard.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
Getter for the userId- Returns:
- - see
userId
-
getAccount
Getter for the account- Returns:
- - see
account
-
toString
To string method for the User class
-