From: Roland Häder Date: Sun, 30 Jul 2017 20:16:54 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=90b3e26067b889307db659170fb3cb10289ae560;p=jfinancials-war.git Please cherry-pick: - don't clear user names or passwords directly, let an event do it Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionBean.java b/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionBean.java index 262ad200..407deacc 100644 --- a/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionBean.java +++ b/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionBean.java @@ -39,6 +39,8 @@ import org.mxchange.jfinancials.beans.features.FinancialsFeaturesWebApplicationC import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController; import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; +import org.mxchange.jusercore.events.user.clear.password.ObservableClearUserPasswordEvent; +import org.mxchange.jusercore.events.user.clear.username.ObservableClearUserNameEvent; import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent; import org.mxchange.jusercore.events.user.helper.created.ObservableHelperCreatedUserEvent; import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent; @@ -552,17 +554,36 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple return this.visibleUserList; } - @Override - public void clearUserName () { + /** + * Event observer for when a user name should be cleared + *

+ * @param event Event being fired + */ + public void clearUserNameEvent (@Observes final ObservableClearUserNameEvent event) { + // Is it valid? + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); + } + // Clear it - this.setUserName(null); + this.clearUserName(); } - @Override - public void clearUserPasswords () { - // Clear both - this.setUserPassword(null); - this.setUserPasswordRepeat(null); + /** + * Event observer for when both user passwords should be cleared + *

+ * @param event Event being fired + */ + public void clearUserPasswordEvent (@Observes final ObservableClearUserPasswordEvent event) { + // Is it valid? + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); + } + + // Clear it + this.clearUserPasswords(); } @Override @@ -1035,6 +1056,23 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple this.clearUserPasswords(); } + /** + * Clears user name + */ + private void clearUserName () { + // Clear it + this.setUserName(null); + } + + /** + * Clears both user passwords + */ + private void clearUserPasswords () { + // Clear both + this.setUserPassword(null); + this.setUserPasswordRepeat(null); + } + /** * Copies given user into the controller *

diff --git a/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionController.java b/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionController.java index bf8b51b7..b0b9ac81 100644 --- a/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionController.java +++ b/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionController.java @@ -44,16 +44,6 @@ public interface FinancialsUserWebSessionController extends Serializable { */ String getUserPassword (); - /** - * Clears both user passwords - */ - void clearUserPasswords (); - - /** - * Clears user name - */ - void clearUserName (); - /** * Checks if both user passwords are left empty and if this is enabled * (allowed) in context parameter. If true, the calling bean should create a diff --git a/src/java/org/mxchange/jfinancials/beans/user/register/FinancialsUserRegisterWebSessionBean.java b/src/java/org/mxchange/jfinancials/beans/user/register/FinancialsUserRegisterWebSessionBean.java index 7068c5dc..553ef3a8 100644 --- a/src/java/org/mxchange/jfinancials/beans/user/register/FinancialsUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/jfinancials/beans/user/register/FinancialsUserRegisterWebSessionBean.java @@ -34,6 +34,10 @@ import org.mxchange.jfinancials.beans.contact.FinancialsContactWebSessionControl import org.mxchange.jfinancials.beans.features.FinancialsFeaturesWebApplicationController; import org.mxchange.jfinancials.beans.user.FinancialsAdminUserWebRequestController; import org.mxchange.jfinancials.beans.user.FinancialsUserWebSessionController; +import org.mxchange.jusercore.events.user.clear.password.ClearUserPasswordEvent; +import org.mxchange.jusercore.events.user.clear.password.ObservableClearUserPasswordEvent; +import org.mxchange.jusercore.events.user.clear.username.ClearUserNameEvent; +import org.mxchange.jusercore.events.user.clear.username.ObservableClearUserNameEvent; import org.mxchange.jusercore.exceptions.DataRepeatMismatchException; import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; @@ -98,6 +102,20 @@ public class FinancialsUserRegisterWebSessionBean extends BaseFinancialsControll @Any private Event userPasswordChangedEvent; + /** + * An event being fired when a user name should be cleared + */ + @Inject + @Any + private Event clearUserNameEvent; + + /** + * An event being fired when a user password should be cleared + */ + @Inject + @Any + private Event clearUserPasswordEvent; + /** * An event being fired when a new user has registered */ @@ -145,8 +163,10 @@ public class FinancialsUserRegisterWebSessionBean extends BaseFinancialsControll // User name is already used, should not happen here throw new FaceletException(new UserNameAlreadyRegisteredException(user)); } else { - // May happen here, reset field - this.userController.clearUserName(); + // May happen here, fire event + this.clearUserNameEvent.fire(new ClearUserNameEvent()); + + // Output message this.showFacesMessage("form_register_single:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N return ""; //NOI18N } @@ -254,7 +274,9 @@ public class FinancialsUserRegisterWebSessionBean extends BaseFinancialsControll throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N } else if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userController.isUserNameRegistered(user))) { //NOI18N // User name is already used, so clear it - this.userController.clearUserName(); + this.clearUserNameEvent.fire(new ClearUserNameEvent()); + + // Output message this.showFacesMessage("form_register_page1:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N return ""; //NOI18N } else if (!this.contactController.isSameEmailAddressEntered()) { @@ -266,7 +288,7 @@ public class FinancialsUserRegisterWebSessionBean extends BaseFinancialsControll // Is multi-page enabled? if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N // Unset both - this.userController.clearUserPasswords(); + this.clearUserPasswordEvent.fire(new ClearUserPasswordEvent()); // Output faces message this.showFacesMessage("form_register_page1:userPassword", "ERROR_USER_PASSWORD_EMPTY"); //NOI18N