From: Roland Häder Date: Thu, 11 Aug 2016 10:48:48 +0000 (+0200) Subject: Continued with lock/unlock user: (cherry-pick) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=84f0e3d23d9009c069ed2f5007c9a1253c91bd1f;p=jjobs-war.git Continued with lock/unlock user: (cherry-pick) - fired event after user account is locked/unlocked - the fired event can later be observed for updating user lists --- diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java index 027f3698..09d3c631 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java @@ -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 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 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 }