]> 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 154e63e5785ea9326a7c6b82793bb380d89e8938..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;
@@ -34,32 +33,36 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
-import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
-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.UserUtils;
 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.features.PizzaFeaturesWebApplicationController;
 import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+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
@@ -70,11 +73,6 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
         */
        private static final long serialVersionUID = 542_145_347_916L;
 
-       /**
-        * Contact EJB
-        */
-       private ContactSessionBeanRemote contactBean;
-
        /**
         * General contact controller
         */
@@ -98,12 +96,12 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
         */
        @Inject
        @Any
-       private Event<UpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
+       private Event<ObservableUpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
 
        /**
         * Remote user bean
         */
-       private final UserSessionBeanRemote userBean;
+       private UserSessionBeanRemote userBean;
 
        /**
         * User id
@@ -116,7 +114,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
        private List<User> userList;
 
        /**
-        * Login bean (controller)
+        * Login controller (bean)
         */
        @Inject
        private PizzaUserLoginWebSessionController userLoginController;
@@ -132,12 +130,12 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
        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;
 
@@ -148,6 +146,9 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
 
        /**
         * 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;
 
@@ -155,27 +156,16 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
         * 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
-
-                       // Try to lookup
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //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
@@ -191,105 +181,159 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                        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
        }
 
-       @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 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.getUpdatedUser() == null) {
+               } else if (event.getDeletedUser() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
-               } else if (event.getUpdatedUser().getUserId() == null) {
+                       throw new NullPointerException("event.deletedUser is null"); //NOI18N
+               } else if (event.getDeletedUser().getUserId() == null) {
                        // userId is null
-                       throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
-               } else if (event.getUpdatedUser().getUserId() < 1) {
+                       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.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
                }
 
-               // Update list
-               this.updateList(event.getUpdatedUser());
+               // Update user list
+               this.removeFromList(event.getDeletedUser());
 
                // Clear all data
                this.clear();
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
        }
 
-       @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 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.getRegisteredUser() == null) {
+               } else if (event.getLinkedUser() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() == null) {
+                       throw new NullPointerException("event.linkedUser is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserId() == null) {
                        // userId is null
-                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() < 1) {
+                       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.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
                }
 
-               // 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);
+               // Update user list
+               this.updateList(event.getLinkedUser());
 
                // Clear all data
                this.clear();
 
-               // Add user to local list
-               this.userList.add(registeredUser);
-
-               // Add user name
-               this.addUserName(registeredUser);
+               // Set user id again
+               this.setUserId(event.getLinkedUser().getUserId());
+       }
 
-               // Is the account public?
-               if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
-                       // Also add it to this list
-                       this.visibleUserList.add(registeredUser);
+       /**
+        * 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
                }
 
-               // Set user id again
-               this.setUserId(registeredUser.getUserId());
+               // Update user list
+               this.updateList(event.getLockedUser());
+       }
 
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
+       /**
+        * 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());
        }
 
-       @Override
-       public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
+       /**
+        * 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
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
+               } else if (event.getUpdatedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
+               } else if (event.getUpdatedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
+               }
 
+               // Update user list
+               this.updateList(event.getUpdatedUser());
+
+               // Clear all data
+               this.clear();
+       }
+
+       /**
+        * 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
@@ -305,31 +349,16 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
                }
 
-               // Get iterator from list
-               Iterator<User> iterator = this.userList.iterator();
-
-               // "Walk" through all entries
-               while (iterator.hasNext()) {
-                       // Get next element
-                       User next = iterator.next();
-
-                       // Is id number the same?
-                       if (Objects.equals(event.getConfirmedUser().getUserId(), next.getUserId())) {
-                               // Found entry, so remove it and abort
-                               this.userList.remove(next);
-                               break;
-                       }
-               }
-
-               // Add contact to list
-               this.userList.add(event.getConfirmedUser());
+               // Update user list
+               this.updateList(event.getConfirmedUser());
        }
 
-       @Override
-       public void afterUserLogin (@Observes final UserLoggedInEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: 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
@@ -345,18 +374,97 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                        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(event.getLoggedInUser());
+               this.copyUser(loggedInUser);
 
-               // Re-initialize list
-               this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
+               // Is the user visible?
+               if (Objects.equals(loggedInUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
+                       // Yes, then add user
+                       this.visibleUserList.add(loggedInUser);
+               }
+       }
 
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
+       /**
+        * 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
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getRegisteredUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+               }
+
+               // Get user instance
+               User registeredUser = event.getRegisteredUser();
+
+               // Copy all data from registered->user
+               this.copyUser(registeredUser);
+
+               // Clear all data
+               this.clear();
+
+               // Update user list
+               this.updateList(registeredUser);
+
+               // Add user name
+               this.addUserName(registeredUser);
+
+               // Is the account public?
+               if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
+                       // Also add it to this list
+                       this.visibleUserList.add(registeredUser);
+               }
+
+               // Set user id again
+               this.setUserId(registeredUser.getUserId());
        }
 
-       @Override
-       public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
+       /**
+        * 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
+               }
+
+               // Update user list
+               this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
+       }
+
+       /**
+        * 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
@@ -372,24 +480,26 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                        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()));
 
@@ -409,17 +519,17 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                        this.setUserProfileMode(ProfileMode.INVISIBLE);
 
                        // Generate random password
-                       String randomPassword = UserUtils.createRandomPassword(PizzaUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
+                       String randomPassword = UserLoginUtils.createRandomPassword(PizzaUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
 
                        // Set random password
                        this.setUserPassword(randomPassword);
                        this.setUserPasswordRepeat(randomPassword);
                }
 
-               // Set local, user name and mode
-               user.setUserLocale(this.localizationController.getLocale());
+               // Set user name profile mode and locale
                user.setUserName(this.getUserName());
                user.setUserProfileMode(this.getUserProfileMode());
+               user.setUserLocale(this.localizationController.getLocale());
 
                // Is multiple registration page
                if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N
@@ -428,14 +538,12 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
 
                        // 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 user;
        }
@@ -448,23 +556,22 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                // 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
@@ -479,9 +586,9 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
                        // Password not matching
                        throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
-               } else if (!this.featureController.isFeatureEnabled("edit_user_data")) {
+               } else if (!this.featureController.isFeatureEnabled("change_user_personal_data")) {
                        // Editing is not allowed
-                       throw new IllegalStateException("User tried to edit personal data"); //NOI18N
+                       throw new IllegalStateException("User tried to edit personal data."); //NOI18N
                }
 
                // Get user instance
@@ -491,12 +598,12 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                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());
@@ -505,10 +612,10 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                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
@@ -562,8 +669,11 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
        }
 
        @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())));
        }
 
        /**
@@ -571,6 +681,18 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
         */
        @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();
 
