* <p>Create or update the user information.</p>
* @throws ExpiredPasswordException
*/
public String save() throws ExpiredPasswordException {
UserDatabase database = getUserDatabase();
String mode = getState().getMode();
boolean ok = true;
User user = null;
if ("CREATE".equals(mode)) {
// Verify that the proposed username is not already taken
if (database.findUser(username) != null) {
// FIXME - localization
getFacesContext().addMessage("registration:username",
new FacesMessage("That username is already taken"));
ok = false;
}
// Verify that the two password values match
if (!password.equals(password2)) {
// FIXME - localization
getFacesContext().addMessage("registration:password2",
new FacesMessage("Password values do not match"));
ok = false;
}
// Create a new user with the specified username and password
// and log the new user on
if (ok) {
user = database.createUser(username);
getState().setUser(user);
}
} else /* if ("EDIT".equals(mode)) */ {
// Verify that the two password values match (if entered)
if ((password != null) && (password.length() > 0) &&
(password2 != null) && (password2.length() > 0) &&
!password.equals(password2)) {
// FIXME - localization
getFacesContext().addMessage("registration:password2",
new FacesMessage("Password values do not match"));
ok = false;
}
// Edit the currently logged on user
user = getState().getUser();
}
// Copy the remaining properties
if (ok) {
if ((password != null) && (password.length() > 0)) {
user.setPassword(password);
}
user.setFullName(fullName);
user.setFromAddress(fromAddress);
user.setReplyToAddress(replyToAddress);
}
// Save the updated information to the database
try {
database.save();
} catch (Exception e) {
getFacesContext().addMessage(null,
new FacesMessage(e.getMessage()));
log.error("Database save exception", e);
ok = false;