blather.controller
Class AppController

java.lang.Object
  extended by blather.controller.AppController
All Implemented Interfaces:
AppControllerInterface

public class AppController
extends java.lang.Object
implements AppControllerInterface


Field Summary
 
Fields inherited from interface blather.controller.AppControllerInterface
DEFAULT_FILENAME
 
Constructor Summary
AppController(UserDB db, SessionDB sd)
          Creates a new AppController with the given user and session databases.
 
Method Summary
 UserControllerInterface getUser(java.lang.String username, java.lang.String sessionID)
          Returns a newly-allocated UserController for the given username.
 java.lang.String[] getUserList()
          Returns a list of all valid user names in the user database.
 boolean load()
          Loads a user database from the default filename.
 boolean loadFromFile(java.lang.String filename)
          Loads a user database from the given filename.
 java.lang.String login(java.lang.String username, java.lang.String password)
          Logs the given user in to the session database
 void logout(java.lang.String session)
          Logs out the user with the given session ID.
 boolean newUser(java.lang.String username, java.lang.String password, java.lang.String email)
          Creates a new user with the specified username, password, and email address.
 boolean save()
          Saves the user database to the default filename.
 boolean saveToFile(java.lang.String filename)
          Saves the user database to the given filename.
 boolean userExists(java.lang.String username)
          Returns true if the given username is valid, false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AppController

public AppController(UserDB db,
                     SessionDB sd)
Creates a new AppController with the given user and session databases.

Parameters:
db -
sd -
Method Detail

newUser

public boolean newUser(java.lang.String username,
                       java.lang.String password,
                       java.lang.String email)
Description copied from interface: AppControllerInterface
Creates a new user with the specified username, password, and email address. The username must not already be taken in the user database, the email address must be valid (as given by EmailAddress.isValid()), and the password must be at least four characters. If these conditions are met, a new BlatherUser is created and added to the UserDB.

Specified by:
newUser in interface AppControllerInterface
Returns:
true on success, false on failure

login

public java.lang.String login(java.lang.String username,
                              java.lang.String password)
Description copied from interface: AppControllerInterface
Logs the given user in to the session database

Specified by:
login in interface AppControllerInterface
Returns:
a session ID if login was successful; null if login fails (e.g. wrong username or password).

logout

public void logout(java.lang.String session)
Description copied from interface: AppControllerInterface
Logs out the user with the given session ID.

Specified by:
logout in interface AppControllerInterface

userExists

public boolean userExists(java.lang.String username)
Description copied from interface: AppControllerInterface
Returns true if the given username is valid, false otherwise.

Specified by:
userExists in interface AppControllerInterface
Returns:

getUser

public UserControllerInterface getUser(java.lang.String username,
                                       java.lang.String sessionID)
Description copied from interface: AppControllerInterface
Returns a newly-allocated UserController for the given username. If username is not valid, throws a new BogusParameterException. If the person using the application is logged in, you must pass a valid session ID to this method.

Specified by:
getUser in interface AppControllerInterface
Returns:

getUserList

public java.lang.String[] getUserList()
Description copied from interface: AppControllerInterface
Returns a list of all valid user names in the user database.

Specified by:
getUserList in interface AppControllerInterface
Returns:

save

public boolean save()
Description copied from interface: AppControllerInterface
Saves the user database to the default filename. Returns true on success, false on failure.

Specified by:
save in interface AppControllerInterface

load

public boolean load()
Description copied from interface: AppControllerInterface
Loads a user database from the default filename. Returns true on success, false on failure.

Specified by:
load in interface AppControllerInterface

saveToFile

public boolean saveToFile(java.lang.String filename)
Description copied from interface: AppControllerInterface
Saves the user database to the given filename.

Specified by:
saveToFile in interface AppControllerInterface
Returns:
true on success, false on failure

loadFromFile

public boolean loadFromFile(java.lang.String filename)
Description copied from interface: AppControllerInterface
Loads a user database from the given filename.

Specified by:
loadFromFile in interface AppControllerInterface
Returns:
true on success, false on failure