From d1fbf5fec351ac116ce3dd44065173f53f23aaf7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 10 Jun 2016 12:03:45 +0200 Subject: [PATCH] New "feature" controller introduced: (please cherry-pick this) - no more tons of separate and same-looking methods, just one central and very flexible method isFeatureEnabled() - renamed all context parameters - added features "imprint", "terms" and "privacy" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsAdminContactWebRequestBean.java | 11 +++++ .../contact/JobsContactWebSessionBean.java | 11 +++++ .../JobsContactWebSessionController.java | 24 ++++++++++ .../JobsEmailChangeWebSessionBean.java | 10 ++++ .../JobsUserRegisterWebSessionBean.java | 48 ++++++++----------- .../JobsUserRegisterWebSessionController.java | 14 ------ .../beans/user/JobsUserWebSessionBean.java | 25 +++------- ...PizzaFeaturesWebApplicationController.java | 39 +++++++++++++++ .../generic/gender_selection_box.tpl | 2 +- web/WEB-INF/templates/guest/guest_base.tpl | 4 +- web/WEB-INF/templates/guest/guest_footer.tpl | 32 ++++++++----- web/WEB-INF/templates/guest/guest_menu.tpl | 14 +++--- .../register/guest_form_register_page1.tpl | 4 +- .../register/guest_form_register_single.tpl | 4 +- .../templates/login/user/user_menu.tpl | 24 ++++++---- web/WEB-INF/web.xml | 47 ++++++++++++++---- web/admin/user/admin_user_export.xhtml | 2 +- web/admin/user/admin_user_show.xhtml | 2 +- web/guest/user/login.xhtml | 23 +++++---- web/guest/user/lost_passwd.xhtml | 4 +- web/guest/user/register.xhtml | 34 +++++++------ web/guest/user/register_page2.xhtml | 6 +-- web/guest/user/user_list.xhtml | 37 +++++++------- web/imprint.xhtml | 4 +- web/privacy.xhtml | 4 +- web/terms.xhtml | 4 +- web/user/login_change_personal_data.xhtml | 7 +-- web/user/login_contact_data_saved.xhtml | 2 + 28 files changed, 288 insertions(+), 154 deletions(-) create mode 100644 src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeaturesWebApplicationController.java diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java index 74ea93c8..1109322a 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java @@ -536,6 +536,17 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.contactId = contactId; } + @Override + public String getControllerType () { + return "admin"; //NOI18N + } + + @Override + @Deprecated + public void setControllerType (final String controllerType) { + throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N + } + @Override public Country getCountry () { return this.country; diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java index 6f8982e4..92c9c236 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java @@ -614,6 +614,17 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job this.comment = comment; } + @Override + public String getControllerType () { + return "general"; //NOI18N + } + + @Override + @Deprecated + public void setControllerType (final String controllerType) { + throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N + } + @Override public Country getCountry () { return this.country; diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java index 7e9561f1..ad0a0e42 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java @@ -415,6 +415,22 @@ public interface JobsContactWebSessionController extends Serializable { */ void setZipCode (final Integer zipCode); + /** + * Getter for controller type + *

+ * @return controller type + */ + String getControllerType (); + + /** + * Setter for controller type + *

+ * @param controllerType Controller type + * @deprecated Don't use this method. + */ + @Deprecated + void setControllerType (final String controllerType); + /** * Checks whether contact instance's email address is used *

@@ -453,4 +469,12 @@ public interface JobsContactWebSessionController extends Serializable { */ String doChangePersonalContactData (); + /** + * Returns a list of all selectable contacts for user creation. Contacts + * from already existing users are excluded in this list. + *

+ * @return A list of all selectable contacts + */ + List selectableContacts (); + } diff --git a/src/java/org/mxchange/jjobs/beans/email_address/JobsEmailChangeWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/email_address/JobsEmailChangeWebSessionBean.java index 227f39bf..781e798e 100644 --- a/src/java/org/mxchange/jjobs/beans/email_address/JobsEmailChangeWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/email_address/JobsEmailChangeWebSessionBean.java @@ -29,6 +29,7 @@ import javax.naming.NamingException; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jjobs.beans.BaseJobsController; +import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController; import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; @@ -70,6 +71,12 @@ public class JobsEmailChangeWebSessionBean extends BaseJobsController implements */ private final EmailChangeSessionBeanRemote emailBean; + /** + * Features controller + */ + @Inject + private JobsFeaturesWebApplicationController featureController; + /** * Login bean (controller) */ @@ -112,6 +119,9 @@ public class JobsEmailChangeWebSessionBean extends BaseJobsController implements // Password not matching this.showFacesMessage("form_login_change_email_address:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N return ""; //NOI18N + } else if (!this.featureController.isFeatureEnabled("edit_user_data")) { //NOI18N + // Editing is not allowed + throw new IllegalStateException("User tried to edit personal data"); //NOI18N } // Get user instance diff --git a/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java index 5b4f1797..c2456e70 100644 --- a/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java @@ -20,7 +20,6 @@ import java.text.MessageFormat; import javax.enterprise.context.SessionScoped; import javax.enterprise.event.Event; import javax.enterprise.inject.Any; -import javax.faces.context.FacesContext; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; @@ -32,6 +31,7 @@ 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.RegisteredUserEvent; @@ -70,6 +70,12 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement @Inject private JobsContactWebSessionController contactController; + /** + * Features controller + */ + @Inject + private JobsFeaturesWebApplicationController featureController; + /** * Reemote register session bean */ @@ -106,6 +112,12 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement @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(); @@ -116,7 +128,7 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement } else if (!this.userController.isRequiredPersonalDataSet()) { // Not all required fields are set throw new FaceletException("Not all required fields are set."); //NOI18N - } else if ((this.userController.isUserNameRequired()) && (this.userController.isUserNameRegistered(user))) { + } 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())) { @@ -174,6 +186,12 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement @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(); @@ -181,7 +199,7 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement if (null == user) { // user must be set throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N - } else if ((this.userController.isUserNameRequired()) && (this.userController.isUserNameRegistered(user))) { + } 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()) { @@ -206,28 +224,4 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement return "register_page2"; //NOI18N } - @Override - public boolean isMultiplePageEnabled () { - // Get context parameter - String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_multi_register_page"); //NOI18N - - // Is it set? - boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N - - // Return value - return isEnabled; - } - - @Override - public boolean isResendConfirmationLinkEnabled () { - // Get context parameter - String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_resend_confirm_link_enabled"); //NOI18N - - // Is it set? - boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N - - // Return value - return isEnabled; - } - } diff --git a/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionController.java b/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionController.java index 600149f8..16116dbe 100644 --- a/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionController.java @@ -42,18 +42,4 @@ public interface JobsUserRegisterWebSessionController extends Serializable { */ String doRegisterMultiPage1 (); - /** - * Checks wether multi-page or single-page registration is active - *

