userman
Class UserManager

java.lang.Object
  extended by userman.UserManager
All Implemented Interfaces:
java.io.Serializable

@Named
@SessionScoped
public class UserManager
extends java.lang.Object
implements java.io.Serializable

The UserManager bean class handles all aspects of logging in and registering. For other modules, it provides access to information about the current application user.

This class represents a session-scoped managed bean with name userManager.

This class exposes the following properties:

Property Value
user current application user as a User object
allUsers all application users as a Result object
nothingSelected true if no user management task has been selected by the admin
editSelected true if the Edit Users task has been selected by the admin
pendingSelected true if the Review Pending task has been selected by the admin
selectedUser integer ID of a user selected for editing
editedUser current user being edited as a User object
errorMessage the current error message string if any

See Also:
Serialized Form

Nested Class Summary
static class UserManager.Status
          An enumerated type for representing login and registration status.
 
Field Summary
static java.lang.String HASH_ALGORITHM
           
 
Constructor Summary
UserManager()
          The UserManager constructor creates two User objects.
 
Method Summary
 UserManager.Status attemptLogin(java.lang.String name, java.lang.String password)
          Attempts to look up a user in the database with the given login information.
 UserManager.Status attemptRegister(java.lang.String name, java.lang.String password)
          Attempts to add a new user to the database
 java.lang.String editUser(int id)
          Action method called when an administrator selects a user for editing.
 javax.servlet.jsp.jstl.sql.Result getAllUsers()
          Getter for the allUsers property.
 User getEditedUser()
          Getter for the editedUser property.
 java.lang.String getErrorMessage()
          Getter for the errorMessage property.
 int getSelectedUser()
          Getter for the selectedUser property.
 User getUser()
          Getter for the user property.
 boolean isEditSelected()
          Getter for the editSelected property.
 boolean isNothingSelected()
          Getter for the nothingSelected property.
 boolean isPendingSelected()
          Getter for the pendingSelected property.
 void logout()
          Replaces all current user information with default (unauthorized) guest information.
 java.lang.String selectEdit()
          Action method called when an administrator selects the Edit Users task.
 java.lang.String selectPending()
          Action method called when an administrator selects the Review Pending task.
 void setErrorMessage(java.lang.String errorMessage)
          Setter for the errorMessage property.
 void updateUser(User user)
          Updates a user's database information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HASH_ALGORITHM

public static final java.lang.String HASH_ALGORITHM
See Also:
Constant Field Values
Constructor Detail

UserManager

public UserManager()
The UserManager constructor creates two User objects. The first is populated with guest (unauthenticated) user information that will be updated when the user logs in. The second will be used later if the administrator performs user management.

Method Detail

getUser

public User getUser()
Getter for the user property.

Returns:
information about the current user of the application

getEditedUser

public User getEditedUser()
Getter for the editedUser property.

Returns:
information about the user currently being edited by an admin

getErrorMessage

public java.lang.String getErrorMessage()
Getter for the errorMessage property.

Returns:
information about the current error message

setErrorMessage

public void setErrorMessage(java.lang.String errorMessage)
Setter for the errorMessage property.

Parameters:
errorMessage - the current error message

attemptLogin

public UserManager.Status attemptLogin(java.lang.String name,
                                       java.lang.String password)
                                throws java.sql.SQLException,
                                       java.io.IOException
Attempts to look up a user in the database with the given login information.

Parameters:
name - the submitted user name
password - the submitted password
Returns:
status indicating either login success, name not found, or password not matched
Throws:
java.sql.SQLException - if a database error occurs
java.io.IOException - if a query file error occurs

logout

public void logout()
Replaces all current user information with default (unauthorized) guest information.


attemptRegister

public UserManager.Status attemptRegister(java.lang.String name,
                                          java.lang.String password)
                                   throws java.io.IOException,
                                          java.sql.SQLException
Attempts to add a new user to the database

Parameters:
name -
password -
Returns:
registration status
Throws:
java.io.IOException
java.sql.SQLException

getAllUsers

public javax.servlet.jsp.jstl.sql.Result getAllUsers()
Getter for the allUsers property.

Returns:
a Result object suitable for use in a web page's data table

updateUser

public void updateUser(User user)
                throws java.sql.SQLException,
                       java.io.IOException
Updates a user's database information.

Parameters:
user -
Throws:
java.sql.SQLException
java.io.IOException

selectEdit

public java.lang.String selectEdit()
Action method called when an administrator selects the Edit Users task. This requires a database retrieval of all users and a setting of the allUsers property.

Returns:
an action string for navigating to an error page of the retrieval fails or back to the user management page if it succeeds

getSelectedUser

public int getSelectedUser()
Getter for the selectedUser property.

Returns:
the database ID of the selected user

editUser

public java.lang.String editUser(int id)
Action method called when an administrator selects a user for editing. This requires a database retrieval of the full user record. If successful the editedUser property is populated.

Parameters:
id - the database ID of the selected user
Returns:
an action string for navigating to an error page of the retrieval fails or back to the user management page if it succeeds

selectPending

public java.lang.String selectPending()
Action method called when an administrator selects the Review Pending task. This requires a database retrieval of all pending users and a setting of the pendingUsers property.

Returns:
an action string for navigating to an error page of the retrieval fails or back to the user management page if it succeeds

isNothingSelected

public boolean isNothingSelected()
Getter for the nothingSelected property.

Returns:
true if the administrator has yet to select a user management task

isPendingSelected

public boolean isPendingSelected()
Getter for the pendingSelected property.

Returns:
true if the administrator selected the Review Pending user management task

isEditSelected

public boolean isEditSelected()
Getter for the editSelected property.

Returns:
true if the administrator selected the Edit Users user management task