]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
moved all now to proper packages
authorRoland Häder <roland@mxchange.org>
Sat, 8 Jul 2017 19:23:57 +0000 (21:23 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 8 Jul 2017 19:23:57 +0000 (21:23 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
20 files changed:
src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestController.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionController.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionController.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/profile/PizzaUserProfileWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionController.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestController.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebSessionController.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/user/login/PizzaUserLoginWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/user/login/PizzaUserLoginWebSessionController.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/user/resendlink/PizzaResendLinkWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/user/resendlink/PizzaResendLinkWebSessionController.java [new file with mode: 0644]

diff --git a/src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestBean.java
deleted file mode 100644 (file)
index 3f3e555..0000000
+++ /dev/null
@@ -1,222 +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.pizzaapplication.beans.confirmlink;
-
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.RequestScoped;
-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.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
-import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
-import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
-import org.mxchange.jusercore.exceptions.UserStatusLockedException;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
-import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
-
-/**
- * A web request bean for confirmation link handling
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("confirmationLinkController")
-@RequestScoped
-public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController implements PizzaConfirmationLinkWebRequestController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 57_637_182_796_370L;
-
-       /**
-        * Bean helper instance
-        */
-       @Inject
-       private PizzaWebRequestHelperController beanHelper;
-
-       /**
-        * Confirmation key
-        */
-       private String confirmationKey;
-
-       /**
-        * Remote user bean
-        */
-       private UserSessionBeanRemote userBean;
-
-       /**
-        * Event being fired when a user has confirmed the account
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserConfirmedAccountEvent> userConfirmedEvent;
-
-       /**
-        * User controller
-        */
-       @Inject
-       private PizzaUserWebSessionController userController;
-
-       /**
-        * Default constructor
-        */
-       public PizzaConfirmationLinkWebRequestBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public String getConfirmationKey () {
-               return this.confirmationKey;
-       }
-
-       @Override
-       public void setConfirmationKey (final String confirmationKey) {
-               this.confirmationKey = confirmationKey;
-       }
-
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-       }
-
-       @Override
-       public void maybeConfirmUserAccount () {
-               // Is the confirmation key set?
-               if (this.getConfirmationKey() == null) {
-                       // May be null if not set
-                       return;
-               } else if (this.getConfirmationKey().isEmpty()) {
-                       // Is empty string
-                       return;
-               }
-
-               // Now try to find the user in user list, first get the whole list
-               List<User> users = this.userController.allUsers();
-
-               // Get iterator from it
-               Iterator<User> iterator = users.iterator();
-
-               // Init instance
-               User user = null;
-
-               // Then loop through all
-               while (iterator.hasNext()) {
-                       // Get next user
-                       User next = iterator.next();
-
-                       // Same confirmation key?
-                       if (Objects.equals(this.getConfirmationKey(), next.getUserConfirmKey())) {
-                               // Found it, then set it and abort loop
-                               user = next;
-                               break;
-                       }
-               }
-
-               // Is the user instance null?
-               if ((null == user) || (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED)) {
-                       // Then clear this bean and the helper
-                       this.beanHelper.setUser(null);
-               } else {
-                       // Set user ...
-                       this.beanHelper.setUser(user);
-
-                       // ... and copy it to the controller
-                       this.beanHelper.copyUserToController();
-
-                       // Try to confirm it
-                       this.confirmUserAccount();
-               }
-       }
-
-       /**
-        * Tries to confirm the currently set user instance (in helper).
-        */
-       private void confirmUserAccount () {
-               // Get user instance
-               User user = this.beanHelper.getUser();
-
-               // Should be set
-               if (null == user) {
-                       // Throw NPE
-                       throw new NullPointerException("user is null");
-               } else if (user.getUserId() == null) {
-                       // Abort here
-                       throw new NullPointerException("user.userId is null"); //NOI18N
-               } else if (user.getUserId() < 1) {
-                       // Invalid number
-                       throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
-               } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
-                       // Account is already confirmed
-                       throw new FaceletException(new UserStatusConfirmedException(user));
-               } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
-                       // Account is already confirmed
-                       throw new FaceletException(new UserStatusLockedException(user));
-               } else if (user.getUserConfirmKey() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
-               }
-
-               // Updated user instance
-               User updatedUser;
-
-               try {
-                       // Get base URL
-                       String baseUrl = FacesUtils.generateBaseUrl();
-
-                       // Confirm account
-                       updatedUser = this.userBean.confirmAccount(user, baseUrl);
-               } catch (final UserStatusConfirmedException | UserStatusLockedException ex) {
-                       // Something unexpected happened
-                       throw new FaceletException(MessageFormat.format("Cannot confirm user account {0}", user.getUserName()), ex); //NOI18N
-               }
-
-               // Fire event that the user has confirmed account
-               this.userConfirmedEvent.fire(new UserConfirmedAccountEvent(updatedUser));
-
-               // Set it again in helper
-               this.beanHelper.setUser(updatedUser);
-       }
-
-}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestController.java
deleted file mode 100644 (file)
index df617ce..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.pizzaapplication.beans.confirmlink;
-
-import java.io.Serializable;
-
-/**
- * An interface for an email change controller
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface PizzaConfirmationLinkWebRequestController extends Serializable {
-
-       /**
-        * Getter for confirmation key
-        * <p>
-        * @return Confirmation key
-        */
-       String getConfirmationKey ();
-
-       /**
-        * Setter for confirmation key
-        * <p>
-        * @param confirmationKey Confirmation key
-        */
-       void setConfirmationKey (final String confirmationKey);
-
-       /**
-        * Tries to lookup the user by currently set confirmation key and if found
-        * tries to confirm it. If no user is found, the instance beanHelper.user is
-        * set to null. Other methods or JSF pages should then respond on this
-        * accordingly.
-        */
-       void maybeConfirmUserAccount ();
-
-}
index b6d85ef4e9887cd771343768459a563dd092410f..6b4d09ae37acaa83d2e035d4073ff9ebc55ef9c1 100644 (file)
@@ -56,7 +56,7 @@ import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
 
 /**
diff --git a/src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionBean.java
deleted file mode 100644 (file)
index 0f247b7..0000000
+++ /dev/null
@@ -1,238 +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.pizzaapplication.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.jusercore.exceptions.UserPasswordMismatchException;
-import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
-import org.mxchange.jusercore.model.email_address.EmailAddressChange;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController;
-import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
-
-/**
- * A web session-scoped bean for changing email addresses
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("userEmailChangeController")
-@SessionScoped
-public class PizzaEmailChangeWebSessionBean extends BasePizzaController implements PizzaEmailChangeWebSessionController {
-
-       /**
-        * 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 PizzaFeaturesWebApplicationController featureController;
-
-       /**
-        * Login bean (controller)
-        */
-       @Inject
-       private PizzaUserLoginWebSessionController userLoginController;
-
-       /**
-        * Default constructor
-        */
-       public PizzaEmailChangeWebSessionBean () {
-               // 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.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
-                       throw new FaceletException("Email address 1/2 are mismatching."); //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
-               } else if (!this.featureController.isFeatureEnabled("edit_user_data")) { //NOI18N
-                       // Editing is not allowed
-                       throw new IllegalStateException("User tried to edit personal data"); //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())) {
-                       // Yes, then abort here
-                       return "login_email_already_added"; //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 "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/pizzaservice-ejb/email-change!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/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionController.java
deleted file mode 100644 (file)
index 1796a14..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.pizzaapplication.beans.email_address;
-
-import java.io.Serializable;
-
-/**
- * An interface for an email change controller
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface PizzaEmailChangeWebSessionController 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/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionBean.java
deleted file mode 100644 (file)
index e794847..0000000
+++ /dev/null
@@ -1,448 +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.pizzaapplication.beans.login.user;
-
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Any;
-import javax.faces.context.FacesContext;
-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.jusercore.container.login.LoginContainer;
-import org.mxchange.jusercore.container.login.UserLoginContainer;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.jusercore.events.login.UserLoggedInEvent;
-import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent;
-import org.mxchange.jusercore.events.logout.UserLogoutEvent;
-import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
-import org.mxchange.jusercore.exceptions.UserStatusLockedException;
-import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
-import org.mxchange.jusercore.model.login.user.UserLoginSessionBeanRemote;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserUtils;
-import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
-import org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
-
-/**
- * A web bean for user registration
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("userLoginController")
-@SessionScoped
-public class PizzaUserLoginWebSessionBean extends BasePizzaController implements PizzaUserLoginWebSessionController {
-
-       /**
-        * Path name for guest base template
-        */
-       private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest";
-
-       /**
-        * Path name for logged-in user base template
-        */
-       private static final String USER_BASE_TEMPLATE_NAME = "login/user/user";
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 47_828_986_719_691_592L;
-
-       /**
-        * Template type for pages that might be displayed in guest area and login
-        * area.
-        */
-       private String baseTemplatePathName;
-
-       /**
-        * Logged-in user instance
-        */
-       private User loggedInUser;
-
-       /**
-        * Event fired when user has logged in
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserLoggedInEvent> loginEvent;
-
-       /**
-        * User controller
-        */
-       @Inject
-       private PizzaUserWebSessionController userController;
-
-       /**
-        * Current password
-        */
-       private String userCurrentPassword;
-
-       /**
-        * Flag whether the user has logged-in, set only from inside
-        */
-       private boolean userLoggedIn;
-
-       /**
-        * Remote register session-scoped bean
-        */
-       private UserLoginSessionBeanRemote userLoginBean;
-
-       /**
-        * Event fired when user has logged in
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserLoggedInEvent> userLoginEvent;
-
-       /**
-        * Event fired when user has logged out
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserLogoutEvent> userLogoutEvent;
-
-       /**
-        * User's password history
-        */
-       private List<PasswordHistory> userPasswordHistory;
-
-       /**
-        * EJB for user's password history
-        */
-       private UserPasswordHistorySessionBeanRemote userPasswordHistoryBean;
-
-       /**
-        * Default constructor
-        */
-       public PizzaUserLoginWebSessionBean () {
-               // Call super constructor
-               super();
-
-               // Defaul template is guest
-               this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
-       }
-
-       /**
-        * Method being call after user's password has been updated (and history
-        * entry has been created).
-        * <p>
-        * @param event Event being observed
-        */
-       public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
-               // Check parameter
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getPasswordHistory() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.passwordHistory is null"); //NOI18N
-               } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
-                       // ... and again
-                       throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
-               } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
-                       // Invalid value
-                       throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
-               }
-
-               // All fine, so update list
-               this.updatePasswordHistory(event.getPasswordHistory());
-       }
-
-       @Override
-       public String doAdminLogout () {
-               // Is a user logged-in?
-               if (this.isUserLoggedIn()) {
-                       // Call other logout
-                       return this.doUserLogout();
-               }
-
-               // Invalidate session
-               FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
-
-               // Set template type to guest
-               this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N
-
-               // Redirect to index
-               return "index?faces-redirect=true"; //NOI18N
-       }
-
-       @Override
-       public String doUserLogin () {
-               // Get user instance
-               User user = this.userController.createUserLogin();
-
-               // Create login container
-               LoginContainer container = new UserLoginContainer(user, this.userController.getUserPassword());
-
-               try {
-                       // Call bean
-                       User confirmedUser = this.userLoginBean.validateUserAccountStatus(container);
-
-                       // All fine here so set it here
-                       this.setLoggedInUser(confirmedUser);
-
-                       // Retrieve user's password list
-                       this.userPasswordHistory = this.userPasswordHistoryBean.getUserPasswordHistory(confirmedUser);
-
-                       // Set template to "login"
-                       this.setBaseTemplatePathName(USER_BASE_TEMPLATE_NAME); //NOI18N
-
-                       // Fire event away. Keep this last before return statement.
-                       this.userLoginEvent.fire(new UserLoggedInEvent(confirmedUser));
-
-                       // Clear this bean
-                       this.clear();
-
-                       // All fine
-                       return "login_user"; //NOI18N
-               } catch (final UserNotFoundException ex) {
-                       // Show JSF message
-                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND"); //NOI18N
-                       return ""; //NOI18N
-               } catch (final UserStatusLockedException ex) {
-                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED"); //NOI18N
-                       return ""; //NOI18N
-               } catch (final UserStatusUnconfirmedException ex) {
-                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED"); //NOI18N
-                       return ""; //NOI18N
-               } catch (final UserPasswordMismatchException ex) {
-                       // Show JSF message
-                       this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH"); //NOI18N
-                       return ""; //NOI18N
-               }
-       }
-
-       @Override
-       public String doUserLogout () {
-               // Is loggedInUser set?
-               if (this.getLoggedInUser() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("this.loggedInUser is null"); //NOI18N
-               } else if (this.getLoggedInUser().getUserId() == null) {
-                       // Throw again
-                       throw new NullPointerException("this.loggedInUser.userId is null"); //NOI18N
-               } else if (this.getLoggedInUser().getUserId() < 1) {
-                       // Invalid user id
-                       throw new IllegalStateException(MessageFormat.format("this.loggedInUser.userId={0} is not valid.", this.getLoggedInUser().getUserId())); //NOI18N
-               }
-
-               // Fire event
-               this.userLogoutEvent.fire(new UserLogoutEvent(this.getLoggedInUser()));
-
-               // Invalidate session
-               FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
-
-               // Unset any user instances
-               this.setLoggedInUser(null);
-               this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N
-
-               // Redirect to index
-               return "index"; //NOI18N
-       }
-
-       @Override
-       public String getBaseTemplatePathName () {
-               return this.baseTemplatePathName;
-       }
-
-       @Override
-       public void setBaseTemplatePathName (final String baseTemplatePathName) {
-               this.baseTemplatePathName = baseTemplatePathName;
-       }
-
-       @Override
-       public User getLoggedInUser () {
-               return this.loggedInUser;
-       }
-
-       @Override
-       public void setLoggedInUser (final User loggedInUser) {
-               this.loggedInUser = loggedInUser;
-       }
-
-       @Override
-       public String getUserCurrentPassword () {
-               return this.userCurrentPassword;
-       }
-
-       @Override
-       public void setUserCurrentPassword (final String userCurrentPassword) {
-               this.userCurrentPassword = userCurrentPassword;
-       }
-
-       @Override
-       public List<PasswordHistory> getUserPasswordHistory () {
-               return Collections.unmodifiableList(this.userPasswordHistory);
-       }
-
-       @Override
-       public boolean ifCurrentPasswordMatches () {
-               // The current password must be set and not empty
-               if (this.getUserCurrentPassword() == null) {
-                       // Is not set
-                       throw new NullPointerException("this.userCurrentPassword is null"); //NOI18N
-               } else if (this.getUserCurrentPassword().isEmpty()) {
-                       // Is set empty
-                       throw new IllegalStateException("this.userCurrentPassword is empty."); //NOI18N
-               }
-
-               // Create "container"
-               LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getUserCurrentPassword());
-
-               // Now check if it matches
-               return UserUtils.ifPasswordMatches(container, this.getLoggedInUser());
-       }
-
-       @Override
-       public boolean ifUserMustChangePassword () {
-               return ((this.isUserLoggedIn()) && (Objects.equals(this.getLoggedInUser().getUserMustChangePassword(), Boolean.TRUE)));
-       }
-
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userLoginBean = (UserLoginSessionBeanRemote) context.lookup("java:global/jrecruiter-ejb/userLogin!org.mxchange.jusercore.model.login.user.UserLoginSessionBeanRemote"); //NOI18N
-
-                       // Also find this
-                       this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/jrecruiter-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote"); //NOI18N
-
-                       // Defaul template is guest
-                       this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
-               } catch (final NamingException ex) {
-                       // Continue to throw
-                       throw new FaceletException(ex);
-               }
-       }
-
-       @Override
-       public boolean isInvisible () {
-               // Check on login
-               if (!this.isUserLoggedIn()) {
-                       // Not logged in!
-                       throw new IllegalStateException("isInvisible() has been invoked for a guest."); //NOI18N
-               }
-
-               // Check logged-in first, then invisibility
-               return Objects.equals(this.getLoggedInUser().getUserProfileMode(), ProfileMode.INVISIBLE);
-       }
-
-       @Override
-       public boolean isPasswordInHistory (final String userPassword) {
-               // Default is not found
-               boolean isPasswordInHistory = false;
-
-               // Init variables
-               int count = 1;
-               int maxEntries = this.getIntegerContextParameter("max_user_password_history"); //NOI18N
-
-               // Check all passwords
-               for (final PasswordHistory entry : this.getUserPasswordHistory()) {
-                       // Is password the same?
-                       if (UserUtils.ifPasswordMatches(userPassword, entry.getUserPasswordHistoryUser())) {
-                               // Yes, found it
-                               isPasswordInHistory = true;
-                               break;
-                       } else if (count == maxEntries) {
-                               // Maximum reached
-                               break;
-                       }
-
-                       // Count up
-                       count++;
-               }
-
-               // Return status
-               return isPasswordInHistory;
-       }
-
-       @Override
-       public boolean isUserLoggedIn () {
-               // Compare instance
-               this.userLoggedIn = ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED)));
-
-               // Return it
-               return this.userLoggedIn;
-       }
-
-       /**
-        * Clears this bean
-        */
-       private void clear () {
-               // Clear all fields
-               this.setUserCurrentPassword(null);
-       }
-
-       /**
-        * Updates password history by adding given entry to it as long as it is not
-        * there.
-        * <p>
-        * @param passwordHistory Password history entry
-        */
-       private void updatePasswordHistory (final PasswordHistory passwordHistory) {
-               if (null == passwordHistory) {
-                       // Throw NPE
-                       throw new NullPointerException("passwordHistory is null"); //NOI18N
-               } else if (passwordHistory.getUserPasswordHistoryId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("passwordHistory.userPasswordHistoryId is null"); //NOI18N
-               } else if (passwordHistory.getUserPasswordHistoryId() < 1) {
-                       // Invalid id
-                       throw new IllegalArgumentException(MessageFormat.format("passwordHistory.userPasswordHistoryId={0} is not valid.", passwordHistory.getUserPasswordHistoryId())); //NOI18N
-               }
-
-               // Is it there?
-               if (this.userPasswordHistory.contains(passwordHistory)) {
-                       // Excact copy found
-                       return;
-               }
-
-               // Check all entries
-               for (final PasswordHistory entry : this.userPasswordHistory) {
-                       // Is same id number?
-                       if (Objects.equals(entry.getUserPasswordHistoryId(), passwordHistory.getUserPasswordHistoryId())) {
-                               // Found it
-                               return;
-                       }
-               }
-
-               // Not found, so add it
-               this.userPasswordHistory.add(passwordHistory);
-       }
-
-}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/login/user/PizzaUserLoginWebSessionController.java
deleted file mode 100644 (file)
index 7d0afab..0000000
+++ /dev/null
@@ -1,142 +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.pizzaapplication.beans.login.user;
-
-import java.io.Serializable;
-import java.util.List;
-import javax.ejb.Local;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
-
-/**
- * An interface for registration web controllers
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Local
-public interface PizzaUserLoginWebSessionController extends Serializable {
-
-       /**
-        * Checks whether given clear-text password is in user's password history.
-        * <p>
-        * @param userPassword Clear-text password
-        * <p>
-        * @return Whether clear-text password is in user's password history
-        */
-       boolean isPasswordInHistory (final String userPassword);
-
-       /**
-        * Getter for base template type
-        * <p>
-        * @return Template type
-        */
-       String getBaseTemplatePathName ();
-
-       /**
-        * Setter for base template type
-        * <p>
-        * @param baseTemplatePathName Template type
-        */
-       void setBaseTemplatePathName (final String baseTemplatePathName);
-
-       /**
-        * Logout for administrator area. If a logged-in user instance exists, it is
-        * being logged-out, too.
-        * <p>
-        * @return Outcome (should be redirected)
-        */
-       String doAdminLogout ();
-
-       /**
-        * Logins the user, if the account is found, confirmed and unlocked.
-        * <p>
-        * @return Redirect target
-        */
-       String doUserLogin ();
-
-       /**
-        * Logout for current user by invalidating the current session.
-        * <p>
-        * @return Outcome (should be redirected)
-        */
-       String doUserLogout ();
-
-       /**
-        * Getter for logged-in user instance
-        * <p>
-        * @return Logged-in user instance
-        */
-       User getLoggedInUser ();
-
-       /**
-        * Setter for logged-in user instance
-        * <p>
-        * @param loggedInUser Logged-in user instance
-        */
-       void setLoggedInUser (final User loggedInUser);
-
-       /**
-        * Checks whether the user is logged-in
-        * <p>
-        * @return Whether the user is logged-in
-        */
-       boolean isUserLoggedIn ();
-
-       /**
-        * Checks whether the user needs to change password
-        * <p>
-        * @return Whether the user needs to change password
-        */
-       boolean ifUserMustChangePassword ();
-
-       /**
-        * Whether the currently logged-in user is invisible
-        * <p>
-        * @return Whether the currently logged-in user is invisible
-        */
-       boolean isInvisible ();
-
-       /**
-        * Setter for current password (clear text)
-        * <p>
-        * @param userCurrentPassword Current password
-        */
-       void setUserCurrentPassword (final String userCurrentPassword);
-
-       /**
-        * Getter for current password (clear text)
-        * <p>
-        * @return Current password
-        */
-       String getUserCurrentPassword ();
-
-       /**
-        * Checks whether the (previously entered) current password matches with
-        * from the user instance.
-        * <p>
-        * @return If current password matches
-        */
-       boolean ifCurrentPasswordMatches ();
-
-       /**
-        * Getter for user's password history
-        * <p>
-        * @return User's password history
-        */
-       List<PasswordHistory> getUserPasswordHistory ();
-
-}
index ba5b576c21e7f448046c68ba89a1d47459d2a921..fe9f04a7544c6f83c1656cb97be9ba8ac8a82228 100644 (file)
@@ -26,7 +26,7 @@ import org.mxchange.jusercore.exceptions.UserNotFoundException;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
 
 /**
diff --git a/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionBean.java
deleted file mode 100644 (file)
index 7538e39..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.pizzaapplication.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.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.user.User;
-import org.mxchange.jusercore.model.user.resendlink.ResendLinkSessionBeanRemote;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController;
-import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
-
-/**
- * A web session-scoped bean for resending confirmation link
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("userResendConfirmationController")
-@SessionScoped
-public class PizzaResendLinkWebSessionBean extends BasePizzaController implements PizzaResendLinkWebSessionController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 186_078_724_659_153L;
-
-       /**
-        * Email address
-        */
-       private String emailAddress;
-
-       /**
-        * Localization controller
-        */
-       @Inject
-       private PizzaLocalizationSessionController localizationController;
-
-       /**
-        * EJB for resending confirmation link
-        */
-       private ResendLinkSessionBeanRemote resendLinkBean;
-
-       /**
-        * Regular user controller
-        */
-       @Inject
-       private PizzaUserWebSessionController userController;
-
-       /**
-        * Event being fired after confirmation link is being sent
-        */
-       @Inject
-       @Any
-       private Event<ObservableUserResendLinkAccountEvent> userResendLinkEvent;
-
-       /**
-        * Default constructor
-        */
-       public PizzaResendLinkWebSessionBean () {
-               // 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/pizzaservice-ejb/userResendConfirmationLink!org.mxchange.jusercore.model.user.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/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionController.java
deleted file mode 100644 (file)
index 642c564..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.pizzaapplication.beans.resendlink;
-
-import java.io.Serializable;
-
-/**
- * An interface for an email change controller
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface PizzaResendLinkWebSessionController 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 ();
-
-}
index b2554e1f1414f887198d84a96f9516fb79b32883..72287e8a2d7797c3177488690fc1eec02f38c5ca 100644 (file)
@@ -57,7 +57,7 @@ import org.mxchange.pizzaapplication.beans.BasePizzaController;
 import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
 import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController;
 import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController;
-import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
 
 /**
  * A user bean (controller)
diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestBean.java
new file mode 100644 (file)
index 0000000..23edfa6
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * 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.pizzaapplication.beans.user.confirmlink;
+
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.RequestScoped;
+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.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
+import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
+import org.mxchange.jusercore.exceptions.UserStatusLockedException;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
+
+/**
+ * A web request bean for confirmation link handling
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("confirmationLinkController")
+@RequestScoped
+public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController implements PizzaConfirmationLinkWebRequestController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 57_637_182_796_370L;
+
+       /**
+        * Bean helper instance
+        */
+       @Inject
+       private PizzaWebRequestHelperController beanHelper;
+
+       /**
+        * Confirmation key
+        */
+       private String confirmationKey;
+
+       /**
+        * Remote user bean
+        */
+       private UserSessionBeanRemote userBean;
+
+       /**
+        * Event being fired when a user has confirmed the account
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserConfirmedAccountEvent> userConfirmedEvent;
+
+       /**
+        * User controller
+        */
+       @Inject
+       private PizzaUserWebSessionController userController;
+
+       /**
+        * Default constructor
+        */
+       public PizzaConfirmationLinkWebRequestBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public String getConfirmationKey () {
+               return this.confirmationKey;
+       }
+
+       @Override
+       public void setConfirmationKey (final String confirmationKey) {
+               this.confirmationKey = confirmationKey;
+       }
+
+       /**
+        * Post-construction method
+        */
+       @PostConstruct
+       public void init () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+       }
+
+       @Override
+       public void maybeConfirmUserAccount () {
+               // Is the confirmation key set?
+               if (this.getConfirmationKey() == null) {
+                       // May be null if not set
+                       return;
+               } else if (this.getConfirmationKey().isEmpty()) {
+                       // Is empty string
+                       return;
+               }
+
+               // Now try to find the user in user list, first get the whole list
+               List<User> users = this.userController.allUsers();
+
+               // Get iterator from it
+               Iterator<User> iterator = users.iterator();
+
+               // Init instance
+               User user = null;
+
+               // Then loop through all
+               while (iterator.hasNext()) {
+                       // Get next user
+                       User next = iterator.next();
+
+                       // Same confirmation key?
+                       if (Objects.equals(this.getConfirmationKey(), next.getUserConfirmKey())) {
+                               // Found it, then set it and abort loop
+                               user = next;
+                               break;
+                       }
+               }
+
+               // Is the user instance null?
+               if ((null == user) || (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED)) {
+                       // Then clear this bean and the helper
+                       this.beanHelper.setUser(null);
+               } else {
+                       // Set user ...
+                       this.beanHelper.setUser(user);
+
+                       // ... and copy it to the controller
+                       this.beanHelper.copyUserToController();
+
+                       // Try to confirm it
+                       this.confirmUserAccount();
+               }
+       }
+
+       /**
+        * Tries to confirm the currently set user instance (in helper).
+        */
+       private void confirmUserAccount () {
+               // Get user instance
+               User user = this.beanHelper.getUser();
+
+               // Should be set
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null");
+               } else if (user.getUserId() == null) {
+                       // Abort here
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
+               } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
+                       // Account is already confirmed
+                       throw new FaceletException(new UserStatusConfirmedException(user));
+               } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
+                       // Account is already confirmed
+                       throw new FaceletException(new UserStatusLockedException(user));
+               } else if (user.getUserConfirmKey() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
+               }
+
+               // Updated user instance
+               User updatedUser;
+
+               try {
+                       // Get base URL
+                       String baseUrl = FacesUtils.generateBaseUrl();
+
+                       // Confirm account
+                       updatedUser = this.userBean.confirmAccount(user, baseUrl);
+               } catch (final UserStatusConfirmedException | UserStatusLockedException ex) {
+                       // Something unexpected happened
+                       throw new FaceletException(MessageFormat.format("Cannot confirm user account {0}", user.getUserName()), ex); //NOI18N
+               }
+
+               // Fire event that the user has confirmed account
+               this.userConfirmedEvent.fire(new UserConfirmedAccountEvent(updatedUser));
+
+               // Set it again in helper
+               this.beanHelper.setUser(updatedUser);
+       }
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestController.java
new file mode 100644 (file)
index 0000000..c7c2180
--- /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.pizzaapplication.beans.user.confirmlink;
+
+import java.io.Serializable;
+
+/**
+ * An interface for an email change controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface PizzaConfirmationLinkWebRequestController extends Serializable {
+
+       /**
+        * Getter for confirmation key
+        * <p>
+        * @return Confirmation key
+        */
+       String getConfirmationKey ();
+
+       /**
+        * Setter for confirmation key
+        * <p>
+        * @param confirmationKey Confirmation key
+        */
+       void setConfirmationKey (final String confirmationKey);
+
+       /**
+        * Tries to lookup the user by currently set confirmation key and if found
+        * tries to confirm it. If no user is found, the instance beanHelper.user is
+        * set to null. Other methods or JSF pages should then respond on this
+        * accordingly.
+        */
+       void maybeConfirmUserAccount ();
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebSessionBean.java
new file mode 100644 (file)
index 0000000..9bfce6f
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+ * 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.pizzaapplication.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.jusercore.exceptions.UserPasswordMismatchException;
+import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
+import org.mxchange.jusercore.model.email_address.EmailAddressChange;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController;
+import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
+
+/**
+ * A web session-scoped bean for changing email addresses
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("userEmailChangeController")
+@SessionScoped
+public class PizzaEmailChangeWebSessionBean extends BasePizzaController implements PizzaEmailChangeWebSessionController {
+
+       /**
+        * 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 PizzaFeaturesWebApplicationController featureController;
+
+       /**
+        * Login bean (controller)
+        */
+       @Inject
+       private PizzaUserLoginWebSessionController userLoginController;
+
+       /**
+        * Default constructor
+        */
+       public PizzaEmailChangeWebSessionBean () {
+               // 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.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
+                       throw new FaceletException("Email address 1/2 are mismatching."); //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
+               } else if (!this.featureController.isFeatureEnabled("edit_user_data")) { //NOI18N
+                       // Editing is not allowed
+                       throw new IllegalStateException("User tried to edit personal data"); //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())) {
+                       // Yes, then abort here
+                       return "login_email_already_added"; //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 "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/pizzaservice-ejb/email-change!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/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebSessionController.java
new file mode 100644 (file)
index 0000000..2e3ad3a
--- /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.pizzaapplication.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 PizzaEmailChangeWebSessionController 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/pizzaapplication/beans/user/login/PizzaUserLoginWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/login/PizzaUserLoginWebSessionBean.java
new file mode 100644 (file)
index 0000000..81c2800
--- /dev/null
@@ -0,0 +1,448 @@
+/*
+ * 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.pizzaapplication.beans.user.login;
+
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
+import javax.faces.context.FacesContext;
+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.jusercore.container.login.LoginContainer;
+import org.mxchange.jusercore.container.login.UserLoginContainer;
+import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent;
+import org.mxchange.jusercore.events.logout.UserLogoutEvent;
+import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
+import org.mxchange.jusercore.exceptions.UserStatusLockedException;
+import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
+import org.mxchange.jusercore.model.login.user.UserLoginSessionBeanRemote;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserUtils;
+import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
+import org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
+
+/**
+ * A web bean for user registration
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("userLoginController")
+@SessionScoped
+public class PizzaUserLoginWebSessionBean extends BasePizzaController implements PizzaUserLoginWebSessionController {
+
+       /**
+        * Path name for guest base template
+        */
+       private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest";
+
+       /**
+        * Path name for logged-in user base template
+        */
+       private static final String USER_BASE_TEMPLATE_NAME = "login/user/user";
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 47_828_986_719_691_592L;
+
+       /**
+        * Template type for pages that might be displayed in guest area and login
+        * area.
+        */
+       private String baseTemplatePathName;
+
+       /**
+        * Logged-in user instance
+        */
+       private User loggedInUser;
+
+       /**
+        * Event fired when user has logged in
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserLoggedInEvent> loginEvent;
+
+       /**
+        * User controller
+        */
+       @Inject
+       private PizzaUserWebSessionController userController;
+
+       /**
+        * Current password
+        */
+       private String userCurrentPassword;
+
+       /**
+        * Flag whether the user has logged-in, set only from inside
+        */
+       private boolean userLoggedIn;
+
+       /**
+        * Remote register session-scoped bean
+        */
+       private UserLoginSessionBeanRemote userLoginBean;
+
+       /**
+        * Event fired when user has logged in
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserLoggedInEvent> userLoginEvent;
+
+       /**
+        * Event fired when user has logged out
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserLogoutEvent> userLogoutEvent;
+
+       /**
+        * User's password history
+        */
+       private List<PasswordHistory> userPasswordHistory;
+
+       /**
+        * EJB for user's password history
+        */
+       private UserPasswordHistorySessionBeanRemote userPasswordHistoryBean;
+
+       /**
+        * Default constructor
+        */
+       public PizzaUserLoginWebSessionBean () {
+               // Call super constructor
+               super();
+
+               // Defaul template is guest
+               this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
+       }
+
+       /**
+        * Method being call after user's password has been updated (and history
+        * entry has been created).
+        * <p>
+        * @param event Event being observed
+        */
+       public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
+               // Check parameter
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getPasswordHistory() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.passwordHistory is null"); //NOI18N
+               } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
+                       // ... and again
+                       throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
+               } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
+                       // Invalid value
+                       throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
+               }
+
+               // All fine, so update list
+               this.updatePasswordHistory(event.getPasswordHistory());
+       }
+
+       @Override
+       public String doAdminLogout () {
+               // Is a user logged-in?
+               if (this.isUserLoggedIn()) {
+                       // Call other logout
+                       return this.doUserLogout();
+               }
+
+               // Invalidate session
+               FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
+
+               // Set template type to guest
+               this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N
+
+               // Redirect to index
+               return "index?faces-redirect=true"; //NOI18N
+       }
+
+       @Override
+       public String doUserLogin () {
+               // Get user instance
+               User user = this.userController.createUserLogin();
+
+               // Create login container
+               LoginContainer container = new UserLoginContainer(user, this.userController.getUserPassword());
+
+               try {
+                       // Call bean
+                       User confirmedUser = this.userLoginBean.validateUserAccountStatus(container);
+
+                       // All fine here so set it here
+                       this.setLoggedInUser(confirmedUser);
+
+                       // Retrieve user's password list
+                       this.userPasswordHistory = this.userPasswordHistoryBean.getUserPasswordHistory(confirmedUser);
+
+                       // Set template to "login"
+                       this.setBaseTemplatePathName(USER_BASE_TEMPLATE_NAME); //NOI18N
+
+                       // Fire event away. Keep this last before return statement.
+                       this.userLoginEvent.fire(new UserLoggedInEvent(confirmedUser));
+
+                       // Clear this bean
+                       this.clear();
+
+                       // All fine
+                       return "login_user"; //NOI18N
+               } catch (final UserNotFoundException ex) {
+                       // Show JSF message
+                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND"); //NOI18N
+                       return ""; //NOI18N
+               } catch (final UserStatusLockedException ex) {
+                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED"); //NOI18N
+                       return ""; //NOI18N
+               } catch (final UserStatusUnconfirmedException ex) {
+                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED"); //NOI18N
+                       return ""; //NOI18N
+               } catch (final UserPasswordMismatchException ex) {
+                       // Show JSF message
+                       this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH"); //NOI18N
+                       return ""; //NOI18N
+               }
+       }
+
+       @Override
+       public String doUserLogout () {
+               // Is loggedInUser set?
+               if (this.getLoggedInUser() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.loggedInUser is null"); //NOI18N
+               } else if (this.getLoggedInUser().getUserId() == null) {
+                       // Throw again
+                       throw new NullPointerException("this.loggedInUser.userId is null"); //NOI18N
+               } else if (this.getLoggedInUser().getUserId() < 1) {
+                       // Invalid user id
+                       throw new IllegalStateException(MessageFormat.format("this.loggedInUser.userId={0} is not valid.", this.getLoggedInUser().getUserId())); //NOI18N
+               }
+
+               // Fire event
+               this.userLogoutEvent.fire(new UserLogoutEvent(this.getLoggedInUser()));
+
+               // Invalidate session
+               FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
+
+               // Unset any user instances
+               this.setLoggedInUser(null);
+               this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N
+
+               // Redirect to index
+               return "index"; //NOI18N
+       }
+
+       @Override
+       public String getBaseTemplatePathName () {
+               return this.baseTemplatePathName;
+       }
+
+       @Override
+       public void setBaseTemplatePathName (final String baseTemplatePathName) {
+               this.baseTemplatePathName = baseTemplatePathName;
+       }
+
+       @Override
+       public User getLoggedInUser () {
+               return this.loggedInUser;
+       }
+
+       @Override
+       public void setLoggedInUser (final User loggedInUser) {
+               this.loggedInUser = loggedInUser;
+       }
+
+       @Override
+       public String getUserCurrentPassword () {
+               return this.userCurrentPassword;
+       }
+
+       @Override
+       public void setUserCurrentPassword (final String userCurrentPassword) {
+               this.userCurrentPassword = userCurrentPassword;
+       }
+
+       @Override
+       public List<PasswordHistory> getUserPasswordHistory () {
+               return Collections.unmodifiableList(this.userPasswordHistory);
+       }
+
+       @Override
+       public boolean ifCurrentPasswordMatches () {
+               // The current password must be set and not empty
+               if (this.getUserCurrentPassword() == null) {
+                       // Is not set
+                       throw new NullPointerException("this.userCurrentPassword is null"); //NOI18N
+               } else if (this.getUserCurrentPassword().isEmpty()) {
+                       // Is set empty
+                       throw new IllegalStateException("this.userCurrentPassword is empty."); //NOI18N
+               }
+
+               // Create "container"
+               LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getUserCurrentPassword());
+
+               // Now check if it matches
+               return UserUtils.ifPasswordMatches(container, this.getLoggedInUser());
+       }
+
+       @Override
+       public boolean ifUserMustChangePassword () {
+               return ((this.isUserLoggedIn()) && (Objects.equals(this.getLoggedInUser().getUserMustChangePassword(), Boolean.TRUE)));
+       }
+
+       /**
+        * Post-construction method
+        */
+       @PostConstruct
+       public void init () {
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.userLoginBean = (UserLoginSessionBeanRemote) context.lookup("java:global/jrecruiter-ejb/userLogin!org.mxchange.jusercore.model.login.user.UserLoginSessionBeanRemote"); //NOI18N
+
+                       // Also find this
+                       this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/jrecruiter-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote"); //NOI18N
+
+                       // Defaul template is guest
+                       this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
+               } catch (final NamingException ex) {
+                       // Continue to throw
+                       throw new FaceletException(ex);
+               }
+       }
+
+       @Override
+       public boolean isInvisible () {
+               // Check on login
+               if (!this.isUserLoggedIn()) {
+                       // Not logged in!
+                       throw new IllegalStateException("isInvisible() has been invoked for a guest."); //NOI18N
+               }
+
+               // Check logged-in first, then invisibility
+               return Objects.equals(this.getLoggedInUser().getUserProfileMode(), ProfileMode.INVISIBLE);
+       }
+
+       @Override
+       public boolean isPasswordInHistory (final String userPassword) {
+               // Default is not found
+               boolean isPasswordInHistory = false;
+
+               // Init variables
+               int count = 1;
+               int maxEntries = this.getIntegerContextParameter("max_user_password_history"); //NOI18N
+
+               // Check all passwords
+               for (final PasswordHistory entry : this.getUserPasswordHistory()) {
+                       // Is password the same?
+                       if (UserUtils.ifPasswordMatches(userPassword, entry.getUserPasswordHistoryUser())) {
+                               // Yes, found it
+                               isPasswordInHistory = true;
+                               break;
+                       } else if (count == maxEntries) {
+                               // Maximum reached
+                               break;
+                       }
+
+                       // Count up
+                       count++;
+               }
+
+               // Return status
+               return isPasswordInHistory;
+       }
+
+       @Override
+       public boolean isUserLoggedIn () {
+               // Compare instance
+               this.userLoggedIn = ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED)));
+
+               // Return it
+               return this.userLoggedIn;
+       }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all fields
+               this.setUserCurrentPassword(null);
+       }
+
+       /**
+        * Updates password history by adding given entry to it as long as it is not
+        * there.
+        * <p>
+        * @param passwordHistory Password history entry
+        */
+       private void updatePasswordHistory (final PasswordHistory passwordHistory) {
+               if (null == passwordHistory) {
+                       // Throw NPE
+                       throw new NullPointerException("passwordHistory is null"); //NOI18N
+               } else if (passwordHistory.getUserPasswordHistoryId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("passwordHistory.userPasswordHistoryId is null"); //NOI18N
+               } else if (passwordHistory.getUserPasswordHistoryId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("passwordHistory.userPasswordHistoryId={0} is not valid.", passwordHistory.getUserPasswordHistoryId())); //NOI18N
+               }
+
+               // Is it there?
+               if (this.userPasswordHistory.contains(passwordHistory)) {
+                       // Excact copy found
+                       return;
+               }
+
+               // Check all entries
+               for (final PasswordHistory entry : this.userPasswordHistory) {
+                       // Is same id number?
+                       if (Objects.equals(entry.getUserPasswordHistoryId(), passwordHistory.getUserPasswordHistoryId())) {
+                               // Found it
+                               return;
+                       }
+               }
+
+               // Not found, so add it
+               this.userPasswordHistory.add(passwordHistory);
+       }
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/login/PizzaUserLoginWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/user/login/PizzaUserLoginWebSessionController.java
new file mode 100644 (file)
index 0000000..354253b
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * 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.pizzaapplication.beans.user.login;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.ejb.Local;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
+
+/**
+ * An interface for registration web controllers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Local
+public interface PizzaUserLoginWebSessionController extends Serializable {
+
+       /**
+        * Checks whether given clear-text password is in user's password history.
+        * <p>
+        * @param userPassword Clear-text password
+        * <p>
+        * @return Whether clear-text password is in user's password history
+        */
+       boolean isPasswordInHistory (final String userPassword);
+
+       /**
+        * Getter for base template type
+        * <p>
+        * @return Template type
+        */
+       String getBaseTemplatePathName ();
+
+       /**
+        * Setter for base template type
+        * <p>
+        * @param baseTemplatePathName Template type
+        */
+       void setBaseTemplatePathName (final String baseTemplatePathName);
+
+       /**
+        * Logout for administrator area. If a logged-in user instance exists, it is
+        * being logged-out, too.
+        * <p>
+        * @return Outcome (should be redirected)
+        */
+       String doAdminLogout ();
+
+       /**
+        * Logins the user, if the account is found, confirmed and unlocked.
+        * <p>
+        * @return Redirect target
+        */
+       String doUserLogin ();
+
+       /**
+        * Logout for current user by invalidating the current session.
+        * <p>
+        * @return Outcome (should be redirected)
+        */
+       String doUserLogout ();
+
+       /**
+        * Getter for logged-in user instance
+        * <p>
+        * @return Logged-in user instance
+        */
+       User getLoggedInUser ();
+
+       /**
+        * Setter for logged-in user instance
+        * <p>
+        * @param loggedInUser Logged-in user instance
+        */
+       void setLoggedInUser (final User loggedInUser);
+
+       /**
+        * Checks whether the user is logged-in
+        * <p>
+        * @return Whether the user is logged-in
+        */
+       boolean isUserLoggedIn ();
+
+       /**
+        * Checks whether the user needs to change password
+        * <p>
+        * @return Whether the user needs to change password
+        */
+       boolean ifUserMustChangePassword ();
+
+       /**
+        * Whether the currently logged-in user is invisible
+        * <p>
+        * @return Whether the currently logged-in user is invisible
+        */
+       boolean isInvisible ();
+
+       /**
+        * Setter for current password (clear text)
+        * <p>
+        * @param userCurrentPassword Current password
+        */
+       void setUserCurrentPassword (final String userCurrentPassword);
+
+       /**
+        * Getter for current password (clear text)
+        * <p>
+        * @return Current password
+        */
+       String getUserCurrentPassword ();
+
+       /**
+        * Checks whether the (previously entered) current password matches with
+        * from the user instance.
+        * <p>
+        * @return If current password matches
+        */
+       boolean ifCurrentPasswordMatches ();
+
+       /**
+        * Getter for user's password history
+        * <p>
+        * @return User's password history
+        */
+       List<PasswordHistory> getUserPasswordHistory ();
+
+}
index fada0a3771c24fd45395570ee1e97b8b62f82a44..3b02598612aaeb5ea6924b367c3597821685bd4a 100644 (file)
@@ -40,7 +40,7 @@ import org.mxchange.jusercore.model.user.UserUtils;
 import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
 import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController;
