From 0ba1fbc222df1fc0bcf7890b2c3e14154bc096e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 30 Jul 2017 22:16:54 +0200 Subject: [PATCH] Please cherry-pick: - don't clear user names or passwords directly, let an event do it MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../user/AddressbookUserWebSessionBean.java | 54 ++++++++++++++++--- .../AddressbookUserWebSessionController.java | 10 ---- ...AddressbookUserRegisterWebSessionBean.java | 30 +++++++++-- 3 files changed, 72 insertions(+), 22 deletions(-) diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java index 1466b3d9..8382b433 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java @@ -39,6 +39,8 @@ import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessio import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController; import org.mxchange.jcontacts.contact.Contact; 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 AddressbookUserWebSessionBean extends BaseAddressbookController imp 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 AddressbookUserWebSessionBean extends BaseAddressbookController imp 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/addressbook/beans/user/AddressbookUserWebSessionController.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java index b5b79e9b..6490d48c 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java @@ -44,16 +44,6 @@ public interface AddressbookUserWebSessionController 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/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java index 8f3f7a65..785070ef 100644 --- a/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java @@ -34,6 +34,10 @@ import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.UserContact; import org.mxchange.jcoreee.utils.FacesUtils; +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 AddressbookUserRegisterWebSessionBean extends BaseAddressbookContro @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 AddressbookUserRegisterWebSessionBean extends BaseAddressbookContro // 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 AddressbookUserRegisterWebSessionBean extends BaseAddressbookContro 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 AddressbookUserRegisterWebSessionBean extends BaseAddressbookContro // 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 -- 2.39.5