X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjava%2Forg%2Fmxchange%2Fpizzaapplication%2Fbeans%2Fuser%2FPizzaAdminUserWebRequestBean.java;h=f27c950b3a85424f7d3a4fc3a9f5b13e1ca4cc20;hb=fea403ed5c05f960a2d17fd4c8f4ca639c46cbb2;hp=3c00e1e202c27adb6f7258ed4544ca4f346e6138;hpb=f492eebe89cdf2f70f5ebd8ac91642b7e7d91a89;p=pizzaservice-war.git diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java index 3c00e1e2..f27c950b 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Roland Haeder + * Copyright (C) 2016 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 @@ -43,6 +43,7 @@ import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserPasswordRepeatMismatchException; +import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; import org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote; @@ -60,7 +61,7 @@ import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController; /** * Administrative user bean (controller) *

- * @author Roland Haeder + * @author Roland Häder */ @Named ("adminUserController") @RequestScoped @@ -163,7 +164,7 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements // Try to lookup this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N - this.adminUserBean = (AdminUserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote"); //NOI18N + this.adminUserBean = (AdminUserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); @@ -485,6 +486,41 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N } + @Override + public String unlockUserAccount (final User user) { + // Is the user instance valid and CONFIRMED? + if (null == user) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + // Throw again + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N + } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) { + // User account is locked + throw new FacesException(new UserStatusConfirmedException(user)); + } else if (user.getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) { + // User account is locked + throw new FaceletException(new UserStatusUnconfirmedException(user)); + } + + try { + // Get base URL + String baseUrl = FacesUtils.generateBaseUrl(); + + // Call EJB to unlock account + this.adminUserBean.unlockUserAccount(user, baseUrl); + } catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) { + // Throw again + throw new FaceletException(ex); + } + + // Should go fine at this point, redirect to user profile + return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N + } + /** * Clears this bean */