/*
- * Copyright (C) 2016 quix0r
+ * Copyright (C) 2016 Roland Haeder
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
package org.mxchange.addressbook.beans.email_address;
import java.text.MessageFormat;
-import java.util.GregorianCalendar;
import java.util.List;
import java.util.Objects;
import javax.enterprise.context.SessionScoped;
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);
// Call EJB
this.emailBean.enqueueEmailAddressForChange(emailAddress);
}
/**
- * 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.
+ * <p>
+ * @param emailAddress Email address to verify
* <p>
* @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