]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java
Please cherry-pick:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / user / PizzaUserWebSessionBean.java
index d1eb853cebff4ff4e2c8f0d64d32ec09fb69d5e9..b2d6c5d3188c9f926f06bdb7d3532026b8bf4a36 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder
+ * 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
@@ -17,7 +17,6 @@
 package org.mxchange.pizzaapplication.beans.user;
 
 import java.text.MessageFormat;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
@@ -26,6 +25,7 @@ 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;
@@ -33,33 +33,40 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
-import org.mxchange.jusercore.events.login.UserLoggedInEvent;
-import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
-import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
-import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
+import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
+import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
+import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
+import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
+import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
 import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
-import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent;
+import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
+import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
+import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
+import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
+import org.mxchange.juserlogincore.login.UserLoginUtils;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
 import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController;
+import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController;
+import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
 
 /**
  * A user bean (controller)
  * <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
  */
 @Named ("userController")
 @SessionScoped
-public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
+public class PizzaUserWebSessionBean extends BasePizzaController implements PizzaUserWebSessionController {
 
        /**
         * Serial number
@@ -73,27 +80,28 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
        private PizzaContactWebSessionController contactController;
 
        /**
-        * Login bean (controller)
+        * Features controller
         */
        @Inject
-       private PizzaUserLoginWebSessionController loginController;
+       private PizzaFeaturesWebApplicationController featureController;
 
        /**
-        * A list of all selectable contacts
+        * Localization controller
         */
-       private List<Contact> selectableContacts;
+       @Inject
+       private PizzaLocalizationSessionController localizationController;
 
        /**
         * Event being fired when user updated personal data
         */
        @Inject
        @Any
-       private Event<UpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
+       private Event<ObservableUpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
 
        /**
         * Remote user bean
         */
-       private final UserSessionBeanRemote userBean;
+       private UserSessionBeanRemote userBean;
 
        /**
         * User id
@@ -106,7 +114,7 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
        private List<User> userList;
 
        /**
-        * Login bean (controller)
+        * Login controller (bean)
         */
        @Inject
        private PizzaUserLoginWebSessionController userLoginController;
@@ -122,12 +130,12 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
        private List<String> userNameList;
 
        /**
-        * User password (unencrypted from web form)
+        * User password (clear-text from web form)
         */
        private String userPassword;
 
        /**
-        * User password repeated (unencrypted from web form)
+        * User password repeated (clear-text from web form)
         */
        private String userPasswordRepeat;
 
@@ -138,6 +146,9 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
 
        /**
         * A list of all public user profiles
+        * <p>
+        * @TODO Hmm, makes that sense? Having visible user list in current
+        * (session-scoped) user's visible user list?
         */
        private List<User> visibleUserList;
 
@@ -145,24 +156,16 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
         * Default constructor
         */
        public PizzaUserWebSessionBean () {
-               // 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);
-               }
+               // Call super constructor
+               super();
        }
 
