vooga.users.user
Class UserDatabaseInterface

java.lang.Object
  extended by vooga.users.user.UserDatabaseInterface

public class UserDatabaseInterface
extends java.lang.Object

UserDatabaseInterface is effectively a Users API for interacting with the given database (e.g., Network or Local) where user information is stored. Other parts of VOOGA use this to look up user info based on their user name. For example, the Social team could verify if a given username is linked to a registered user through the following code:

 String potentialNewUsername = getUserInput();
 boolean isNewNameTaken = myUserDB.isUserInDatabase(potentialNewUsername);
 if (isNewNameTaken)
 {
     System.out.println("Error: '" + potentialNewUsername +
                        "' is taken. Please try another name.");
 }
 else
 {
     //...
 }
 

Author:
Stephanie Chang, Alex Edelsburg, Matt Prorok

Constructor Summary
UserDatabaseInterface(IVoogaGUI gui)
          Creates a new instance of UserDatabaseInterface.
 
Method Summary
 boolean addUser(java.lang.String username, java.lang.String password)
          Attempts to add a user to the database, but does nothing if the username is already in the database
 boolean addUser(java.lang.String username, java.lang.String password, java.lang.String recoveryQuestion, java.lang.String recoveryAnswer)
          Attempts to add a user to the database, but does nothing if the username is already in the database
 boolean changeAboutMeText(VoogaUser user, java.lang.String password, java.lang.String aboutMeText)
           
 boolean changePassword(VoogaUser userToChange, java.lang.String oldPassword, java.lang.String newPassword)
          Returns true if the conversion from oldPassword to newPassword is successful, false otherwise.
 boolean changeUserName(java.lang.String oldName, java.lang.String password, java.lang.String newName)
          Changes a user's username as requested if the new username does not exist and the password is correct
 VoogaUser findMatch(VoogaUser userToMatch, java.util.List<VoogaUser> matchees, java.lang.String gameName)
          Looks to match a VoogaUser with someone else of similar high score for a specified game.
 java.util.ArrayList<java.lang.String> getAllUsernames()
          Returns an ArrayList of the usernames of all the users stored in the database
 java.lang.String getRecoveryQuestion(VoogaUser user)
          Returns the security question associated with this user
 VoogaUser getUser(java.lang.String username)
          Returns the user who has the given userID
 boolean isPasswordValid(VoogaUser userToCheck, java.lang.String password)
          Returns true if password is the correct password for this user
 boolean isUserInDatabase(java.lang.String username)
          Checks if a given username is in the database
 boolean isUserInDatabase(VoogaUser user)
          Checks if a given user is in the database
 boolean isValidSecurityAnswer(VoogaUser user, java.lang.String answer, java.lang.String newPassword)
          Tries to change a user's password based on her answer to the security question.
 boolean login(java.lang.String username, java.lang.String password)
          Logs a user in if the username/password combination is correct.
 boolean logout(java.lang.String username)
          Logs a user out of the system and commits the change to the database.
 boolean logout(VoogaUser user)
          Logs a user out of the system and commits the change to the database.
 void removeUser(java.lang.String username)
          Used to delete users from the database (only used by UserTestSuite, won't be public for long!)
 void storeUser(VoogaUser user)
          Stores user in the general users database table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserDatabaseInterface

public UserDatabaseInterface(IVoogaGUI gui)
Creates a new instance of UserDatabaseInterface. By default, tries to create a connection to the network database. If unsuccessful, creates local database.

Method Detail

addUser

public boolean addUser(java.lang.String username,
                       java.lang.String password)
Attempts to add a user to the database, but does nothing if the username is already in the database

Parameters:
username - the username of the user being added
password - the password of the user being added
Returns:
true if they were successfully added, false if a user with this username is already in the table

addUser

public boolean addUser(java.lang.String username,
                       java.lang.String password,
                       java.lang.String recoveryQuestion,
                       java.lang.String recoveryAnswer)
Attempts to add a user to the database, but does nothing if the username is already in the database

Parameters:
username - the username of the user being added
password - the password of the user being added
recoveryQuestion - question to recover the password if user forgets
recoveryAnswer - answer to question to recover the password if user forgets
Returns:
true if they were successfully added, false if a user with this username is already in the table

getRecoveryQuestion

public java.lang.String getRecoveryQuestion(VoogaUser user)
Returns the security question associated with this user

Parameters:
user - the user for whom to retrieve a security question
Returns:
the security question for this user

isValidSecurityAnswer

public boolean isValidSecurityAnswer(VoogaUser user,
                                     java.lang.String answer,
                                     java.lang.String newPassword)
Tries to change a user's password based on her answer to the security question. Returns true if the change to newPassword is successful, false otherwise

Parameters:
user - the user in question
answer - the answer provided to the security question
newPassword - the new password to set for the user
Returns:
true if the conversion to newPassword as the password was successful, false otherwise

login

public boolean login(java.lang.String username,
                     java.lang.String password)
Logs a user in if the username/password combination is correct. Currently, does not require user to be logged out in order to log in, due to problems with ensuring proper setting of logged-out status in the network database when Vooga crashes. Commits the login status change to the database.

Parameters:
username - the username of the user trying to log in
password - the password of the user trying to log in
Returns:
true if login successful, false if unsuccessful

logout

public boolean logout(java.lang.String username)
Logs a user out of the system and commits the change to the database.

Parameters:
username - the username of the user trying to log in
Returns:
true if logout successful, false if user does not exist in database or is not logged in

logout

public boolean logout(VoogaUser user)
Logs a user out of the system and commits the change to the database.

Parameters:
user - the user trying to log in
Returns:
true if logout successful, false if user does not exist in database or is not logged in

isUserInDatabase

public boolean isUserInDatabase(VoogaUser user)
Checks if a given user is in the database

Parameters:
userToCheck - the user being checked
Returns:
true if the user is in the database, false otherwise

isUserInDatabase

public boolean isUserInDatabase(java.lang.String username)
Checks if a given username is in the database

Parameters:
username - the username being checked
Returns:
true if the username is in the database, false otherwise

changePassword

public boolean changePassword(VoogaUser userToChange,
                              java.lang.String oldPassword,
                              java.lang.String newPassword)
Returns true if the conversion from oldPassword to newPassword is successful, false otherwise. Commits the change to the database.

Parameters:
userToChange - the user whose password is to be changed
oldPassword - the current password for this user
newPassword - the user's new password
Returns:
true if the password change is successful, false if not

isPasswordValid

public boolean isPasswordValid(VoogaUser userToCheck,
                               java.lang.String password)
Returns true if password is the correct password for this user

Parameters:
userToCheck - the user whose password is to be checked
password - the password to verify
Returns:
true if the provided password is correct, false otherwise

getUser

public VoogaUser getUser(java.lang.String username)
Returns the user who has the given userID

Parameters:
userID - the userID of the user whose data is being requested
Returns:
the corresponding user object

storeUser

public void storeUser(VoogaUser user)
Stores user in the general users database table. Overwrites previous user info if it already exists.

Parameters:
user - the user to store in the database

removeUser

public void removeUser(java.lang.String username)
Used to delete users from the database (only used by UserTestSuite, won't be public for long!)

Parameters:
username - the username to be deleted

changeUserName

public boolean changeUserName(java.lang.String oldName,
                              java.lang.String password,
                              java.lang.String newName)
Changes a user's username as requested if the new username does not exist and the password is correct

Parameters:
oldName - the old username
password - user's password (for validation)
newName - the new username
Returns:
true if the name change is valid (& was performed), false otherwise

findMatch

public VoogaUser findMatch(VoogaUser userToMatch,
                           java.util.List<VoogaUser> matchees,
                           java.lang.String gameName)
Looks to match a VoogaUser with someone else of similar high score for a specified game. Explicitly, returns the VoogaUser "user" from matchees for which Math.abs(toMatch.getHighScore(game)-user.getHighScore(game)) is minimized. This method is also guaranteed to never return toMatch, even if toMatch is a member of matchees

Parameters:
userToMatch - the VoogaUser to match
matchees - potential matches for toMatch
gameName - the AbstractGame for which we are doing the matching
Returns:
the VoogaUser from matchees who is the best match for toMatch. null if matchees has no elements

getAllUsernames

public java.util.ArrayList<java.lang.String> getAllUsernames()
Returns an ArrayList of the usernames of all the users stored in the database

Returns:
a list of the usernames of all the users stored in the database

changeAboutMeText

public boolean changeAboutMeText(VoogaUser user,
                                 java.lang.String password,
                                 java.lang.String aboutMeText)
Parameters:
user -
password -
aboutMeText -
Returns: