+++ /dev/null
-/*
- * 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
- * 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jjobs.beans.email_address;
-
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.Objects;
-import javax.enterprise.context.SessionScoped;
-import javax.faces.view.facelets.FaceletException;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jjobs.beans.login.UserLoginWebSessionController;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
-import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
-import org.mxchange.jusercore.model.email_address.EmailAddressChange;
-import org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A web session bean for changing email addresses
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Named ("emailChangeController")
-@SessionScoped
-public class EmailChangeWebSessionBean implements EmailChangeWebSessionController {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 186_078_724_659_153L;
-
- /**
- * Email address 1 (changing)
- */
- private String emailAddress1;
-
- /**
- * Email address 2 (repeat in changing)
- */
- private String emailAddress2;
-
- /**
- * Local list of already queued email addresses
- */
- private List<String> emailAddresses;
-
- /**
- * Remote email change bean
- */
- private final EmailChangeSessionBeanRemote emailBean;
-
- /**
- * Login bean (controller)
- */
- @Inject
- private UserLoginWebSessionController loginController;
-
- /**
- * Default constructor
- */
- public EmailChangeWebSessionBean () {
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Try to lookup
- this.emailBean = (EmailChangeSessionBeanRemote) context.lookup("ejb/stateless-jjobs-email-change"); //NOI18N
-
- // Init list
- this.emailAddresses = this.emailBean.allQueuedAddressesAsList();
- } catch (final NamingException e) {
- // Throw again
- throw new FaceletException(e);
- }
- }
-
- @Override
- public String doChangeEmailAddress () {
- // This method shall only be called if the user is logged-in
- if (!this.loginController.isUserLoggedIn()) {
- // Not logged-in
- throw new IllegalStateException("User is not logged-in"); //NOI18N
- } else if (!this.isRequiredChangeEmailAddressSet()) {
- // Not all required fields are set
- throw new FaceletException("Not all required fields are set."); //NOI18N
- } else if (!Objects.equals(this.getEmailAddress1(), this.getEmailAddress2())) {
- // Email address 1+2 mismatch
- throw new FaceletException("Email address 1/2 are mismatching."); //NOI18N
- } else if (!this.loginController.ifCurrentPasswordMatches()) {
- // Password not matching
- throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
- }
-
- // Get user instance
- User user = this.loginController.getLoggedInUser();
-
- // It should be there, so run some tests on it
- assert (user instanceof User) : "Instance loginController.loggedInUser is null"; //NOI18N
- assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null"; //NOI18N
- assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
- assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N
- 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(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, dummyEmail);
-
- // Call EJB
- this.emailBean.enqueueEmailAddressForChange(emailAddress);
-
- // All fine
- return "login_email_change_queued"; //NOI18N
- }
-
- @Override
- public String getEmailAddress1 () {
- return this.emailAddress1;
- }
-
- @Override
- public void setEmailAddress1 (final String emailAddress1) {
- this.emailAddress1 = emailAddress1;
- }
-
- @Override
- public String getEmailAddress2 () {
- return this.emailAddress2;
- }
-
- @Override
- public void setEmailAddress2 (final String emailAddress2) {
- this.emailAddress2 = emailAddress2;
- }
-
- @Override
- public boolean isRequiredChangeEmailAddressSet () {
- return ((this.getEmailAddress1() != null) &&
- (this.getEmailAddress2() != null));
- }
-
- /**
- * 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 (final String emailAddress) {
- // It should be there
- 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(emailAddress)) {
- // Okay, found it
- return true;
- }
-
- // Check EJB
- boolean isQueued = this.emailBean.isEmailAddressEnqueued(emailAddress);
-
- // Is it there?
- if (isQueued) {
- // Add to list
- this.emailAddresses.add(emailAddress);
- }
-
- // Return status
- return isQueued;
- }
-
-}
+++ /dev/null
-/*
- * 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
- * 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jjobs.beans.email_address;
-
-import java.io.Serializable;
-
-/**
- * An interface for an email change controller
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-public interface EmailChangeWebSessionController extends Serializable {
-
- /**
- * Getter for email address 1 (changing)
- * <p>
- * @return Email address
- */
- String getEmailAddress1 ();
-
- /**
- * Setter for email address 1 (changing)
- * <p>
- * @param emailAddress1 Email address 1
- */
- void setEmailAddress1 (final String emailAddress1);
-
- /**
- * Getter for email address 2 (repeat changing)
- * <p>
- * @return Email address 2
- */
- String getEmailAddress2 ();
-
- /**
- * Setter for email address 2 (repeat changing)
- * <p>
- * @param emailAddress2 Email address 2
- */
- void setEmailAddress2 (final String emailAddress2);
-
- /**
- * Checks whether all required are set for changing email address
- * <p>
- * @return Whether the required personal data is set
- */
- boolean isRequiredChangeEmailAddressSet ();
-
- /**
- * Changes logged-in user's email address if the current password matches.
- * <p>
- * @return New target page
- */
- String doChangeEmailAddress ();
-
-}
--- /dev/null
+/*
+ * 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
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.email_address;
+
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Objects;
+import javax.enterprise.context.SessionScoped;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jjobs.beans.login.UserLoginWebSessionController;
+import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
+import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
+import org.mxchange.jusercore.model.email_address.EmailAddressChange;
+import org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A web session bean for changing email addresses
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("emailChangeController")
+@SessionScoped
+public class JobsEmailChangeWebSessionBean implements JobsEmailChangeWebSessionController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 186_078_724_659_153L;
+
+ /**
+ * Email address 1 (changing)
+ */
+ private String emailAddress1;
+
+ /**
+ * Email address 2 (repeat in changing)
+ */
+ private String emailAddress2;
+
+ /**
+ * Local list of already queued email addresses
+ */
+ private List<String> emailAddresses;
+
+ /**
+ * Remote email change bean
+ */
+ private final EmailChangeSessionBeanRemote emailBean;
+
+ /**
+ * Login bean (controller)
+ */
+ @Inject
+ private UserLoginWebSessionController loginController;
+
+ /**
+ * Default constructor
+ */
+ public JobsEmailChangeWebSessionBean () {
+ // Try it
+ try {
+ // Get initial context
+ Context context = new InitialContext();
+
+ // Try to lookup
+ this.emailBean = (EmailChangeSessionBeanRemote) context.lookup("ejb/stateless-jjobs-email-change"); //NOI18N
+
+ // Init list
+ this.emailAddresses = this.emailBean.allQueuedAddressesAsList();
+ } catch (final NamingException e) {
+ // Throw again
+ throw new FaceletException(e);
+ }
+ }
+
+ @Override
+ public String doChangeEmailAddress () {
+ // This method shall only be called if the user is logged-in
+ if (!this.loginController.isUserLoggedIn()) {
+ // Not logged-in
+ throw new IllegalStateException("User is not logged-in"); //NOI18N
+ } else if (!this.isRequiredChangeEmailAddressSet()) {
+ // Not all required fields are set
+ throw new FaceletException("Not all required fields are set."); //NOI18N
+ } else if (!Objects.equals(this.getEmailAddress1(), this.getEmailAddress2())) {
+ // Email address 1+2 mismatch
+ throw new FaceletException("Email address 1/2 are mismatching."); //NOI18N
+ } else if (!this.loginController.ifCurrentPasswordMatches()) {
+ // Password not matching
+ throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
+ }
+
+ // Get user instance
+ User user = this.loginController.getLoggedInUser();
+
+ // It should be there, so run some tests on it
+ assert (user instanceof User) : "Instance loginController.loggedInUser is null"; //NOI18N
+ assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null"; //NOI18N
+ assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
+ assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N
+ 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(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, dummyEmail);
+
+ // Call EJB
+ this.emailBean.enqueueEmailAddressForChange(emailAddress);
+
+ // All fine
+ return "login_email_change_queued"; //NOI18N
+ }
+
+ @Override
+ public String getEmailAddress1 () {
+ return this.emailAddress1;
+ }
+
+ @Override
+ public void setEmailAddress1 (final String emailAddress1) {
+ this.emailAddress1 = emailAddress1;
+ }
+
+ @Override
+ public String getEmailAddress2 () {
+ return this.emailAddress2;
+ }
+
+ @Override
+ public void setEmailAddress2 (final String emailAddress2) {
+ this.emailAddress2 = emailAddress2;
+ }
+
+ @Override
+ public boolean isRequiredChangeEmailAddressSet () {
+ return ((this.getEmailAddress1() != null) &&
+ (this.getEmailAddress2() != null));
+ }
+
+ /**
+ * 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 (final String emailAddress) {
+ // It should be there
+ 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(emailAddress)) {
+ // Okay, found it
+ return true;
+ }
+
+ // Check EJB
+ boolean isQueued = this.emailBean.isEmailAddressEnqueued(emailAddress);
+
+ // Is it there?
+ if (isQueued) {
+ // Add to list
+ this.emailAddresses.add(emailAddress);
+ }
+
+ // Return status
+ return isQueued;
+ }
+
+}
--- /dev/null
+/*
+ * 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
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.email_address;
+
+import java.io.Serializable;
+
+/**
+ * An interface for an email change controller
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface JobsEmailChangeWebSessionController extends Serializable {
+
+ /**
+ * Getter for email address 1 (changing)
+ * <p>
+ * @return Email address
+ */
+ String getEmailAddress1 ();
+
+ /**
+ * Setter for email address 1 (changing)
+ * <p>
+ * @param emailAddress1 Email address 1
+ */
+ void setEmailAddress1 (final String emailAddress1);
+
+ /**
+ * Getter for email address 2 (repeat changing)
+ * <p>
+ * @return Email address 2
+ */
+ String getEmailAddress2 ();
+
+ /**
+ * Setter for email address 2 (repeat changing)
+ * <p>
+ * @param emailAddress2 Email address 2
+ */
+ void setEmailAddress2 (final String emailAddress2);
+
+ /**
+ * Checks whether all required are set for changing email address
+ * <p>
+ * @return Whether the required personal data is set
+ */
+ boolean isRequiredChangeEmailAddressSet ();
+
+ /**
+ * Changes logged-in user's email address if the current password matches.
+ * <p>
+ * @return New target page
+ */
+ String doChangeEmailAddress ();
+
+}