-       @Override
-       public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
-
+       /**
+        * Event observer for newly added users by administrator
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
                // event should not be null
                if (null == event) {
                        // Throw NPE
@@ -178,24 +181,131 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
                }
 
-               // Add user to local list
-               this.userList.add(event.getAddedUser());
+               // Update user list
+               this.updateList(event.getAddedUser());
 
                // Clear all data
                this.clear();
 
                // Set user id again
                this.setUserId(event.getAddedUser().getUserId());
+       }
 
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
+       /**
+        * Event observer for deleted user accounts (by administrator)
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminDeletedUserEvent (@Observes final ObservableAdminDeletedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getDeletedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.deletedUser is null"); //NOI18N
+               } else if (event.getDeletedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
+               } else if (event.getDeletedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.removeFromList(event.getDeletedUser());
+
+               // Clear all data
+               this.clear();
        }
 
-       @Override
-       public void afterAdminUpdatedUserDataEvent (@Observes final AdminUpdatedUserDataEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N
+       /**
+        * Event observer for linked users with existing contact data
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLinkedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.linkedUser is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
+               }
 
+               // Update user list
+               this.updateList(event.getLinkedUser());
+
+               // Clear all data
+               this.clear();
+
+               // Set user id again
+               this.setUserId(event.getLinkedUser().getUserId());
+       }
+
+       /**
+        * Event observer for locked users
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLockedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.lockedUser is null"); //NOI18N
+               } else if (event.getLockedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
+               } else if (event.getLockedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.updateList(event.getLockedUser());
+       }
+
+       /**
+        * Event observer for unlocked users
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUnlockedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.unlockedUser is null"); //NOI18N
+               } else if (event.getUnlockedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
+               } else if (event.getUnlockedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.updateList(event.getUnlockedUser());
+       }
+
+       /**
+        * Event observer for updated user data by administrator
+        * <p>
+        * @param event Event being updated
+        */
+       public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
                // event should not be null
                if (null == event) {
                        // Throw NPE
@@ -211,21 +321,78 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
                }
 
-               // Update list
+               // Update user list
                this.updateList(event.getUpdatedUser());
 
                // Clear all data
                this.clear();
+       }
 
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
+       /**
+        * Event observer when user confirmed account.
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterUserConfirmedAccountEvent (@Observes final ObservableUserConfirmedAccountEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getConfirmedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.confirmedUser is null"); //NOI18N
+               } else if (event.getConfirmedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
+               } else if (event.getConfirmedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.updateList(event.getConfirmedUser());
        }
 
-       @Override
-       public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
+       /**
+        * Event observer for logged-in user
+        * <p>
+        * @param event Event instance
+        */
+       public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLoggedInUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
+               }
+
+               // "Cache" user instance
+               User loggedInUser = event.getLoggedInUser();
+
+               // Copy all data to this bean
+               this.copyUser(loggedInUser);
+
+               // Is the user visible?
+               if (Objects.equals(loggedInUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
+                       // Yes, then add user
+                       this.visibleUserList.add(loggedInUser);
+               }
+       }
 
+       /**
+        * Event observer for new user registrations
+        * <p>
+        * @param event User registration event
+        */
+       public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
                // event should not be null
                if (null == event) {
                        // Throw NPE
@@ -244,17 +411,14 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                // Get user instance
                User registeredUser = event.getRegisteredUser();
 
-               // Debug message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
-
                // Copy all data from registered->user
                this.copyUser(registeredUser);
 
                // Clear all data
                this.clear();
 
-               // Add user to local list
-               this.userList.add(registeredUser);
+               // Update user list
+               this.updateList(registeredUser);
 
                // Add user name
                this.addUserName(registeredUser);
@@ -267,43 +431,40 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
 
                // Set user id again
                this.setUserId(registeredUser.getUserId());
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
        }
 
