]> git.mxchange.org Git - addressbook-war.git/commitdiff
Continued with unlocking users: (please cherry-pick)
authorRoland Häder <roland@mxchange.org>
Fri, 5 Aug 2016 14:33:42 +0000 (16:33 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 6 Aug 2016 21:35:07 +0000 (23:35 +0200)
- added controller method unlockUserAccount() which unlocks locked user accounts ... (so?)

src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java

index d572894c444ad368b6a18adb3fae062496c788ba..9cf1a7bc221c0f01c294054c4fa18e04aaee8d5f 100644 (file)
@@ -47,6 +47,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 AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                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
         */
index 33ed3f4e1c07a15d5e865d76aaef9ac105dfb3c2..6146c723f5283af8cffb6f29007bdd3184be5617 100644 (file)
@@ -60,6 +60,16 @@ public interface AddressbookAdminUserWebRequestController extends Serializable {
         */
        String lockUserAccount (final User user);
 
+       /**
+        * Unlocks selected user's account. This method makes sure that the account
+        * is locked.
+        * <p>
+        * @param user User instance to be unlocked
+        * <p>
+        * @return Redirect outcome
+        */
+       String unlockUserAccount (final User user);
+
        /**
         * Getter for user name
         * <p>