From 2a469a22dca97b2f6c4d823f7913eb6a204406d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 5 Aug 2016 16:33:42 +0200 Subject: [PATCH] Continued with unlocking users: (please cherry-pick) - added controller method unlockUserAccount() which unlocks locked user accounts ... (so?) --- .../user/PizzaAdminUserWebRequestBean.java | 36 +++++++++++++++++++ .../PizzaAdminUserWebRequestController.java | 10 ++++++ 2 files changed, 46 insertions(+) diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java index 3c00e1e2..c600125d 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java @@ -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; @@ -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 */ diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java index 045f8b1d..59887386 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java @@ -60,6 +60,16 @@ public interface PizzaAdminUserWebRequestController extends Serializable { */ String lockUserAccount (final User user); + /** + * Unlocks selected user's account. This method makes sure that the account + * is locked. + *

+ * @param user User instance to be unlocked + *

+ * @return Redirect outcome + */ + String unlockUserAccount (final User user); + /** * Getter for user name *

-- 2.39.5