okPassword = false;
}
}
// Validate duplicate username if creating
LogonLogic logic = (LogonLogic) getBean(LOGIC_BEAN);
if (state.isCreating() && (logic.findUser(state.getUsername()) != null)) {
error(messages.getMessage("profile.duplicate"));
okUsername = false;
}
// Return appropriate outcome on validation failures
if (!okUsername) {
return USERNAME;
} else if (!okPassword) {
return PASSWORD;
}
// Create or acquire our User instance
User user = null;
if (state.isCreating()) {
user = logic.createUser();
} else {
user = (User) getBean(getUserKey());
}
// Update to reflect changes during this dialog
user.setCategories(state.getCategories());
if (state.isCreating()) {
user.setConfirmed(!isConfirmation());
}
user.setEmailAddress(state.getEmailAddress());
user.setFullName(state.getFullName());
if ((state.getPassword() != null) && (state.getPassword().length() > 0)) {
user.setPassword(state.getPassword());
}
user.setUsername(state.getUsername());
// Persist the changes made during this dialog
if (state.isCreating()) {
logic.insertUser(user);
} else {
logic.updateUser(user);
}
// Log in a new user if already confirmed
// Otherwise, send the confirmation email
if (state.isCreating()) {