]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Fri, 23 Jun 2017 20:16:07 +0000 (22:16 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 23 Jun 2017 20:16:07 +0000 (22:16 +0200)
- moved to proper package as these are user-related controllers

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/beans/contact/FinancialsAdminContactWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/contact/FinancialsContactWebSessionBean.java
src/java/org/mxchange/jfinancials/beans/email_address/FinancialsEmailChangeWebSessionBean.java [deleted file]
src/java/org/mxchange/jfinancials/beans/email_address/FinancialsEmailChangeWebSessionController.java [deleted file]
src/java/org/mxchange/jfinancials/beans/resendlink/FinancialsResendLinkWebSessionBean.java [deleted file]
src/java/org/mxchange/jfinancials/beans/resendlink/FinancialsResendLinkWebSessionController.java [deleted file]
src/java/org/mxchange/jfinancials/beans/user/email_address/FinancialsEmailChangeWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/user/email_address/FinancialsEmailChangeWebSessionController.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/user/resendlink/FinancialsResendLinkWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/user/resendlink/FinancialsResendLinkWebSessionController.java [new file with mode: 0644]

index 09b47dda14c81c8bd6b049511684d785dd9089e6..44c3fc97678e90885ba0eee61e7ad561a289d743 100644 (file)
@@ -35,7 +35,7 @@ import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
 import org.mxchange.jcontacts.contact.UserContact;
 import org.mxchange.jcontacts.contact.title.PersonalTitle;
-import org.mxchange.jcontacts.contact.utils.ContactUtils;
+import org.mxchange.jcontacts.contact.ContactUtils;
 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
index 825f1af237f33ca0621faa252b1baaa8806cef9a..5ee4988532a849ee376083a9d226e2c26c18fd88 100644 (file)
@@ -36,7 +36,7 @@ import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
 import org.mxchange.jcontacts.contact.UserContact;
 import org.mxchange.jcontacts.contact.title.PersonalTitle;
-import org.mxchange.jcontacts.contact.utils.ContactUtils;
+import org.mxchange.jcontacts.contact.ContactUtils;
 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
 import org.mxchange.jcontactsbusiness.exceptions.BusinessContactNotFoundException;
diff --git a/src/java/org/mxchange/jfinancials/beans/email_address/FinancialsEmailChangeWebSessionBean.java b/src/java/org/mxchange/jfinancials/beans/email_address/FinancialsEmailChangeWebSessionBean.java
deleted file mode 100644 (file)
index da10877..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jfinancials.beans.email_address;
-
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-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.jcoreee.utils.FacesUtils;
-import org.mxchange.jfinancials.beans.BaseFinancialsController;
-import org.mxchange.jfinancials.beans.features.FinancialsFeaturesWebApplicationController;
-import org.mxchange.jfinancials.beans.login.user.FinancialsUserLoginWebSessionController;
-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.UserEmailChangeSessionBeanRemote;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A web session-scoped bean for changing email addresses
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("emailChangeController")
-@SessionScoped
-public class FinancialsEmailChangeWebSessionBean extends BaseFinancialsController implements FinancialsEmailChangeWebSessionController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 186_078_724_659_153L;
-
-       /**
-        * Email address 1 (changing)
-        */
-       private String emailAddress;
-
-       /**
-        * Email address 2 (repeat in changing)
-        */
-       private String emailAddressRepeat;
-
-       /**
-        * Local list of already queued email addresses
-        */
-       private List<String> emailAddresses;
-
-       /**
-        * Remote email change bean
-        */
-       private UserEmailChangeSessionBeanRemote emailChangeBean;
-
-       /**
-        * Features controller
-        */
-       @Inject
-       private FinancialsFeaturesWebApplicationController featureController;
-
-       /**
-        * Login controller (bean)
-        */
-       @Inject
-       private FinancialsUserLoginWebSessionController userLoginController;
-
-       /**
-        * Default constructor
-        */
-       public FinancialsEmailChangeWebSessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public String doUserChangeEmailAddress () {
-               // This method shall only be called if the user is logged-in
-               if (!this.userLoginController.isUserLoggedIn()) {
-                       // Not logged-in
-                       throw new IllegalStateException("User is not logged-in"); //NOI18N
-               } else if (!this.featureController.isFeatureEnabled("user_change_email_address")) { //NOI18N
-                       // Editing is not allowed
-                       throw new IllegalStateException("User tried to change email address"); //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.getEmailAddress(), this.getEmailAddressRepeat())) {
-                       // Email address 1+2 mismatch
-                       this.showFacesMessage("form_user_change_email_address:emailAddressRepeat", "ERROR_USER_EMAIL_ADDRESSES_MISMATCH"); //NOI18N
-                       return ""; //NOI18N
-               } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
-                       // Password not matching
-                       this.showFacesMessage("form_login_user_change_email_address:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
-                       return ""; //NOI18N
-               }
-
-               // Get user instance
-               User user = this.userLoginController.getLoggedInUser();
-
-               // It should be there, so run some tests on it
-               assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N
-               assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N
-               assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
-               assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
-               assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
-               assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
-
-               // Check if the email address is already enqueued
-               if (this.isEmailAddressQueued(this.getEmailAddress())) {
-                       // Clear both email addresses
-                       this.setEmailAddress(null);
-                       this.setEmailAddressRepeat(null);
-
-                       // Yes, then abort here
-                       this.showFacesMessage("form_user_change_email_address:emailAddress", "ERROR_USER_CHANGE_EMAIL_ADDRESS_ALREADY_QUEUED"); //NOI18N
-                       return ""; //NOI18N
-               }
-
-               // Create change object, to save EJB calls, the hash is not generated here
-               ChangeableEmailAddress emailChange = new EmailAddressChange(user, this.getEmailAddress());
-
-               // Get base URL
-               String baseUrl = FacesUtils.generateBaseUrl();
-
-               // Call EJB
-               this.emailChangeBean.enqueueEmailAddressForChange(emailChange, baseUrl);
-
-               // Unset all so the user is forced to re-enter it
-               this.clear();
-
-               // All fine
-               return "user_login_email_change_queued"; //NOI18N
-       }
-
-       @Override
-       public String getEmailAddress () {
-               return this.emailAddress;
-       }
-
-       @Override
-       public void setEmailAddress (final String emailAddress) {
-               this.emailAddress = emailAddress;
-       }
-
-       @Override
-       public String getEmailAddressRepeat () {
-               return this.emailAddressRepeat;
-       }
-
-       @Override
-       public void setEmailAddressRepeat (final String emailAddressRepeat) {
-               this.emailAddressRepeat = emailAddressRepeat;
-       }
-
-       /**
-        * Post-construction
-        */
-       @PostConstruct
-       public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.emailChangeBean = (UserEmailChangeSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/userEmailChange!org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-
-               // Init list
-               this.emailAddresses = this.emailChangeBean.allQueuedAddresses();
-       }
-
-       @Override
-       public boolean isRequiredChangeEmailAddressSet () {
-               return ((this.getEmailAddress() != null) &&
-                               (this.getEmailAddressRepeat() != null));
-       }
-
-       /**
-        * Clears email address fields so the user has to re-enter them
-        */
-       private void clear () {
-               // Clear fields
-               this.setEmailAddress(null);
-               this.setEmailAddressRepeat(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 emailAddress 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.emailChangeBean.isEmailAddressEnqueued(emailAddress);
-
-               // Is it there?
-               if (isQueued) {
-                       // Add to list
-                       this.emailAddresses.add(emailAddress);
-               }
-
-               // Return status
-               return isQueued;
-       }
-
-}
diff --git a/src/java/org/mxchange/jfinancials/beans/email_address/FinancialsEmailChangeWebSessionController.java b/src/java/org/mxchange/jfinancials/beans/email_address/FinancialsEmailChangeWebSessionController.java
deleted file mode 100644 (file)
index 4c37276..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jfinancials.beans.email_address;
-
-import java.io.Serializable;
-
-/**
- * An interface for an email change controller
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface FinancialsEmailChangeWebSessionController extends Serializable {
-
-       /**
-        * Getter for email address 1 (changing)
-        * <p>
-        * @return Email address
-        */
-       String getEmailAddress ();
-
-       /**
-        * Setter for email address 1 (changing)
-        * <p>
-        * @param emailAddress Email address 1
-        */
-       void setEmailAddress (final String emailAddress);
-
-       /**
-        * Getter for email address 2 (repeat changing)
-        * <p>
-        * @return Email address 2
-        */
-       String getEmailAddressRepeat ();
-
-       /**
-        * Setter for email address 2 (repeat changing)
-        * <p>
-        * @param emailAddressRepeat Email address 2
-        */
-       void setEmailAddressRepeat (final String emailAddressRepeat);
-
-       /**
-        * 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 doUserChangeEmailAddress ();
-
-}
diff --git a/src/java/org/mxchange/jfinancials/beans/resendlink/FinancialsResendLinkWebSessionBean.java b/src/java/org/mxchange/jfinancials/beans/resendlink/FinancialsResendLinkWebSessionBean.java
deleted file mode 100644 (file)
index ddc5c03..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jfinancials.beans.resendlink;
-
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.inject.Any;
-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.jcoreee.utils.FacesUtils;
-import org.mxchange.jfinancials.beans.BaseFinancialsController;
-import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController;
-import org.mxchange.jfinancials.beans.user.FinancialsUserWebSessionController;
-import org.mxchange.jusercore.events.resendlink.ObservableUserResendLinkAccountEvent;
-import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent;
-import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
-import org.mxchange.jusercore.exceptions.UserStatusLockedException;
-import org.mxchange.jusercore.model.resendlink.ResendLinkSessionBeanRemote;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-
-/**
- * A web session-scoped bean for resending confirmation link
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("resendController")
-@SessionScoped
-public class FinancialsResendLinkWebSessionBean extends BaseFinancialsController implements FinancialsResendLinkWebSessionController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 186_078_724_659_153L;
-
-       /**
-        * Email address
-        */
-       private String emailAddress;
-
-       /**
-        * Localization controller
-        */
-       @Inject
-       private FinancialsLocalizationSessionController localizationController;
-
-       /**
-        * EJB for resending confirmation link
-        */
-       private ResendLinkSessionBeanRemote resendLinkBean;
-
-       /**
-        * Regular user controller
-        */
-       @Inject
-       private FinancialsUserWebSessionController userController;
-
-       /**
-        * Event being fired after confirmation link is being sent
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserResendLinkAccountEvent> userResendLinkEvent;
-
-       /**
-        * Default constructor
-        */
-       public FinancialsResendLinkWebSessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public String doResendLink () {
-               // The email address should not be empty as the JSF validates this
-               if (this.getEmailAddress() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("this.emailAddress is null"); //NOI18N
-               }
-
-               // Init user instance
-               User user;
-
-               try {
-                       // Is the email address really not used?
-                       user = this.userController.lookupUserByEmailAddress(this.getEmailAddress());
-               } catch (final UserEmailAddressNotFoundException ex) {
-                       // Always clear bean
-                       this.clear();
-
-                       // Not found, should not happen as the registered validator should find it
-                       this.showFacesMessage("form_resend_link:", "ERROR_USER_EMAIL_ADDRESS_NOT_FOUND"); //NOI18N
-                       return ""; //NOI18N
-               }
-
-               // Is the user account already confirmed?
-               if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
-                       // Always clear bean
-                       this.clear();
-
-                       // Then abort here
-                       this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_ALREADY_CONFIRMED"); //NOI18N
-                       return ""; //NOI18N
-               } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
-                       // Always clear bean
-                       this.clear();
-
-                       // User account is locked
-                       this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_LOCKED"); //NOI18N
-                       return ""; //NOI18N
-               } else if (user.getUserConfirmKey() == null) {
-                       // Status is UNCONFIRMED but confirmation key is NULL
-                       throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
-               }
-
-               try {
-                       // Get base URL
-                       String baseUrl = FacesUtils.generateBaseUrl();
-
-                       // Call EJB and return redirect target
-                       this.resendLinkBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
-               } catch (final UserNotFoundException ex) {
-                       // User not found
-                       this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_NOT_FOUND"); //NOI18N
-                       return ""; //NOI18N
-               } catch (final UserStatusLockedException | UserStatusConfirmedException ex) {
-                       // Output message, this should not happen as the confirmation key is being removed
-                       this.showFacesMessage("form_resend_link:resendEmailAddress", ex); //NOI18N
-                       return ""; //NOI18N
-               }
-
-               // Fire event
-               this.userResendLinkEvent.fire(new UserResendLinkAccountEvent(user));
-
-               // Clear this bean
-               this.clear();
-
-               // Return redirect target
-               return "user_resend_done"; //NOI18N
-       }
-
-       @Override
-       public String getEmailAddress () {
-               return this.emailAddress;
-       }
-
-       @Override
-       public void setEmailAddress (final String emailAddress) {
-               this.emailAddress = emailAddress;
-       }
-
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.resendLinkBean = (ResendLinkSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/resendLink!org.mxchange.jusercore.model.resendlink.ResendLinkSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-       }
-
-       /**
-        * Clears email address fields so the user has to re-enter them
-        */
-       private void clear () {
-               // Clear fields
-               this.setEmailAddress(null);
-       }
-
-}
diff --git a/src/java/org/mxchange/jfinancials/beans/resendlink/FinancialsResendLinkWebSessionController.java b/src/java/org/mxchange/jfinancials/beans/resendlink/FinancialsResendLinkWebSessionController.java
deleted file mode 100644 (file)
index 844e5ee..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jfinancials.beans.resendlink;
-
-import java.io.Serializable;
-
-/**
- * An interface for an email change controller
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface FinancialsResendLinkWebSessionController extends Serializable {
-
-       /**
-        * Getter for email address 1 (changing)
-        * <p>
-        * @return Email address
-        */
-       String getEmailAddress ();
-
-       /**
-        * Setter for email address 1 (changing)
-        * <p>
-        * @param emailAddress Email address 1
-        */
-       void setEmailAddress (final String emailAddress);
-
-       /**
-        * Resends (new) confirmation link to given email address, if found.
-        * Otherwise an exception is thrown. On success a redirect takes place.
-        * <p>
-        * @return Redirection target
-        */
-       String doResendLink ();
-
-}
diff --git a/src/java/org/mxchange/jfinancials/beans/user/email_address/FinancialsEmailChangeWebSessionBean.java b/src/java/org/mxchange/jfinancials/beans/user/email_address/FinancialsEmailChangeWebSessionBean.java
new file mode 100644 (file)
index 0000000..fc591d5
--- /dev/null
@@ -0,0 +1,244 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.user.email_address;
+
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+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.jcoreee.utils.FacesUtils;
+import org.mxchange.jfinancials.beans.BaseFinancialsController;
+import org.mxchange.jfinancials.beans.features.FinancialsFeaturesWebApplicationController;
+import org.mxchange.jfinancials.beans.login.user.FinancialsUserLoginWebSessionController;
+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.UserEmailChangeSessionBeanRemote;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A web session-scoped bean for changing email addresses
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("emailChangeController")
+@SessionScoped
+public class FinancialsEmailChangeWebSessionBean extends BaseFinancialsController implements FinancialsEmailChangeWebSessionController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 186_078_724_659_153L;
+
+       /**
+        * Email address 1 (changing)
+        */
+       private String emailAddress;
+
+       /**
+        * Email address 2 (repeat in changing)
+        */
+       private String emailAddressRepeat;
+
+       /**
+        * Local list of already queued email addresses
+        */
+       private List<String> emailAddresses;
+
+       /**
+        * Remote email change bean
+        */
+       private UserEmailChangeSessionBeanRemote emailChangeBean;
+
+       /**
+        * Features controller
+        */
+       @Inject
+       private FinancialsFeaturesWebApplicationController featureController;
+
+       /**
+        * Login controller (bean)
+        */
+       @Inject
+       private FinancialsUserLoginWebSessionController userLoginController;
+
+       /**
+        * Default constructor
+        */
+       public FinancialsEmailChangeWebSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public String doUserChangeEmailAddress () {
+               // This method shall only be called if the user is logged-in
+               if (!this.userLoginController.isUserLoggedIn()) {
+                       // Not logged-in
+                       throw new IllegalStateException("User is not logged-in"); //NOI18N
+               } else if (!this.featureController.isFeatureEnabled("user_change_email_address")) { //NOI18N
+                       // Editing is not allowed
+                       throw new IllegalStateException("User tried to change email address"); //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.getEmailAddress(), this.getEmailAddressRepeat())) {
+                       // Email address 1+2 mismatch
+                       this.showFacesMessage("form_user_change_email_address:emailAddressRepeat", "ERROR_USER_EMAIL_ADDRESSES_MISMATCH"); //NOI18N
+                       return ""; //NOI18N
+               } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
+                       // Password not matching
+                       this.showFacesMessage("form_login_user_change_email_address:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Get user instance
+               User user = this.userLoginController.getLoggedInUser();
+
+               // It should be there, so run some tests on it
+               assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N
+               assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N
+               assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
+               assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
+               assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
+               assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
+
+               // Check if the email address is already enqueued
+               if (this.isEmailAddressQueued(this.getEmailAddress())) {
+                       // Clear both email addresses
+                       this.setEmailAddress(null);
+                       this.setEmailAddressRepeat(null);
+
+                       // Yes, then abort here
+                       this.showFacesMessage("form_user_change_email_address:emailAddress", "ERROR_USER_CHANGE_EMAIL_ADDRESS_ALREADY_QUEUED"); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Create change object, to save EJB calls, the hash is not generated here
+               ChangeableEmailAddress emailChange = new EmailAddressChange(user, this.getEmailAddress());
+
+               // Get base URL
+               String baseUrl = FacesUtils.generateBaseUrl();
+
+               // Call EJB
+               this.emailChangeBean.enqueueEmailAddressForChange(emailChange, baseUrl);
+
+               // Unset all so the user is forced to re-enter it
+               this.clear();
+
+               // All fine
+               return "user_login_email_change_queued"; //NOI18N
+       }
+
+       @Override
+       public String getEmailAddress () {
+               return this.emailAddress;
+       }
+
+       @Override
+       public void setEmailAddress (final String emailAddress) {
+               this.emailAddress = emailAddress;
+       }
+
+       @Override
+       public String getEmailAddressRepeat () {
+               return this.emailAddressRepeat;
+       }
+
+       @Override
+       public void setEmailAddressRepeat (final String emailAddressRepeat) {
+               this.emailAddressRepeat = emailAddressRepeat;
+       }
+
+       /**
+        * Post-construction
+        */
+       @PostConstruct
+       public void init () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.emailChangeBean = (UserEmailChangeSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/userEmailChange!org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+
+               // Init list
+               this.emailAddresses = this.emailChangeBean.allQueuedAddresses();
+       }
+
+       @Override
+       public boolean isRequiredChangeEmailAddressSet () {
+               return ((this.getEmailAddress() != null) &&
+                               (this.getEmailAddressRepeat() != null));
+       }
+
+       /**
+        * Clears email address fields so the user has to re-enter them
+        */
+       private void clear () {
+               // Clear fields
+               this.setEmailAddress(null);
+               this.setEmailAddressRepeat(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 emailAddress 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.emailChangeBean.isEmailAddressEnqueued(emailAddress);
+
+               // Is it there?
+               if (isQueued) {
+                       // Add to list
+                       this.emailAddresses.add(emailAddress);
+               }
+
+               // Return status
+               return isQueued;
+       }
+
+}
diff --git a/src/java/org/mxchange/jfinancials/beans/user/email_address/FinancialsEmailChangeWebSessionController.java b/src/java/org/mxchange/jfinancials/beans/user/email_address/FinancialsEmailChangeWebSessionController.java
new file mode 100644 (file)
index 0000000..500570e
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.user.email_address;
+
+import java.io.Serializable;
+
+/**
+ * An interface for an email change controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface FinancialsEmailChangeWebSessionController extends Serializable {
+
+       /**
+        * Getter for email address 1 (changing)
+        * <p>
+        * @return Email address
+        */
+       String getEmailAddress ();
+
+       /**
+        * Setter for email address 1 (changing)
+        * <p>
+        * @param emailAddress Email address 1
+        */
+       void setEmailAddress (final String emailAddress);
+
+       /**
+        * Getter for email address 2 (repeat changing)
+        * <p>
+        * @return Email address 2
+        */
+       String getEmailAddressRepeat ();
+
+       /**
+        * Setter for email address 2 (repeat changing)
+        * <p>
+        * @param emailAddressRepeat Email address 2
+        */
+       void setEmailAddressRepeat (final String emailAddressRepeat);
+
+       /**
+        * 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 doUserChangeEmailAddress ();
+
+}
diff --git a/src/java/org/mxchange/jfinancials/beans/user/resendlink/FinancialsResendLinkWebSessionBean.java b/src/java/org/mxchange/jfinancials/beans/user/resendlink/FinancialsResendLinkWebSessionBean.java
new file mode 100644 (file)
index 0000000..4ba9d5c
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.user.resendlink;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+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.jcoreee.utils.FacesUtils;
+import org.mxchange.jfinancials.beans.BaseFinancialsController;
+import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController;
+import org.mxchange.jfinancials.beans.user.FinancialsUserWebSessionController;
+import org.mxchange.jusercore.events.resendlink.ObservableUserResendLinkAccountEvent;
+import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent;
+import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
+import org.mxchange.jusercore.exceptions.UserStatusLockedException;
+import org.mxchange.jusercore.model.resendlink.ResendLinkSessionBeanRemote;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+
+/**
+ * A web session-scoped bean for resending confirmation link
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("resendController")
+@SessionScoped
+public class FinancialsResendLinkWebSessionBean extends BaseFinancialsController implements FinancialsResendLinkWebSessionController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 186_078_724_659_153L;
+
+       /**
+        * Email address
+        */
+       private String emailAddress;
+
+       /**
+        * Localization controller
+        */
+       @Inject
+       private FinancialsLocalizationSessionController localizationController;
+
+       /**
+        * EJB for resending confirmation link
+        */
+       private ResendLinkSessionBeanRemote resendLinkBean;
+
+       /**
+        * Regular user controller
+        */
+       @Inject
+       private FinancialsUserWebSessionController userController;
+
+       /**
+        * Event being fired after confirmation link is being sent
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserResendLinkAccountEvent> userResendLinkEvent;
+
+       /**
+        * Default constructor
+        */
+       public FinancialsResendLinkWebSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public String doResendLink () {
+               // The email address should not be empty as the JSF validates this
+               if (this.getEmailAddress() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.emailAddress is null"); //NOI18N
+               }
+
+               // Init user instance
+               User user;
+
+               try {
+                       // Is the email address really not used?
+                       user = this.userController.lookupUserByEmailAddress(this.getEmailAddress());
+               } catch (final UserEmailAddressNotFoundException ex) {
+                       // Always clear bean
+                       this.clear();
+
+                       // Not found, should not happen as the registered validator should find it
+                       this.showFacesMessage("form_resend_link:", "ERROR_USER_EMAIL_ADDRESS_NOT_FOUND"); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Is the user account already confirmed?
+               if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
+                       // Always clear bean
+                       this.clear();
+
+                       // Then abort here
+                       this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_ALREADY_CONFIRMED"); //NOI18N
+                       return ""; //NOI18N
+               } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
+                       // Always clear bean
+                       this.clear();
+
+                       // User account is locked
+                       this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_LOCKED"); //NOI18N
+                       return ""; //NOI18N
+               } else if (user.getUserConfirmKey() == null) {
+                       // Status is UNCONFIRMED but confirmation key is NULL
+                       throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
+               }
+
+               try {
+                       // Get base URL
+                       String baseUrl = FacesUtils.generateBaseUrl();
+
+                       // Call EJB and return redirect target
+                       this.resendLinkBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
+               } catch (final UserNotFoundException ex) {
+                       // User not found
+                       this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_NOT_FOUND"); //NOI18N
+                       return ""; //NOI18N
+               } catch (final UserStatusLockedException | UserStatusConfirmedException ex) {
+                       // Output message, this should not happen as the confirmation key is being removed
+                       this.showFacesMessage("form_resend_link:resendEmailAddress", ex); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Fire event
+               this.userResendLinkEvent.fire(new UserResendLinkAccountEvent(user));
+
+               // Clear this bean
+               this.clear();
+
+               // Return redirect target
+               return "user_resend_done"; //NOI18N
+       }
+
+       @Override
+       public String getEmailAddress () {
+               return this.emailAddress;
+       }
+
+       @Override
+       public void setEmailAddress (final String emailAddress) {
+               this.emailAddress = emailAddress;
+       }
+
+       /**
+        * Post-construction method
+        */
+       @PostConstruct
+       public void init () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.resendLinkBean = (ResendLinkSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/resendLink!org.mxchange.jusercore.model.resendlink.ResendLinkSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+       }
+
+       /**
+        * Clears email address fields so the user has to re-enter them
+        */
+       private void clear () {
+               // Clear fields
+               this.setEmailAddress(null);
+       }
+
+}
diff --git a/src/java/org/mxchange/jfinancials/beans/user/resendlink/FinancialsResendLinkWebSessionController.java b/src/java/org/mxchange/jfinancials/beans/user/resendlink/FinancialsResendLinkWebSessionController.java
new file mode 100644 (file)
index 0000000..bfc794c
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.user.resendlink;
+
+import java.io.Serializable;
+
+/**
+ * An interface for an email change controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface FinancialsResendLinkWebSessionController extends Serializable {
+
+       /**
+        * Getter for email address 1 (changing)
+        * <p>
+        * @return Email address
+        */
+       String getEmailAddress ();
+
+       /**
+        * Setter for email address 1 (changing)
+        * <p>
+        * @param emailAddress Email address 1
+        */
+       void setEmailAddress (final String emailAddress);
+
+       /**
+        * Resends (new) confirmation link to given email address, if found.
+        * Otherwise an exception is thrown. On success a redirect takes place.
+        * <p>
+        * @return Redirection target
+        */
+       String doResendLink ();
+
+}