]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java
updated JNDI names
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / user / password / PizzaUserPasswordWebRequestBean.java
index a70843aa000605a30b068ddeb55e4230e14ed341..fada0a3771c24fd45395570ee1e97b8b62f82a44 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,6 +17,7 @@
 package org.mxchange.pizzaapplication.beans.user.password;
 
 import java.util.Objects;
+import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.inject.Any;
@@ -26,8 +27,9 @@ import javax.inject.Named;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import org.mxchange.jcoreee.utils.FacesUtils;
+import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
 import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
-import org.mxchange.jusercore.events.user.password_change.UserUpdatedPasswordEvent;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
@@ -38,12 +40,12 @@ import org.mxchange.jusercore.model.user.UserUtils;
 import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
 import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.login.user.PizzaUserLoginWebSessionController;
 
 /**
  * A user password (change) bean (controller)
  * <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
  */
 @Named ("userPasswordController")
 @RequestScoped
@@ -63,7 +65,7 @@ public class PizzaUserPasswordWebRequestBean extends BasePizzaController impleme
        /**
         * Remote user bean
         */
-       private final UserSessionBeanRemote userBean;
+       private UserSessionBeanRemote userBean;
 
        /**
         * Current password (for confirmation of password change)
@@ -77,12 +79,12 @@ public class PizzaUserPasswordWebRequestBean extends BasePizzaController impleme
        private PizzaUserLoginWebSessionController userLoginController;
 
        /**
-        * 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;
 
@@ -91,23 +93,14 @@ public class PizzaUserPasswordWebRequestBean extends BasePizzaController impleme
         */
        @Any
        @Inject
-       private Event<UpdatedUserPasswordEvent> userUpdatedPasswordEvent;
+       private Event<ObservableUpdatedUserPasswordEvent> userUpdatedPasswordEvent;
 
        /**
         * Default constructor
         */
        public PizzaUserPasswordWebRequestBean () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
+               // Call super constructor
+               super();
        }
 
        @Override
@@ -173,11 +166,14 @@ public class PizzaUserPasswordWebRequestBean extends BasePizzaController impleme
                user.setUserEncryptedPassword(encryptedPassword);
 
                try {
+                       // Get base URL
+                       String baseUrl = FacesUtils.generateBaseUrl();
+
                        // All is set, then update password
-                       PasswordHistory passwordHistory = this.userBean.updateUserPassword(user);
+                       PasswordHistory passwordHistory = this.userBean.updateUserPassword(user, baseUrl);
 
                        // Fire event
-                       this.userUpdatedPasswordEvent.fire(new UserUpdatedPasswordEvent(passwordHistory));
+                       this.userUpdatedPasswordEvent.fire(new UpdatedUserPasswordEvent(passwordHistory));
                } catch (final UserNotFoundException | UserStatusUnconfirmedException | UserStatusLockedException ex) {
                        // Clear bean
                        this.clear();
@@ -223,6 +219,25 @@ public class PizzaUserPasswordWebRequestBean extends BasePizzaController impleme
                this.userPasswordRepeat = userPasswordRepeat;
        }
 
+       /**
+        * Post-initialization of this class
+        */
+       @PostConstruct
+       public void init () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+       }
+
+       @Override
        public boolean isRequiredChangePasswordSet () {
                // Is all data set?
                return ((this.getUserCurrentPassword() != null) &&