-       @Override
-       public void afterUserLogin (final @Observes UserLoggedInEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
-
-               // event should not be null
+       /**
+        * 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.getLoggedInUser() == null) {
+               } else if (event.getPasswordHistory() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
-               } else if (event.getLoggedInUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
-               } else if (event.getLoggedInUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
+                       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
                }
 
-               // Copy all data to this bean
-               this.copyUser(event.getLoggedInUser());
-
-               // Re-initialize list
-               this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
+               // Update user list
+               this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
        }
 
-       @Override
-       public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
+       /**
+        * Listens to fired event when user updated personal data
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterUserUpdatedPersonalDataEvent (@Observes final ObservableUpdatedUserPersonalDataEvent event) {
                // Check parameter
                if (null == event) {
                        // Throw NPE
@@ -319,24 +480,26 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                        throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
                }
 
-               // All fine, so update list
+               // Update user list
                this.updateList(event.getUpdatedUser());
        }
 
        @Override
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
        public List<User> allUsers () {
                // Return it
-               return Collections.unmodifiableList(this.userList);
+               return this.userList;
        }
 
        @Override
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
        public List<User> allVisibleUsers () {
                // Return it
-               return Collections.unmodifiableList(this.visibleUserList);
+               return this.visibleUserList;
        }
 
        @Override
-       public User createUserInstance () {
+       public User createUserInstance (final boolean createContactData) {
                // Trace message
                //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: CALLED!", this.getClass().getSimpleName()));
 
@@ -344,26 +507,45 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
 
                // Create new user instance
-               User localUser = new LoginUser();
+               User user = new LoginUser();
 
-               // Update all data ...
-               localUser.setUserName(this.getUserName());
-               localUser.setUserProfileMode(this.getUserProfileMode());
+               // Is user name required?
+               if (!this.isUserNameRequired()) {
+                       // Generate pseudo-random user name
+                       String randomName = this.userBean.generateRandomUserName();
+
+                       // Set it and inivisible profile
+                       this.setUserName(randomName);
+                       this.setUserProfileMode(ProfileMode.INVISIBLE);
+
+                       // Generate random password
+                       String randomPassword = UserLoginUtils.createRandomPassword(PizzaUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
 
-               // Create contact instance
-               Contact contact = this.contactController.createContactInstance();
+                       // Set random password
+                       this.setUserPassword(randomPassword);
+                       this.setUserPasswordRepeat(randomPassword);
+               }
+
+               // Set user name profile mode and locale
+               user.setUserName(this.getUserName());
+               user.setUserProfileMode(this.getUserProfileMode());
+               user.setUserLocale(this.localizationController.getLocale());
 
-               // Debug message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact));
+               // Is multiple registration page
+               if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N
+                       // Create contact instance
+                       Contact contact = this.contactController.createContactInstance();
 
-               // Set contact in user
-               localUser.setUserContact(contact);
+                       // Debug message
+                       //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact));
+                       // Set contact in user
+                       user.setUserContact(contact);
+               }
 
                // Trace message
                //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: user={1} - EXIT!", this.getClass().getSimpleName(), user));
-
                // Return it
-               return localUser;
+               return user;
        }
 
        @Override
@@ -374,52 +556,54 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                // Is all data set?
                if (this.getUserName() == null) {
                        // Throw NPE
-                       throw new NullPointerException("recruiterName is null"); //NOI18N
+                       throw new NullPointerException("userName is null"); //NOI18N
                } else if (this.getUserName().isEmpty()) {
                        // Is empty
-                       throw new IllegalStateException("recruiterName is empty."); //NOI18N
+                       throw new IllegalStateException("userName is empty."); //NOI18N
                }
 
-               // Create new recruiter instance
-               User recruiter = new LoginUser();
+               // Create new user instance
+               User user = new LoginUser();
 
                // Update all data ...
-               recruiter.setUserName(this.getUserName());
+               user.setUserName(this.getUserName());
 
                // Trace message
-               //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: recruiter={1} - EXIT!", this.getClass().getSimpleName(), recruiter));
-
+               //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: user={1} - EXIT!", this.getClass().getSimpleName(), user));
                // Return the new instance
-               return recruiter;
+               return user;
        }
 
        @Override
        public String doChangePersonalData () {
                // This method shall only be called if the user is logged-in
-               if (!this.loginController.isUserLoggedIn()) {
+               if (!this.userLoginController.isUserLoggedIn()) {
                        // Not logged-in
                        throw new IllegalStateException("User is not logged-in"); //NOI18N
                } else if (!this.isRequiredChangePersonalDataSet()) {
                        // Not all required fields are set
                        throw new FaceletException("Not all required fields are set."); //NOI18N
-               } else if (!this.loginController.ifCurrentPasswordMatches()) {
+               } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
                        // Password not matching
-                       throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
+                       throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
+               } else if (!this.featureController.isFeatureEnabled("change_user_personal_data")) {
+                       // Editing is not allowed
+                       throw new IllegalStateException("User tried to edit personal data."); //NOI18N
                }
 
                // Get user instance
-               User user = this.loginController.getLoggedInUser();
+               User user = this.userLoginController.getLoggedInUser();
 
                // Copy contact data to contact instance
                this.contactController.updateContactDataFromController(user.getUserContact());
 
                // It should be there, so run some tests on it
-               assert (user instanceof User) : "Instance loginController.loggedInUser is null"; //NOI18N
-               assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null"; //NOI18N
-               assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
-               assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N
-               assert (user.getUserContact().getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N
-               assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
+               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
 
                // Update all fields
                user.setUserProfileMode(this.getUserProfileMode());
@@ -428,10 +612,10 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                User updatedUser = this.userBean.updateUserPersonalData(user);
 
                // Fire event
-               this.updatedPersonalDataEvent.fire(new UserUpdatedPersonalDataEvent(updatedUser));
+               this.updatedPersonalDataEvent.fire(new UpdatedUserPersonalDataEvent(updatedUser));
 
                // All fine
-               return "user_data_saved"; //NOI18N
+               return "user_contact_data_saved"; //NOI18N
        }
 
        @Override
@@ -485,8 +669,11 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
        }
 
        @Override
-       public boolean hasUsers () {
-               return (!this.allUsers().isEmpty());
+       public boolean ifBothPasswordsEmptyAllowed () {
+               // Check feature first
+               return ((this.featureController.isFeatureEnabled("allow_user_registration_empty_password")) &&
+                               ((this.getUserPassword() == null) || (this.getUserPassword().isEmpty())) &&
+                               ((this.getUserPasswordRepeat() == null) || (this.getUserPasswordRepeat().isEmpty())));
        }
 
        /**
@@ -494,6 +681,18 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
         */
        @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);