@@ -693,18 +815,18 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
 
        @Override
        public boolean isVisibleUserFound () {
-               return ((this.visibleUserList instanceof List) && (!this.visibleUserList.isEmpty()));
+               return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
        }
 
        @Override
-       public User lookupUserById (final Long userId) throws UserNotFoundException {
+       public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
                // Parameter must be valid
-               if (null == userId) {
+               if (null == emailAddress) {
                        // Throw NPE
-                       throw new NullPointerException("userId is null"); //NOI18N
-               } else if (userId < 1) {
+                       throw new NullPointerException("emailAddress is null"); //NOI18N
+               } else if (emailAddress.isEmpty()) {
                        // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
+                       throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
                }
 
                // Init variable
@@ -715,8 +837,17 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                        // Get next user
                        User next = iterator.next();
 
-                       // Is the user id found?
-                       if (Objects.equals(next.getUserId(), userId)) {
+                       // 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;
@@ -726,7 +857,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                // Is it still null?
                if (null == user) {
                        // Not visible for the current user
-                       throw new UserNotFoundException(userId);
+                       throw new UserEmailAddressNotFoundException(emailAddress);
                }
 
                // Return it
@@ -734,14 +865,14 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
        }
 
        @Override
-       public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
+       public User lookupUserById (final Long userId) throws UserNotFoundException {
                // Parameter must be valid
-               if (null == emailAddress) {
+               if (null == userId) {
                        // Throw NPE
-                       throw new NullPointerException("emailAddress is null"); //NOI18N
-               } else if (emailAddress.isEmpty()) {
+                       throw new NullPointerException("userId is null"); //NOI18N
+               } else if (userId < 1) {
                        // Not valid
-                       throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
                }
 
                // Init variable
@@ -752,17 +883,8 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                        // 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 //NOI18N
-                       }
-
-                       // Is the email address found?
-                       if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) {
+                       // Is the user id found?
+                       if (Objects.equals(next.getUserId(), userId)) {
                                // Copy to other variable
                                user = next;
                                break;
@@ -772,7 +894,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                // Is it still null?
                if (null == user) {
                        // Not visible for the current user
-                       throw new UserEmailAddressNotFoundException(emailAddress);
+                       throw new UserNotFoundException(userId);
                }
 
                // Return it
@@ -790,9 +912,6 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                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
@@ -835,6 +954,32 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                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>
@@ -851,25 +996,34 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                } 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);
        }