From 3c24c9c45c40fa1a6955fd74a974881ade1237a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 23 May 2016 14:53:02 +0200 Subject: [PATCH] added pre-checks on user account MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../PizzaResendLinkWebSessionBean.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionBean.java index 761f643c..2e345fac 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkWebSessionBean.java @@ -17,9 +17,7 @@ package org.mxchange.pizzaapplication.beans.resendlink; import java.text.MessageFormat; -import java.util.Locale; import javax.enterprise.context.SessionScoped; -import javax.faces.context.FacesContext; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; @@ -28,8 +26,12 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException; +import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; +import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.pizzaapplication.beans.BasePizzaController; +import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController; import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; /** @@ -57,7 +59,13 @@ public class PizzaResendLinkWebSessionBean extends BasePizzaController implement private ResendLinkSessionBeanRemote emailBean; /** - * User controller + * Localization controller + */ + @Inject + private PizzaLocalizationSessionController localizationController; + + /** + * Regular user controller */ @Inject private PizzaUserWebSessionController userController; @@ -98,14 +106,23 @@ public class PizzaResendLinkWebSessionBean extends BasePizzaController implement throw new FaceletException(MessageFormat.format("this.emailAddress={0} should be resolveable into User instance.", this.getEmailAddress()), ex); //NOI18N } - // Get locale from faces context - Locale locale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale(); + // Is the user account already confirmed? + if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) { + // Then abort here + throw new FaceletException(new UserStatusConfirmedException(user)); + } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) { + // User account is locked + throw new FaceletException(new UserStatusLockedException(user)); + } else if (user.getUserConfirmKey() == null) { + // Status is UNCONFIRMED but confirmation key is NULL + throw new NullPointerException("user.userConfirmKey is null"); //NOI18N + } // Get base URL String baseUrl = FacesUtils.generateBaseUrl(); // Call EJB and return redirect target - this.emailBean.resendConfirmationLink(user, locale, baseUrl); + this.emailBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl); // Clear this bean this.clear(); -- 2.39.5