+               }
+
                // Initialize user list
                this.userList = this.userBean.allUsers();
 
@@ -508,40 +707,6 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                        // Initialize user list
                        this.visibleUserList = this.userBean.allPublicUsers();
                }
-
-               // Get all users
-               List<User> allUsers = this.allUsers();
-
-               // Get all contacts
-               List<Contact> allContacts = this.contactBean.getAllContacts();
-
-               // Get iterator
-               Iterator<Contact> iterator = allContacts.iterator();
-
-               // Loop through it
-               while (iterator.hasNext()) {
-                       // Get next element
-                       Contact next = iterator.next();
-
-                       // Get iterator
-                       Iterator<User> userIterator = allUsers.iterator();
-
-                       // Loop through all users
-                       while (userIterator.hasNext()) {
-                               // Get user instance
-                               User nextUser = userIterator.next();
-
-                               // Is contact same?
-                               if (Objects.equals(next, nextUser.getUserContact())) {
-                                       // Found same
-                                       iterator.remove();
-                                       break;
-                               }
-                       }
-               }
-
-               // Set contact list
-               this.selectableContacts = allContacts;
        }
 
        @Override
@@ -581,6 +746,24 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                return isFound;
        }
 
+       @Override
+       public boolean isPublicUserProfileEnabled () {
+               // Get context parameter
+               String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N
+
+               // Is it set?
+               boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
+
+               // This requires user names being enabled, too.
+               if ((isEnabled) && (!this.isUserNameRequired())) {
+                       // Not valid state, users must be able to modify their profile, especially when it is public
+                       throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
+               }
+
+               // Return value
+               return isEnabled;
+       }
+
        @Override
        public boolean isRequiredChangePersonalDataSet () {
                return ((this.getUserProfileMode() != null) &&
@@ -590,11 +773,17 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
 
        @Override
        public boolean isRequiredPersonalDataSet () {
-               return ((this.getUserName() != null) &&
-                               (this.getUserProfileMode() != null) &&
-                               (this.contactController.isRequiredPersonalDataSet()) &&
-                               (this.getUserPassword() != null) &&
-                               (this.getUserPasswordRepeat() != null));
+               if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
+                       // Multiple registration page
+                       return this.contactController.isRequiredPersonalDataSet();
+               } else {
+                       // Single registration page
+                       return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
+                                       (this.getUserProfileMode() != null) &&
+                                       (this.contactController.isRequiredPersonalDataSet()) &&
+                                       (this.getUserPassword() != null) &&
+                                       (this.getUserPasswordRepeat() != null));
+               }
        }
 
        @Override