-import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
 
 /**
  * A user password (change) bean (controller)
diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/resendlink/PizzaResendLinkWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/resendlink/PizzaResendLinkWebSessionBean.java
new file mode 100644 (file)
index 0000000..0410c91
--- /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.pizzaapplication.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.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.user.User;
+import org.mxchange.jusercore.model.user.resendlink.ResendLinkSessionBeanRemote;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
+
+/**
+ * A web session-scoped bean for resending confirmation link
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("userResendConfirmationController")
+@SessionScoped
+public class PizzaResendLinkWebSessionBean extends BasePizzaController implements PizzaResendLinkWebSessionController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 186_078_724_659_153L;
+
+       /**
+        * Email address
+        */
+       private String emailAddress;
+
+       /**
+        * Localization controller
+        */
+       @Inject
+       private PizzaLocalizationSessionController localizationController;
+
+       /**
+        * EJB for resending confirmation link
+        */
+       private ResendLinkSessionBeanRemote resendLinkBean;
+
+       /**
+        * Regular user controller
+        */
+       @Inject
+       private PizzaUserWebSessionController userController;
+
+       /**
+        * Event being fired after confirmation link is being sent
+        */
+       @Inject
+       @Any
+       private Event<ObservableUserResendLinkAccountEvent> userResendLinkEvent;
+
+       /**
+        * Default constructor
+        */
+       public PizzaResendLinkWebSessionBean () {
+               // 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/pizzaservice-ejb/userResendConfirmationLink!org.mxchange.jusercore.model.user.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/pizzaapplication/beans/user/resendlink/PizzaResendLinkWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/user/resendlink/PizzaResendLinkWebSessionController.java
new file mode 100644 (file)
index 0000000..0b994f5
--- /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.pizzaapplication.beans.user.resendlink;
+
+import java.io.Serializable;
+
+/**
+ * An interface for an email change controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface PizzaResendLinkWebSessionController 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 ();
+
+}