]> git.mxchange.org Git - jjobs-war.git/commitdiff
Continued with lock/unlock user: (cherry-pick)
authorRoland Häder <roland@mxchange.org>
Thu, 11 Aug 2016 10:48:48 +0000 (12:48 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 19 Aug 2016 20:53:55 +0000 (22:53 +0200)
- fired event after user account is locked/unlocked
- the fired event can later be observed for updating user lists

src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java

index 027f3698e8b6bd6879e70ea2fb8e2f983222cdea..09d3c631bb6302a8fa653ce3738b387d8c430bd6 100644 (file)
@@ -41,6 +41,10 @@ import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.add.AdminUserAddedEvent;
 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
 import org.mxchange.jusercore.events.user.linked.AdminUserLinkedEvent;
+import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
+import org.mxchange.jusercore.events.user.locked.AdminUserLockedEvent;
+import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent;
+import org.mxchange.jusercore.events.user.unlocked.AdminUserUnlockedEvent;
 import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
 import org.mxchange.jusercore.events.user.update.AdminUserDataUpdatedEvent;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
@@ -133,6 +137,13 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
         */
        private String userLockReason;
 
+       /**
+        * Event being fired when an administrator has locked a user
+        */
+       @Inject
+       @Any
+       private Event<AdminLockedUserEvent> userLockedEvent;
+
        /**
         * Flag whether user must change password after login
         */
@@ -153,6 +164,13 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
         */
        private String userPasswordRepeat;
 
+       /**
+        * Event being fired when admin unlocks an account
+        */
+       @Inject
+       @Any
+       private Event<AdminUnlockedUserEvent> userUnlockedEvent;
+
        /**
         * Default constructor
         */
@@ -473,17 +491,26 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
                        throw new IllegalArgumentException("this.userLockReason is empty"); //NOI18N
                }
 
+               // Init updated user instance
+               User updatedUser;
+
                try {
                        // Get base URL
                        String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Call EJB to lock account
-                       this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl);
+                       updatedUser = this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl);
                } catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
                        throw new FaceletException(ex);
                }
 
+               // Fire event
+               this.userLockedEvent.fire(new AdminUserLockedEvent(updatedUser));
+
+               // Clear bean
+               this.clear();
+
                // Should go fine at this point, redirect to user profile
                return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N
        }
@@ -508,17 +535,26 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
                        throw new FaceletException(new UserStatusUnconfirmedException(user));
                }
 
+               // Init updated user instance
+               User updatedUser;
+
                try {
                        // Get base URL
                        String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Call EJB to unlock account
-                       this.adminUserBean.unlockUserAccount(user, baseUrl);
+                       updatedUser = this.adminUserBean.unlockUserAccount(user, baseUrl);
                } catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
                        throw new FaceletException(ex);
                }
 
+               // Fire event
+               this.userUnlockedEvent.fire(new AdminUserUnlockedEvent(updatedUser));
+
+               // Clear bean
+               this.clear();
+
                // Should go fine at this point, redirect to user profile
                return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N
        }