]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Continued with generic logout (please cherry-pick this):
authorRoland Häder <roland@mxchange.org>
Thu, 9 Jun 2016 16:07:17 +0000 (18:07 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 28 Jul 2016 19:33:23 +0000 (21:33 +0200)
- _FOO changed to _LOGOUT
- missing i18n strings set
- added form so the user can still decide to logout or go back
- added observer method afterUserLogout() which clears the localization bean
- added controller method doLogout() which will do the job

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionBean.java
src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionController.java
src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionBean.java
src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionController.java
web/logout.xhtml [deleted file]

index a2a66379d4f4fd4031b4dbb1917b468ba23fc0f2..d399a0784e9ba1b306895d5bad36cf306518640c 100644 (file)
@@ -25,6 +25,7 @@ import javax.faces.context.FacesContext;
 import javax.inject.Named;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent;
 
 /**
  * A session bean for handling localization/internationalization changes. This
@@ -75,6 +76,33 @@ public class AddressbookLocalizationSessionBean extends BaseAddressbookControlle
                //* NOISY-DEBUG: */ System.out.println("LandingLocalizationSessionBean:afterUserLogin - EXIT!"); //NOI18N
        }
 
+       @Override
+       public void afterUserLogout (@Observes final ObserveableUserLogoutEvent event) {
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ReportsLocalizationSessionBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
+
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLoggedOutUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.loggedOutUser is null"); //NOI18N
+               } else if (event.getLoggedOutUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.loggedOutUser.userId is null"); //NOI18N
+               } else if (event.getLoggedOutUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedOutUser(), event.getLoggedOutUser().getUserId())); //NOI18N
+               }
+
+               // Clear this bean as well
+               this.clear();
+
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println("ReportsLocalizationSessionBean:afterUserLogin - EXIT!"); //NOI18N
+       }
+
        @Override
        public String getLanguage () {
                //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AddressbookLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N
@@ -103,7 +131,6 @@ public class AddressbookLocalizationSessionBean extends BaseAddressbookControlle
 
                // Log debug message
                //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AddressbookLocalizationSessionBean::setLanguage: loc={0}", loc)); //NOI18N
-
                // Set it here and in the JSF context
                this.setLocale(loc);
                FacesContext.getCurrentInstance().getViewRoot().setLocale(loc);
@@ -146,7 +173,6 @@ public class AddressbookLocalizationSessionBean extends BaseAddressbookControlle
 
                // Log debug message
                //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AddressbookLocalizationSessionBean::init: loc={0}", loc)); //NOI18N
-
                // Set it here
                this.setLocale(loc);
 
@@ -154,4 +180,13 @@ public class AddressbookLocalizationSessionBean extends BaseAddressbookControlle
                //* NOISY-DEBUG: */ System.out.println("AddressbookLocalizationSessionBean::init: EXIT!"); //NOI18N
        }
 
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all fields
+               this.setLanguage(null);
+               this.setLocale(null);
+       }
+
 }
index 8b5422a21ef2a3474677a4c0a7dbb4ad11d1a0aa..29cc6854d70b301a9664e0b0577471625b5abc93 100644 (file)
@@ -19,6 +19,7 @@ package org.mxchange.addressbook.beans.localization;
 import java.io.Serializable;
 import java.util.Locale;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent;
 
 /**
  * An interface for localization change beans
@@ -34,6 +35,13 @@ public interface AddressbookLocalizationSessionController extends Serializable {
         */
        void afterUserLogin (final UserLoggedInEvent event);
 
+       /**
+        * Event observer for logged-out user
+        * <p>
+        * @param event Event instance
+        */
+       void afterUserLogout (final ObserveableUserLogoutEvent event);
+
        /**
         * Getter for locale
         * <p>
index 6f38d3fb6bbd246e6ba27b817af97f88b3b8f3e4..e4837c424fb04247060bfff39cddfa9534cf2da1 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Objects;
 import javax.enterprise.context.SessionScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.inject.Any;
+import javax.faces.context.FacesContext;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -32,6 +33,8 @@ import org.mxchange.jusercore.container.login.LoginContainer;
 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;
@@ -95,6 +98,20 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
         */
        private boolean userLoggedIn;
 
+       /**
+        * Event fired when user has logged in
+        */
+       @Inject
+       @Any
+       private Event<UserLoggedInEvent> userLoginEvent;
+
+       /**
+        * Event fired when user has logged out
+        */
+       @Inject
+       @Any
+       private Event<ObserveableUserLogoutEvent> userLogoutEvent;
+
        /**
         * Default constructor
         */
@@ -130,7 +147,10 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
                        this.setTemplateType("login"); //NOI18N
 
                        // Fire event away. Keep this last before return statement.
-                       this.loginEvent.fire(new UserLoginEvent(confirmedUser));
+                       this.userLoginEvent.fire(new UserLoginEvent(confirmedUser));
+
+                       // Clear this bean
+                       this.clear();
 
                        // All fine
                        return "login"; //NOI18N
@@ -140,6 +160,26 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
                }
        }
 
+       @Override
+       public void setBaseTemplatePathName (final String baseTemplatePathName) {
+               this.baseTemplatePathName = baseTemplatePathName;
+       }
+
+       @Override
+       public String doUserLogout () {
+               // Fire event
+               this.userLogoutEvent.fire(new UserLogoutEvent(this.getLoggedInUser()));
+
+               // Invalidate session
+               FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
+
+               // Unset any user instances
+               this.setLoggedInUser(null);
+
+               // Redirect to index
+               return "index?faces-redirect=true"; //NOI18N
+       }
+
        @Override
        public String getCurrentPassword () {
                return this.currentPassword;
@@ -219,4 +259,13 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
                // Return it
                return this.userLoggedIn;
        }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all fields
+               this.setCurrentPassword(null);
+       }
+
 }
index 91cc87a5020bff54d0bf68567432684abc67c9f6..63d2aa832520ef30755771d399016270052c3c25 100644 (file)
@@ -62,6 +62,13 @@ public interface AddressbookUserLoginWebSessionController extends Serializable {
         */
        String doUserLogout ();
 
+       /**
+        * Logout for current user by invalidating the current session.
+        * <p>
+        * @return Outcome (should be redirected)
+        */
+       String doLogout ();
+
        /**
         * Getter for logged-in user instance
         * <p>
diff --git a/web/logout.xhtml b/web/logout.xhtml
deleted file mode 100644 (file)
index 98b02eb..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html
-       lang="#{localizationController.language}" xml:lang="#{localizationController.language}"
-       xmlns="http://www.w3.org/1999/xhtml"
-       xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
-       xmlns:h="http://xmlns.jcp.org/jsf/html"
-       xmlns:f="http://xmlns.jcp.org/jsf/core"
-       >
-
-       <ui:composition template="/WEB-INF/templates/guest/guest_base.tpl">
-               <ui:define name="guest_title">#{msg.PAGE_TITLE_INDEX_FOO}</ui:define>
-
-               <ui:define name="content_header">
-                       #{msg.CONTENT_TITLE_INDEX_FOO}
-               </ui:define>
-
-               <ui:define name="content">
-                       Here goes your content.
-               </ui:define>
-       </ui:composition>
-</html>