import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController;
import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
import org.mxchange.jjobs.beans.helper.JobsWebViewHelperController;
+import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
import org.mxchange.jusercore.container.login.UserLoginContainer;
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
import org.mxchange.jusercore.events.user.add.AdminUserAddedEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminUserDeletedEvent;
import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
import org.mxchange.jusercore.events.user.linked.AdminUserLinkedEvent;
import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
@Inject
private JobsContactWebSessionController contactController;
+ /**
+ * Event being fired when admin has deleted user
+ */
+ @Inject
+ @Any
+ private Event<AdminDeletedUserEvent> deleteUserEvent;
+
+ /**
+ * Localization controller
+ */
+ @Inject
+ private JobsLocalizationSessionController localizationController;
+
/**
* An event fired when the administrator has updated a new user
*/
@Inject
private JobsUserWebSessionController userController;
+ /**
+ * Delete reason
+ */
+ private String userDeleteReason;
+
/**
* An event fired when the administrator has linked a user with existing
* contact data.
//* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
}
+ @Override
+ public String deleteUserData (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
+ }
+
+ try {
+ // All fine, delete it
+ this.adminUserBean.deleteUser(user, this.getUserDeleteReason());
+ } catch (final UserNotFoundException ex) {
+ // Should not happen, so throw again
+ throw new FaceletException(ex);
+ }
+
+ // Fire event
+ this.deleteUserEvent.fire(new AdminUserDeletedEvent(user, this.getUserDeleteReason()));
+
+ // Redirect
+ return "admin_list_user"; //NOI18N
+ }
+
@Override
public String editUserData () {
// Get user instance
return "admin_list_user"; //NOI18N
}
+ @Override
+ public String getUserDeleteReason () {
+ return this.userDeleteReason;
+ }
+
+ @Override
+ public void setUserDeleteReason (final String userDeleteReason) {
+ this.userDeleteReason = userDeleteReason;
+ }
+
@Override
public String getUserLockReason () {
return this.userLockReason;
*/
String addUser ();
+ /**
+ * Deletes given user account
+ * <p>
+ * @param user User instance to delete
+ * <p>
+ * @return Redirect outcome
+ */
+ String deleteUserData (final User user);
+
/**
* Edits cuirrently loaded user's data in database.
* <p>
*/
void setUserLockReason (final String userLockReason);
+ /**
+ * Getter for user delete reason
+ * <p>
+ * @return User delete reason
+ */
+ String getUserDeleteReason ();
+
+ /**
+ * Setter for user delete reason
+ * <p>
+ * @param userDeleteReason User delete reason
+ */
+ void setUserDeleteReason (final String userDeleteReason);
+
}
import org.mxchange.jusercore.events.login.UserLoggedInEvent;
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
this.setUserId(event.getAddedUser().getUserId());
}
+ @Override
+ public void afterAdminDeletedUserEvent (final AdminDeletedUserEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getDeletedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedUser is null"); //NOI18N
+ } else if (event.getDeletedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
+ } else if (event.getDeletedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.removeFromList(event.getDeletedUser());
+
+ // Clear all data
+ this.clear();
+ }
+
@Override
public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) {
// event should not be null
this.clear();
}
- @Override
- public void afterUserRegistrationEvent (@Observes final UserRegisteredEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getRegisteredUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.registeredUser is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
- }
-
- // Get user instance
- User registeredUser = event.getRegisteredUser();
-
- // Copy all data from registered->user
- this.copyUser(registeredUser);
-
- // Clear all data
- this.clear();
-
- // Update user list
- this.updateList(registeredUser);
-
- // Add user name
- this.addUserName(registeredUser);
-
- // Is the account public?
- if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
- // Also add it to this list
- this.visibleUserList.add(registeredUser);
- }
-
- // Set user id again
- this.setUserId(registeredUser.getUserId());
- }
-
@Override
public void afterUserConfirmedAccountEvent (@Observes final UserConfirmedAccountEvent event) {
// event should not be null
}
}
+ @Override
+ public void afterUserRegistrationEvent (@Observes final UserRegisteredEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getRegisteredUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.registeredUser is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+ }
+
+ // Get user instance
+ User registeredUser = event.getRegisteredUser();
+
+ // Copy all data from registered->user
+ this.copyUser(registeredUser);
+
+ // Clear all data
+ this.clear();
+
+ // Update user list
+ this.updateList(registeredUser);
+
+ // Add user name
+ this.addUserName(registeredUser);
+
+ // Is the account public?
+ if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
+ // Also add it to this list
+ this.visibleUserList.add(registeredUser);
+ }
+
+ // Set user id again
+ this.setUserId(registeredUser.getUserId());
+ }
+
@Override
public void afterUserUpdatedPasswordEvent (@Observes final UpdatedUserPasswordEvent event) {
// Check parameter
this.setUserProfileMode(user.getUserProfileMode());
}
+ /**
+ * Removes user from all lists
+ * <p>
+ * @param user User to remove
+ */
+ private void removeFromList (final User user) {
+ // The user should be valid
+ if (null == user) {
+ // Throw NPE
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // ... again NPE
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+ }
+
+ // Remove it from lists
+ this.userList.remove(user);
+ this.visibleUserList.remove(user);
+
+ // Remove name from list
+ this.userNameList.remove(user.getUserName());
+ }
+
/**
* Updates list with given user instance
* <p>
import org.mxchange.jusercore.events.login.UserLoggedInEvent;
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
*/
void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
+ /**
+ * Event observer for deleted user accounts (by administrator)
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminDeletedUserEvent (final AdminDeletedUserEvent event);
+
/**
* Event observer for linked users with existing contact data
* <p>
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
this.addUserActivity(event.getAddedUser(), "ADMIN_ADDED_USER_ACCOUNT"); //NOI18N
}
+ @Override
+ public void afterAdminDeletedUserEvent (@Observes final AdminDeletedUserEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getDeletedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedUser is null"); //NOI18N
+ } else if (event.getDeletedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
+ } else if (event.getDeletedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
+ }
+
+ // Add acitivity
+ this.addUserActivity(event.getDeletedUser(), "ADMIN_DELETED_USER_ACCOUNT", event.getUserDeleteReason()); //NOI18N
+ }
+
@Override
public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) {
// event should not be null
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
*/
void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
+ /**
+ * Event observer for deleted user accounts (by administrator)
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminDeletedUserEvent (final AdminDeletedUserEvent event);
+
/**
* Event observer for linked users with existing contact data
* <p>
USER_ACTIVITY_USER_LOGGED_OUT=Sie haben sich ausgeloggt.
ERROR_GUEST_USER_NAME_REQUIRED_DISABLED=Fehler: Die Anwendung verwendet keine Benutzernamen, dennoch wurde dieses Template geladen.
ADMIN_SHOW_PRINCIPAL_NAME=Admin-Login:
+ADMIN_LINK_SHOW_USER_ACTIVITY_LOG_TITLE=Listet Aktivit\u00e4tslogbuch des Benutzers auf.
+ADMIN_DELETE_USER_TITLE=Wollen Sie den Benutzer {0} (Id-Nummer {1}) wirklich l\u00f6schen?
+BUTTON_ADMIN_DELETE_USER=Benutzeraccount l\u00f6schen
+ADMIN_DELETE_USER_NOTICE=Durch das L\u00f6schen des Benutzeraccounts werden nur die Benutzerdaten, jedoch nicht Kontaktdaten.
+ADMIN_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=Benutzeraccount gel\u00f6scht vom Administrator.
+USER_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=Ihr Benutzeraccount wurde von einem Administrator gel\u00f6scht.
USER_ACTIVITY_USER_LOGGED_OUT=You have logged out.
ERROR_GUEST_USER_NAME_REQUIRED_DISABLED=Error: This application requires no user name, still this template has been loaded.
ADMIN_SHOW_PRINCIPAL_NAME=Admin-Login:
+ADMIN_LINK_SHOW_USER_ACTIVITY_LOG_TITLE=Lists all user's activity.
+ADMIN_DELETE_USER_TITLE=Do you really want to delete user account {0} (id number {1})?
+BUTTON_ADMIN_DELETE_USER=Delete user account
+ADMIN_DELETE_USER_NOTICE=By deleting the user's account, only user data is deleted but not contact data.
+ADMIN_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=User account has been deleted by administrator.
+USER_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=Your account has been deleted by an administrator.
</ui:include>
</ui:fragment>
- Here goes your content.
+ <h:form id="form_admin_delete_user" rendered="#{not empty beanHelper.user}">
+ <h:panelGroup styleClass="table" layout="block">
+ <div class="table_header">
+ <h:outputFormat value="#{msg.ADMIN_DELETE_USER_TITLE}">
+ <f:param value="#{beanHelper.user.userName}" />
+ <f:param value="#{beanHelper.user.userId}" />
+ </h:outputFormat>
+ </div>
+
+ <div class="para notice">
+ <h:outputFormat value="#{msg.ADMIN_DELETE_USER_NOTICE}" />
+ </div>
+
+ <ui:include src="/WEB-INF/templates/admin/user/admin_show_user_data_mini.tpl" />
+
+ <div class="table_row">
+ <div class="table_left_medium">
+ <h:outputLabel for="userDeleteReason" value="#{msg.ADMIN_USER_DELETE_REASON}" />
+ </div>
+
+ <div class="table_right_medium">
+ <h:inputTextarea id="userDeleteReason" styleClass="input" value="#{adminUserController.userDeleteReason}" rows="7" cols="25" />
+ </div>
+
+ <div class="clear"></div>
+ </div>
+
+ <div class="table_footer">
+ <h:commandButton styleClass="reset right_space" type="reset" value="#{msg.BUTTON_RESET_FORM}" />
+ <h:commandButton styleClass="delete_button" type="submit" id="delete_user" value="#{msg.BUTTON_ADMIN_DELETE_USER}" action="#{adminUserController.deleteUserData(beanHelper.user)}" />
+ </div>
+ </h:panelGroup>
+ </h:form>
</ui:define>
</ui:composition>
</html>