From: Roland Häder Date: Thu, 22 Jun 2017 19:58:44 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c4c75aae6f956b84e18867f125f1f8ec628b1cd3;p=pizzaservice-war.git Don't cherry-pick: - moved bean to proper package as it is user-specific registration - fixed imports and method calls Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java index 819d6a3c..c54df4fa 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java @@ -28,18 +28,18 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.gender.PersonalTitle; +import org.mxchange.jcontacts.contact.title.PersonalTitle; import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; import org.mxchange.jcustomercore.events.customer.added.AdminAddedCustomerEvent; +import org.mxchange.jcustomercore.events.customer.added.ObservableAdminAddedCustomerEvent; import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException; import org.mxchange.jcustomercore.model.customer.Customer; import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus; import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; import org.mxchange.pizzaapplication.model.customer.PizzaAdminCustomerSessionBeanRemote; import org.mxchange.pizzaapplication.model.customer.PizzaCustomer; -import org.mxchange.jcustomercore.events.customer.added.ObservableAdminAddedCustomerEvent; -import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; /** * Administrative customer bean (controller) @@ -195,7 +195,7 @@ public class PizzaAdminCustomerWebRequestBean extends BasePizzaController implem */ private boolean isCustomerDataSet () { // Check all - return ((this.adminContactController.getGender() instanceof PersonalTitle) && + return ((this.adminContactController.getPersonalTitle() instanceof PersonalTitle) && (this.adminContactController.getFirstName() != null) && (!this.adminContactController.getFirstName().isEmpty()) && (this.adminContactController.getFamilyName() != null) && diff --git a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java deleted file mode 100644 index 84aa05a4..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * 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 . - */ -package org.mxchange.pizzaapplication.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.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; -import org.mxchange.pizzaapplication.beans.BasePizzaController; -import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; -import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController; -import org.mxchange.pizzaapplication.beans.user.PizzaAdminUserWebRequestController; -import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; - -/** - * A web bean for user registration - *

- * @author Roland Häder - */ -@Named ("registerController") -@SessionScoped -public class PizzaUserRegisterWebSessionBean extends BasePizzaController implements PizzaUserRegisterWebSessionController { - - /** - * Serial number - */ - private static final long serialVersionUID = 47_828_986_719_691_592L; - - /** - * User controller - */ - @Inject - private PizzaAdminUserWebRequestController adminUserController; - - /** - * Contact controller - */ - @Inject - private PizzaContactWebSessionController contactController; - - /** - * Features controller - */ - @Inject - private PizzaFeaturesWebApplicationController featureController; - - /** - * Remote register session-scoped bean - */ - private UserRegistrationSessionBeanRemote registerBean; - - /** - * User controller - */ - @Inject - private PizzaUserWebSessionController userController; - - /** - * An en event fireable when a new user has registered - */ - @Inject - @Any - private Event userRegisteredEvent; - - /** - * Default constructor - */ - public PizzaUserRegisterWebSessionBean () { - // 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 - // User name is already used - throw new FaceletException(new UserNameAlreadyRegisteredException(user)); - } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { - // Email address has already been taken - throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); - } 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 - } 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 "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 - throw new FaceletException(new UserNameAlreadyRegisteredException(user)); - } 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 - } - - // 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 - throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); - } - - // 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/pizzaservice-ejb/register!org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw - throw new FaceletException(ex); - } - } - -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionController.java deleted file mode 100644 index 4d387683..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionController.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 . - */ -package org.mxchange.pizzaapplication.beans.register; - -import java.io.Serializable; - -/** - * An interface for registration web controllers - *

- * @author Roland Häder - */ -public interface PizzaUserRegisterWebSessionController extends Serializable { - - /** - * Registers the user, if not found. Otherwise this method should throw an - * exception. - *

- * @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. - *

- * @return Redirect - */ - String doRegisterMultiPage1 (); - -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/register/PizzaUserRegisterWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/register/PizzaUserRegisterWebSessionBean.java new file mode 100644 index 00000000..16f67ce8 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/user/register/PizzaUserRegisterWebSessionBean.java @@ -0,0 +1,237 @@ +/* + * 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 . + */ +package org.mxchange.pizzaapplication.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.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; +import org.mxchange.pizzaapplication.beans.BasePizzaController; +import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; +import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController; +import org.mxchange.pizzaapplication.beans.user.PizzaAdminUserWebRequestController; +import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; + +/** + * A web bean for user registration + *

+ * @author Roland Häder + */ +@Named ("registerController") +@SessionScoped +public class PizzaUserRegisterWebSessionBean extends BasePizzaController implements PizzaUserRegisterWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 47_828_986_719_691_592L; + + /** + * User controller + */ + @Inject + private PizzaAdminUserWebRequestController adminUserController; + + /** + * Contact controller + */ + @Inject + private PizzaContactWebSessionController contactController; + + /** + * Features controller + */ + @Inject + private PizzaFeaturesWebApplicationController featureController; + + /** + * Remote register session-scoped bean + */ + private UserRegistrationSessionBeanRemote registerBean; + + /** + * User controller + */ + @Inject + private PizzaUserWebSessionController userController; + + /** + * An en event fireable when a new user has registered + */ + @Inject + @Any + private Event userRegisteredEvent; + + /** + * Default constructor + */ + public PizzaUserRegisterWebSessionBean () { + // 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 + // User name is already used + throw new FaceletException(new UserNameAlreadyRegisteredException(user)); + } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { + // Email address has already been taken + throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); + } 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 + } 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 "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 + throw new FaceletException(new UserNameAlreadyRegisteredException(user)); + } 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 + } + + // 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 + throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); + } + + // 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/pizzaservice-ejb/register!org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw + throw new FaceletException(ex); + } + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/register/PizzaUserRegisterWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/user/register/PizzaUserRegisterWebSessionController.java new file mode 100644 index 00000000..4dbedc46 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/user/register/PizzaUserRegisterWebSessionController.java @@ -0,0 +1,45 @@ +/* + * 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 . + */ +package org.mxchange.pizzaapplication.beans.user.register; + +import java.io.Serializable; + +/** + * An interface for registration web controllers + *

+ * @author Roland Häder + */ +public interface PizzaUserRegisterWebSessionController extends Serializable { + + /** + * Registers the user, if not found. Otherwise this method should throw an + * exception. + *

+ * @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. + *

+ * @return Redirect + */ + String doRegisterMultiPage1 (); + +}