@@ -612,11 +801,69 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
        }
 
+       @Override
+       public boolean isUserNameRequired () {
+               // Get context parameter
+               String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N
+
+               // Is it set?
+               boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
+
+               // Return value
+               return isRequired;
+       }
+
        @Override
        public boolean isVisibleUserFound () {
                return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
        }
 
+       @Override
+       public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
+               // Parameter must be valid
+               if (null == emailAddress) {
+                       // Throw NPE
+                       throw new NullPointerException("emailAddress is null"); //NOI18N
+               } else if (emailAddress.isEmpty()) {
+                       // Not valid
+                       throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
+               }
+
+               // Init variable
+               User user = null;
+
+               // Try to lookup it in visible user list
+               for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
+                       // Get next user
+                       User next = iterator.next();
+
+                       // Contact should be set
+                       if (next.getUserContact() == null) {
+                               // Contact is null
+                               throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
+                       } else if (next.getUserContact().getContactEmailAddress() == null) {
+                               // Email address should be set
+                               throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N
+                       }
+
+                       // Is the email address found?
+                       if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) {
+                               // Copy to other variable
+                               user = next;
+                               break;
+                       }
+               }
+
+               // Is it still null?
+               if (null == user) {
+                       // Not visible for the current user
+                       throw new UserEmailAddressNotFoundException(emailAddress);
+               }
+
+               // Return it
+               return user;
+       }
+
        @Override
        public User lookupUserById (final Long userId) throws UserNotFoundException {
                // Parameter must be valid
@@ -654,11 +901,6 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                return user;
        }
 
-       @Override
-       public List<Contact> selectableContacts () {
-               return Collections.unmodifiableList(this.selectableContacts);
-       }
-
        /**
         * Adds user's name to bean's internal list. It also updates the public user
         * list if the user has decided to have a public account,
@@ -670,9 +912,6 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                if (this.userNameList.contains(user.getUserName())) {
                        // Abort here
                        throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
-               } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
-                       // Already added
-                       throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
                }
 
                // Add user name
@@ -715,6 +954,32 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                this.setUserProfileMode(user.getUserProfileMode());
        }
 
+       /**
+        * Removes user from all lists
+        * <p>
+        * @param user User to remove
+        */
+       private void removeFromList (final User user) {
+               // The user should be valid
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // ... again NPE
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+               }
+
+               // Remove it from lists
+               this.userList.remove(user);
+               this.visibleUserList.remove(user);
+
+               // Remove name from list
+               this.userNameList.remove(user.getUserName());
+       }
+
        /**
         * Updates list with given user instance
         * <p>
@@ -731,25 +996,34 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController {
                } else if (user.getUserId() < 1) {
                        // Invalid id
                        throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+               } else if (user.getUserContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("user.userContact is null"); //NOI18N
+               } else if (user.getUserContact().getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
+               } else if (user.getUserContact().getContactId() < 1) {
+                       // Throw again ...
+                       throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N
                }
 
-               // Get iterator
+               // Get iterator from list
                Iterator<User> iterator = this.userList.iterator();
 
-               // Look whole list
+               // "Walk" through all entries
                while (iterator.hasNext()) {
                        // Get next element
                        User next = iterator.next();
 
-                       // Is the same user id?
+                       // Is user id number the same?
                        if (Objects.equals(user.getUserId(), next.getUserId())) {
-                               // Found it, so remove it
+                               // Found entry, so remove it and abort
                                this.userList.remove(next);
                                break;
                        }
                }
 
-               // Re-add item
+               // Re-add user
                this.userList.add(user);
        }