From: Roland Haeder Date: Thu, 28 Jul 2016 20:06:29 +0000 (+0200) Subject: re-added doUserLogout() + removed doLogout() as it was to generic X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fde644999cf6a3b6b6792a7826f05a875517b0d0;p=addressbook-war.git re-added doUserLogout() + removed doLogout() as it was to generic --- diff --git a/src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionBean.java index 7cc02845..5caebaea 100644 --- a/src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionBean.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.beans.login; +import java.text.MessageFormat; import java.util.Objects; import javax.enterprise.context.SessionScoped; import javax.enterprise.event.Event; @@ -34,6 +35,7 @@ import org.mxchange.jusercore.container.login.UserLoginContainer; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.login.UserLoginEvent; import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent; +import org.mxchange.jusercore.events.logout.UserLogoutEvent; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.jusercore.exceptions.UserStatusLockedException; @@ -190,6 +192,39 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle } } + @Override + public String doUserLogout () { + // Is loggedInUser set? + if (this.getLoggedInUser() == null) { + // Throw NPE + throw new NullPointerException("this.loggedInUser is null"); //NOI18N + } else if (this.getLoggedInUser().getUserId() == null) { + // Throw again + throw new NullPointerException("this.loggedInUser.userId is null"); //NOI18N + } else if (this.getLoggedInUser().getUserId() < 1) { + // Invalid user id + throw new IllegalStateException(MessageFormat.format("this.loggedInUser.userId={0} is not valid.", this.getLoggedInUser().getUserId())); //NOI18N + } + + // Fire event + this.userLogoutEvent.fire(new UserLogoutEvent(this.getLoggedInUser())); + + // Invalidate session + FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); + + // Unset any user instances + this.setLoggedInUser(null); + this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N + + // Redirect to index + return "index"; //NOI18N + } + + @Override + public String getBaseTemplatePathName () { + return this.baseTemplatePathName; + } + @Override public void setBaseTemplatePathName (final String baseTemplatePathName) { this.baseTemplatePathName = baseTemplatePathName; @@ -215,11 +250,6 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle this.loggedInUser = loggedInUser; } - @Override - public String getBaseTemplatePathName () { - return this.baseTemplatePathName; - } - @Override public boolean ifCurrentPasswordMatches () { // The current password must be set and not empty diff --git a/src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionController.java b/src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionController.java index 25159a2c..a4b7615b 100644 --- a/src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionController.java @@ -62,13 +62,6 @@ public interface AddressbookUserLoginWebSessionController extends Serializable { */ String doUserLogout (); - /** - * Logout for current user by invalidating the current session. - *

- * @return Outcome (should be redirected) - */ - String doLogout (); - /** * Getter for logged-in user instance *