import org.mxchange.jusercore.exceptions.DataRepeatMismatchException;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
-import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.UserUtils;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
// Get user instance
User user = this.userController.createUserInstance(true);
+ // Null random password means registration requires user-entered password
+ String randomPassword = null;
+
// Is the user already used?
if (null == user) {
// user must be set
// Not all required fields are set
throw new FaceletException("Not all required fields are set."); //NOI18N
} else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
- // User name is already used
- throw new FaceletException(new UserNameAlreadyRegisteredException(user));
+ // Is multi-page enabled?
+ if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
+ // User name is already used, should not happen here
+ throw new FaceletException(new UserNameAlreadyRegisteredException(user));
+ } else {
+ // May happen here, reset field
+ this.userController.setUserName(null);
+ this.showFacesMessage("form_register_single:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N
+ return ""; //NOI18N
+ }
} else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
- // Email address has already been taken
- throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
+ // Is multi-page enabled?
+ if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
+ // Email address has already been taken, should not happen here
+ throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
+ } else {
+ // May happen here, reset fields
+ this.contactController.setEmailAddress(null);
+ this.contactController.setEmailAddressRepeat(null);
+ this.showFacesMessage("form_register_single:emailAddressRepeat", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N
+ return ""; //NOI18N
+ }
} else if (!this.contactController.isSameEmailAddressEntered()) {
- // Not same email address entered
- throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N
+ // Is multi-page enabled?
+ if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
+ // Not same email address entered, should not happen here
+ throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N
+ } else {
+ // May happen here, reset fields
+ this.contactController.setEmailAddress(null);
+ this.contactController.setEmailAddressRepeat(null);
+ this.showFacesMessage("form_register_single:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N
+ return ""; //NOI18N
+ }
} else if (!this.userController.isSamePasswordEntered()) {
- // Not same password entered
- throw new FaceletException(new DataRepeatMismatchException("Passwords not matching.")); //NOI18N
+ // Is multi-page enabled?
+ if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
+ // Not same password entered, should no longer happen here
+ throw new FaceletException(new DataRepeatMismatchException("Passwords not matching.")); //NOI18N
+ } else if (this.userController.ifBothPasswordsEmptyAllowed()) {
+ // Both passwords are left empty and is allowed, then generate a random password
+ randomPassword = UserUtils.createRandomPassword(FinancialsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
+
+ // Set it in both fields
+ this.userController.setUserPassword(randomPassword);
+ this.userController.setUserPasswordRepeat(randomPassword);
+ }
}
// Encrypt password
String baseUrl = FacesUtils.generateBaseUrl();
// Call bean
- User registeredUser = this.registerBean.registerUser(user, baseUrl);
+ User registeredUser = this.registerBean.registerUser(user, baseUrl, randomPassword);
// The id number should be set
assert (registeredUser.getUserId() instanceof Long) : "registeredUser.userId is null after registerUser() was called."; //NOI18N
// user must be set
throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N
} else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N
- // User name is already used
- throw new FaceletException(new UserNameAlreadyRegisteredException(user));
+ // User name is already used, so clear it
+ this.userController.setUserName(null);
+ this.showFacesMessage("form_register_page1:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N
+ return ""; //NOI18N
} else if (!this.contactController.isSameEmailAddressEntered()) {
- // Not same email address entered
- throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N
+ // Not same email address entered, clear both
+ this.contactController.setEmailAddress(null);
+ this.contactController.setEmailAddressRepeat(null);
+ this.showFacesMessage("form_register_page1:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N
+ return ""; //NOI18N
+ } else if (!this.userController.isSamePasswordEntered()) {
+ // Is multi-page enabled?
+ if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
+ // Unset both
+ this.userController.setUserPassword(null);
+ this.userController.setUserPasswordRepeat(null);
+
+ // Output faces message
+ this.showFacesMessage("form_register_page1:userPassword", "ERROR_USER_PASSWORD_EMPTY"); //NOI18N
+ this.showFacesMessage("form_register_page1:userPasswordRepeat", "ERROR_USER_PASSWORD_REPEAT_EMPTY"); //NOI18N
+ return ""; //NOI18N
+ } else if (this.userController.ifBothPasswordsEmptyAllowed()) {
+ // Both passwords are left empty and is allowed, then generate a random password
+ String randomPassword = UserUtils.createRandomPassword(FinancialsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
+
+ // Set it in both fields
+ this.userController.setUserPassword(randomPassword);
+ this.userController.setUserPasswordRepeat(randomPassword);
+ }
}
// Create half contact instance with email address
// Check if email address is registered
if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
- // Email address has already been taken
- throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
+ // Email address has already been taken, clear both
+ this.contactController.setEmailAddress(null);
+ this.contactController.setEmailAddressRepeat(null);
+ this.showFacesMessage("form_register_page1:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N
+ return ""; //NOI18N
}
// Now only redirect to next page as the JSF does it
- return "user_register_page2"; //NOI18N
+ return "register_page2"; //NOI18N
}
/**
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<ui:composition
- xmlns="http://www.w3.org/1999/xhtml"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
-
- <h:form id="register_page2_form">
- <div class="table">
- <div class="table_header">
- <h:outputText value="#{msg.GUEST_REGISTRATION_PAGE2_TITLE}" />
- </div>
-
- <ui:include src="/WEB-INF/templates/contact/form_contact_data.tpl" />
-
- <div class="para">
- <fieldset id="login_data">
- <legend title="#{msg.GUEST_REGISTRATION_EMAIL_LEGEND_TITLE}">#{msg.GUEST_REGISTRATION_EMAIL_LEGEND}</legend>
-
- <div class="table_row">
- <div class="table_left">
- <h:outputLabel for="userName" value="#{msg.GUEST_REGISTRATION_ENTER_USER_NAME}" />
- </div>
-
- <div class="table_right">
- <h:inputText styleClass="input" id="userName" size="20" maxlength="255" value="#{userController.userName}" required="true" requiredMessage="#{msg.GUEST_REGISTRATION_USER_NAME_NOT_ENTERED}" />
- </div>
-
- <div class="clear"></div>
- </div>
-
- <h:panelGroup styleClass="error_container" layout="block">
- <h:message for="userName" errorClass="errors" fatalClass="errors" warnClass="errors" />
- </h:panelGroup>
-
- <div class="table_row">
- <div class="table_left">
- <h:outputLabel for="emailAddress" value="#{msg.GUEST_REGISTRATION_ENTER_EMAIL1}" />
- </div>
-
- <div class="table_right">
- <h:inputText styleClass="input" id="emailAddress" size="20" maxlength="255" value="#{contactController.emailAddress}" required="true" requiredMessage="#{msg.EMAIL_ADDRESS_NOT_ENTERED}" />
- </div>
-
- <div class="clear"></div>
- </div>
-
- <h:panelGroup styleClass="error_container" layout="block">
- <h:message for="emailAddress" errorClass="errors" fatalClass="errors" warnClass="errors" />
- </h:panelGroup>
-
- <div class="table_row">
- <div class="table_left">
- <h:outputLabel for="emailAddressRepeat" value="#{msg.GUEST_REGISTRATION_ENTER_EMAIL2}" />
- </div>
-
- <div class="table_right">
- <h:inputText styleClass="input" id="emailAddressRepeat" size="20" maxlength="255" value="#{contactController.emailAddressRepeat}" required="true" requiredMessage="#{msg.EMAIL_ADDRESS_REPEAT_NOT_ENTERED}" />
- </div>
-
- <div class="clear"></div>
- </div>
-
- <h:panelGroup styleClass="error_container" layout="block">
- <h:message for="emailAddressRepeat" errorClass="errors" fatalClass="errors" warnClass="errors" />
- </h:panelGroup>
-
- <div class="para"></div>
-
- <div class="table_row">
- <div class="table_left">
- <h:outputLabel for="userPassword" value="#{msg.GUEST_REGISTRATION_ENTER_PASSWORD}" />
- </div>
-
- <div class="table_right">
- <h:inputSecret styleClass="input" id="userPassword" size="10" maxlength="255" value="#{userController.userPassword}" />
- </div>
-
- <div class="clear"></div>
- </div>
-
- <div class="table_row">
- <div class="table_left">
- <h:outputLabel for="userPasswordRepeat" value="#{msg.GUEST_REGISTRATION_ENTER_PASSWORD_REPEAT}" />
- </div>
-
- <div class="table_right">
- <h:inputSecret styleClass="input" id="userPasswordRepeat" size="10" maxlength="255" value="#{userController.userPasswordRepeat}" />
- </div>
-
- <div class="clear"></div>
- </div>
-
- <div class="para notice">
- <h:outputText value="#{msg.GUEST_REGISTRATION_USER_NAME_NOTICE}" />
- </div>
- </fieldset>
- </div>
-
- <ui:include src="/WEB-INF/templates/guest/guest_privacy_terms.tpl" />
-
- <div class="table_footer">
- <h:commandButton styleClass="reset" type="reset" value="#{msg.BUTTON_RESET_FORM}" />
- <h:commandButton styleClass="submit" type="submit" id="register" value="#{msg.BUTTON_FINISH_REGISTRATION}" action="#{registerController.doFinishRegistration()}" />
- </div>
- </div>
- </h:form>
-</ui:composition>