- * @return Whether multi (true) or single page (false) is active - */ - boolean isMultiplePageEnabled (); - - /** - * Checks whether the "resend confirmation link" feature is enabled - *

- * @return Whether "resend confirmation link" is enabled - */ - boolean isResendConfirmationLinkEnabled (); - } diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index 6cd1f020..81f5d7b0 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -38,9 +38,9 @@ import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; 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.localization.JobsLocalizationSessionController; import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController; -import org.mxchange.jjobs.beans.register.JobsUserRegisterWebSessionController; import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; @@ -84,27 +84,16 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs private JobsContactWebSessionController contactController; /** - * Localization controller - */ - @Inject - private JobsLocalizationSessionController localizationController; - - /** - * Login bean (controller) + * Features controller */ @Inject - private JobsUserLoginWebSessionController loginController; + private JobsFeaturesWebApplicationController featureController; /** - * Registration controller + * Localization controller */ @Inject - private JobsUserRegisterWebSessionController registerController; - - /** - * A list of all selectable contacts - */ - private List selectableContacts; + private JobsLocalizationSessionController localizationController; /** * Event being fired when user updated personal data @@ -467,7 +456,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs user.setUserProfileMode(this.getUserProfileMode()); // Is multiple registration page - if (!this.registerController.isMultiplePageEnabled()) { + if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N // Create contact instance Contact contact = this.contactController.createContactInstance(); @@ -730,7 +719,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs @Override public boolean isRequiredPersonalDataSet () { - if (this.registerController.isMultiplePageEnabled()) { + if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N // Multiple registration page return this.contactController.isRequiredPersonalDataSet(); } else { diff --git a/src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeaturesWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeaturesWebApplicationController.java new file mode 100644 index 00000000..05892d05 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeaturesWebApplicationController.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * 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.features; + +import java.io.Serializable; +import javax.ejb.Local; + +/** + * An interface for country beans + *

+ * @author Roland Haeder + */ +@Local +public interface PizzaFeaturesWebApplicationController extends Serializable { + + /** + * Checks if given feature is enabled. + *

+ * @param feature Feature to be checked + *

+ * @return Whether given feature is enabled + */ + boolean isFeatureEnabled (final String feature); + +} diff --git a/web/WEB-INF/templates/generic/gender_selection_box.tpl b/web/WEB-INF/templates/generic/gender_selection_box.tpl index 6134e37c..dfa9efcb 100644 --- a/web/WEB-INF/templates/generic/gender_selection_box.tpl +++ b/web/WEB-INF/templates/generic/gender_selection_box.tpl @@ -6,7 +6,7 @@ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> - + diff --git a/web/WEB-INF/templates/guest/guest_base.tpl b/web/WEB-INF/templates/guest/guest_base.tpl index 5b50c7c3..16c4f0b5 100644 --- a/web/WEB-INF/templates/guest/guest_base.tpl +++ b/web/WEB-INF/templates/guest/guest_base.tpl @@ -9,7 +9,9 @@ - + + + diff --git a/web/WEB-INF/templates/guest/guest_footer.tpl b/web/WEB-INF/templates/guest/guest_footer.tpl index 30b4b95f..5fffa6f7 100644 --- a/web/WEB-INF/templates/guest/guest_footer.tpl +++ b/web/WEB-INF/templates/guest/guest_footer.tpl @@ -10,21 +10,29 @@ -

+ + + - + + + - + + + - + + + diff --git a/web/WEB-INF/templates/guest/guest_menu.tpl b/web/WEB-INF/templates/guest/guest_menu.tpl index 716799b6..1b5b5069 100644 --- a/web/WEB-INF/templates/guest/guest_menu.tpl +++ b/web/WEB-INF/templates/guest/guest_menu.tpl @@ -26,23 +26,25 @@ - + + -
    -
  • - -
  • -
+
    +
  • + +
  • +
+