X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fpizzaapplication%2Fbeans%2Fuser%2Fpassword%2FPizzaUserPasswordWebRequestBean.java;h=fada0a3771c24fd45395570ee1e97b8b62f82a44;hb=7f0541570bda07790dcddb59eb93c84d82d793a9;hp=a70843aa000605a30b068ddeb55e4230e14ed341;hpb=ed3bc4b102f713aba4b0f868b4d95f7b58ab6953;p=pizzaservice-war.git diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java index a70843aa..fada0a37 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java @@ -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) *

- * @author Roland Haeder + * @author Roland Häder */ @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 userUpdatedPasswordEvent; + private Event 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) &&