+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jjobs.beans.register;
-
-import java.text.MessageFormat;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.inject.Any;
-import javax.faces.view.facelets.FaceletException;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.UserContact;
-import org.mxchange.jcoreee.utils.FacesUtils;
-import org.mxchange.jjobs.beans.BaseJobsController;
-import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
-import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
-import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController;
-import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
-import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
-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.User;
-import org.mxchange.jusercore.model.user.UserUtils;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-
-/**
- * A web bean for user registration
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("registerController")
-@SessionScoped
-public class JobsUserRegisterWebSessionBean extends BaseJobsController implements JobsUserRegisterWebSessionController {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 47_828_986_719_691_592L;
-
- /**
- * User controller
- */
- @Inject
- private JobsAdminUserWebRequestController adminUserController;
-
- /**
- * Contact controller
- */
- @Inject
- private JobsContactWebSessionController contactController;
-
- /**
- * Features controller
- */
- @Inject
- private JobsFeaturesWebApplicationController featureController;
-
- /**
- * Remote register session-scoped bean
- */
- private UserRegistrationSessionBeanRemote registerBean;
-
- /**
- * User controller
- */
- @Inject
- private JobsUserWebSessionController userController;
-
- /**
- * An en event fireable when a new user has registered
- */
- @Inject
- @Any
- private Event<ObservableUserRegisteredEvent> userRegisteredEvent;
-
- /**
- * Default constructor
- */
- public JobsUserRegisterWebSessionBean () {
- // Call super constructor
- super();
- }
-
- @Override
- public String doFinishRegistration () {
- // Is registration enabled?
- if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
- // Is not enabled
- throw new FaceletException("Registration is disabled."); //NOI18N
- }
-
- // Get user instance
- User user = this.userController.createUserInstance(true);
-
- // Is the user already used?
- if (null == user) {
- // user must be set
- throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N
- } else if (!this.userController.isRequiredPersonalDataSet()) {
- // 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
- // 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())) {
- // 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()) {
- // 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
- }
-
- // Encrypt password
- String encryptedPassword = UserUtils.encryptPassword(this.userController.getUserPassword());
-
- // Set it here
- user.setUserEncryptedPassword(encryptedPassword);
-
- // Is developer mode?
- if (this.isDebugModeEnabled("register")) { //NOI18N
- // For debugging/programming only:
- user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
- } else {
- // No debugging of this part
- user.setUserAccountStatus(UserAccountStatus.UNCONFIRMED);
-
- // Ask EJB for generating a not-existing confirmation key
- String confirmKey = this.registerBean.generateConfirmationKey(user);
-
- // Set it in user
- user.setUserConfirmKey(confirmKey);
- }
-
- try {
- // Get base URL
- String baseUrl = FacesUtils.generateBaseUrl();
-
- // Call bean
- User registeredUser = this.registerBean.registerUser(user, baseUrl);
-
- // The id number should be set
- assert (registeredUser.getUserId() instanceof Long) : "registeredUser.userId is null after registerUser() was called."; //NOI18N
-
- // Fire event
- this.userRegisteredEvent.fire(new UserRegisteredEvent(registeredUser));
-
- // All fine, redirect to proper page
- return "user_register_done"; //NOI18N
- } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
- // Continue to throw
- throw new FaceletException(ex);
- }
- }
-
- @Override
- public String doRegisterMultiPage1 () {
- // Is registration enabled?
- if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
- // Is not enabled
- throw new FaceletException("Registration is disabled."); //NOI18N
- }
-
- // Get user instance
- User user = this.userController.createUserInstance(false);
-
- // First check if user is not null and user name is not used + if same email address is entered
- if (null == user) {
- // 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, 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, clear both
- this.contactController.setEmailAddress(null);
- this.contactController.setEmailAddressRepeat(null);
- this.showFacesMessage("form_register_page1:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N
- return ""; //NOI18N
- }
-
- // Create half contact instance with email address
- Contact contact = new UserContact();
- contact.setContactEmailAddress(this.contactController.getEmailAddress());
-
- // Set contact in user
- user.setUserContact(contact);
-
- // Check if email address is registered
- if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
- // 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
- }
-
- /**
- * Post-construction method
- */
- @PostConstruct
- public void init () {
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Try to lookup
- this.registerBean = (UserRegistrationSessionBeanRemote) context.lookup("java:global/jjobs-ejb/register!org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw
- throw new FaceletException(ex);
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jjobs.beans.register;
-
-import java.io.Serializable;
-
-/**
- * An interface for registration web controllers
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface JobsUserRegisterWebSessionController extends Serializable {
-
- /**
- * Registers the user, if not found. Otherwise this method should throw an
- * exception.
- * <p>
- * @return Redirection target
- */
- String doFinishRegistration ();
-
- /**
- * Handles registration request send from first page. The (maybe) entered
- * user name and email address is not used and that privacy and T&C are
- * accepted.
- * <p>
- * @return Redirect
- */
- String doRegisterMultiPage1 ();
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.user.register;
+
+import java.text.MessageFormat;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.UserContact;
+import org.mxchange.jcoreee.utils.FacesUtils;
+import org.mxchange.jjobs.beans.BaseJobsController;
+import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
+import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
+import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController;
+import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
+import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
+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.User;
+import org.mxchange.jusercore.model.user.UserUtils;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+
+/**
+ * A web bean for user registration
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("registerController")
+@SessionScoped
+public class JobsUserRegisterWebSessionBean extends BaseJobsController implements JobsUserRegisterWebSessionController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 47_828_986_719_691_592L;
+
+ /**
+ * User controller
+ */
+ @Inject
+ private JobsAdminUserWebRequestController adminUserController;
+
+ /**
+ * Contact controller
+ */
+ @Inject
+ private JobsContactWebSessionController contactController;
+
+ /**
+ * Features controller
+ */
+ @Inject
+ private JobsFeaturesWebApplicationController featureController;
+
+ /**
+ * Remote register session-scoped bean
+ */
+ private UserRegistrationSessionBeanRemote registerBean;
+
+ /**
+ * User controller
+ */
+ @Inject
+ private JobsUserWebSessionController userController;
+
+ /**
+ * An en event fireable when a new user has registered
+ */
+ @Inject
+ @Any
+ private Event<ObservableUserRegisteredEvent> userRegisteredEvent;
+
+ /**
+ * Default constructor
+ */
+ public JobsUserRegisterWebSessionBean () {
+ // Call super constructor
+ super();
+ }
+
+ @Override
+ public String doFinishRegistration () {
+ // Is registration enabled?
+ if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
+ // Is not enabled
+ throw new FaceletException("Registration is disabled."); //NOI18N
+ }
+
+ // Get user instance
+ User user = this.userController.createUserInstance(true);
+
+ // Is the user already used?
+ if (null == user) {
+ // user must be set
+ throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N
+ } else if (!this.userController.isRequiredPersonalDataSet()) {
+ // 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
+ // 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())) {
+ // 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()) {
+ // 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
+ }
+
+ // Encrypt password
+ String encryptedPassword = UserUtils.encryptPassword(this.userController.getUserPassword());
+
+ // Set it here
+ user.setUserEncryptedPassword(encryptedPassword);
+
+ // Is developer mode?
+ if (this.isDebugModeEnabled("register")) { //NOI18N
+ // For debugging/programming only:
+ user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
+ } else {
+ // No debugging of this part
+ user.setUserAccountStatus(UserAccountStatus.UNCONFIRMED);
+
+ // Ask EJB for generating a not-existing confirmation key
+ String confirmKey = this.registerBean.generateConfirmationKey(user);
+
+ // Set it in user
+ user.setUserConfirmKey(confirmKey);
+ }
+
+ try {
+ // Get base URL
+ String baseUrl = FacesUtils.generateBaseUrl();
+
+ // Call bean
+ User registeredUser = this.registerBean.registerUser(user, baseUrl);
+
+ // The id number should be set
+ assert (registeredUser.getUserId() instanceof Long) : "registeredUser.userId is null after registerUser() was called."; //NOI18N
+
+ // Fire event
+ this.userRegisteredEvent.fire(new UserRegisteredEvent(registeredUser));
+
+ // All fine, redirect to proper page
+ return "user_register_done"; //NOI18N
+ } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
+ // Continue to throw
+ throw new FaceletException(ex);
+ }
+ }
+
+ @Override
+ public String doRegisterMultiPage1 () {
+ // Is registration enabled?
+ if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N
+ // Is not enabled
+ throw new FaceletException("Registration is disabled."); //NOI18N
+ }
+
+ // Get user instance
+ User user = this.userController.createUserInstance(false);
+
+ // First check if user is not null and user name is not used + if same email address is entered
+ if (null == user) {
+ // 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, 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, clear both
+ this.contactController.setEmailAddress(null);
+ this.contactController.setEmailAddressRepeat(null);
+ this.showFacesMessage("form_register_page1:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Create half contact instance with email address
+ Contact contact = new UserContact();
+ contact.setContactEmailAddress(this.contactController.getEmailAddress());
+
+ // Set contact in user
+ user.setUserContact(contact);
+
+ // Check if email address is registered
+ if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
+ // 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
+ }
+
+ /**
+ * Post-construction method
+ */
+ @PostConstruct
+ public void init () {
+ try {
+ // Get initial context
+ Context context = new InitialContext();
+
+ // Try to lookup
+ this.registerBean = (UserRegistrationSessionBeanRemote) context.lookup("java:global/jjobs-ejb/register!org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw
+ throw new FaceletException(ex);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.user.register;
+
+import java.io.Serializable;
+
+/**
+ * An interface for registration web controllers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface JobsUserRegisterWebSessionController extends Serializable {
+
+ /**
+ * Registers the user, if not found. Otherwise this method should throw an
+ * exception.
+ * <p>
+ * @return Redirection target
+ */
+ String doFinishRegistration ();
+
+ /**
+ * Handles registration request send from first page. The (maybe) entered
+ * user name and email address is not used and that privacy and T&C are
+ * accepted.
+ * <p>
+ * @return Redirect
+ */
+ String doRegisterMultiPage1 ();
+
+}