From 294c50aa41c04a34a397acde4a45b221896165c0 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 12 Mar 2016 19:39:54 +0100 Subject: [PATCH] cleared email addresses after check and before usage so the user is forced to re-enter them. --- .../EmailChangeWebSessionBean.java | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionBean.java index aadf4ba3..402c2d75 100644 --- a/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionBean.java @@ -123,14 +123,20 @@ public class EmailChangeWebSessionBean implements EmailChangeWebSessionControlle assert (user.getUserContact().getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N + // Get dummy email address + String dummyEmail = this.getEmailAddress1(); + + // Unset all so the user is forced to re-enter it + this.clear(); + // Check if the email address is already enqueued - if (this.isEmailAddressQueued()) { + if (this.isEmailAddressQueued(dummyEmail)) { // Yes, then abort here return "login_email_already_added"; //NOI18N } // Create change object, to save EJB calls, the hash is not generated here - ChangeableEmailAddress emailAddress = new EmailAddressChange(user, this.getEmailAddress1(), new GregorianCalendar()); + ChangeableEmailAddress emailAddress = new EmailAddressChange(user, dummyEmail, new GregorianCalendar()); // Call EJB this.emailBean.enqueueEmailAddressForChange(emailAddress); @@ -166,30 +172,41 @@ public class EmailChangeWebSessionBean implements EmailChangeWebSessionControlle } /** - * Checks if current emailAddress1 has already been queued. First a local - * list is being checked, if not found, the EJB is called. Only if found, - * the result is "cached" in the list. + * Clears email address fields so the user has to re-enter them + */ + private void clear () { + // Clear fields + this.setEmailAddress1(null); + this.setEmailAddress2(null); + } + + /** + * Checks if given email address has already been queued. First a local list + * is being checked, if not found, the EJB is called. Only if found, the + * result is "cached" in the list. + *

+ * @param emailAddress Email address to verify *

* @return Whether the email address in field emailAddress1 is already queued */ - private boolean isEmailAddressQueued () { + private boolean isEmailAddressQueued (final String emailAddress) { // It should be there - assert (this.getEmailAddress1() != null) : "emailAddress1 should not be null"; //NOI18N - assert (!this.getEmailAddress1().trim().isEmpty()) : "emailAddress1 should not be empty"; //NOI18N + assert (emailAddress != null) : "emailAddress should not be null"; //NOI18N + assert (!emailAddress.trim().isEmpty()) : "emailAddress should not be empty"; //NOI18N // Check list - if (this.emailAddresses.contains(this.getEmailAddress1())) { + if (this.emailAddresses.contains(emailAddress)) { // Okay, found it return true; } // Check EJB - boolean isQueued = this.emailBean.isEmailAddressEnqueued(this.getEmailAddress1()); + boolean isQueued = this.emailBean.isEmailAddressEnqueued(emailAddress); // Is it there? if (isQueued) { // Add to list - this.emailAddresses.add(this.getEmailAddress1()); + this.emailAddresses.add(emailAddress); } // Return status -- 2.39.5