*/
package org.mxchange.addressbook.beans.login;
+import java.text.MessageFormat;
import java.util.Objects;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
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;
}
}
+ @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;
this.loggedInUser = loggedInUser;
}
- @Override
- public String getBaseTemplatePathName () {
- return this.baseTemplatePathName;
- }
-
@Override
public boolean ifCurrentPasswordMatches () {
// The current password must be set and not empty