]> git.mxchange.org Git - pizzaservice-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:14:55 +0000 (21:14 +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/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionController.java
src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java
web/logout.xhtml

index 587435aa3ac0bd067cf5f94a2eea80b444e49dfc..4afeee99e3312400ff7b393c0f2dfa11c5334684 100644 (file)
@@ -24,6 +24,7 @@ import javax.enterprise.event.Observes;
 import javax.faces.context.FacesContext;
 import javax.inject.Named;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
 
 /**
@@ -75,6 +76,33 @@ public class PizzaLocalizationSessionBean extends BasePizzaController implements
                //* 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("PizzaLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N
@@ -154,4 +182,13 @@ public class PizzaLocalizationSessionBean extends BasePizzaController implements
                //* NOISY-DEBUG: */ System.out.println("PizzaLocalizationSessionBean::init: EXIT!"); //NOI18N
        }
 
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all fields
+               this.setLanguage(null);
+               this.setLocale(null);
+       }
+
 }
index 7dbb017eb4f52d37252f6b6e68d4360187efd30d..24bd56cb20278ced455ec3d26b29ac1952925bd2 100644 (file)
@@ -19,6 +19,7 @@ package org.mxchange.pizzaapplication.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 PizzaLocalizationSessionController 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 f3df1d725b81d1a1f041e4ed64f107b114d4290e..cfe2d7da45bd7232a66b1be51cfc6c0b0db3bd1f 100644 (file)
@@ -31,6 +31,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;
@@ -106,6 +108,20 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements
         */
        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
         */
@@ -162,7 +178,10 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements
                        this.setBaseTemplatePathName(USER_BASE_TEMPLATE_NAME); //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
@@ -177,6 +196,21 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements
                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;
@@ -240,4 +274,13 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements
                // Return it
                return this.userLoggedIn;
        }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all fields
+               this.setCurrentPassword(null);
+       }
+
 }
index 6164051a9a07d52b3bebc16bf6314f8d54260802..f5a841f4fc1358b87bb7b0eddb4f82abbfb695e2 100644 (file)
@@ -47,6 +47,13 @@ public interface PizzaUserLoginWebSessionController extends Serializable {
         */
        String doLogin ();
 
+       /**
+        * Logout for current user by invalidating the current session.
+        * <p>
+        * @return Outcome (should be redirected)
+        */
+       String doLogout ();
+
        /**
         * Getter for logged-in user instance
         * <p>
index 0c4010dc147357f9c533c3d73eb90cefe4a83ef4..6f73ddbbc3dded57be9f4f792c85197c32309fb4 100644 (file)
@@ -8,14 +8,30 @@
        >
 
        <ui:composition template="/WEB-INF/templates/guest/guest_base.tpl">
-               <ui:define name="guest_title">Sitzung beenden</ui:define>
+               <ui:define name="guest_title">#{msg.PAGE_TITLE_INDEX_LOGOUT}</ui:define>
 
                <ui:define name="content_header">
-                       Sitzung beenden
+                       #{msg.CONTENT_TITLE_INDEX_LOGOUT}
                </ui:define>
 
                <ui:define name="content">
-                       Offenes TODO!
+                       <!--  rendered="#{userLoginController.isUserLoggedIn()}" //-->
+                       <h:form id="logout">
+                               <div class="table">
+                                       <div class="table_header">
+                                               <h:outputText value="#{msg.LOGIN_USER_LOGOUT_TITLE}" />
+                                       </div>
+
+                                       <div class="para">
+                                               <h:outputText value="#{msg.LOGIN_USER_LOGOUT_NOTICE}" />
+                                       </div>
+
+                                       <div class="table_footer">
+                                               <h:commandButton styleClass="reset" type="reset" value="#{msg.BUTTON_RESET_FORM}" />
+                                               <h:commandButton styleClass="submit" type="submit" action="#{userLoginController.doLogout()}" value="#{msg.BUTTON_USER_LOGOUT}" />
+                                       </div>
+                               </div>
+                       </h:form>
                </ui:define>
        </ui:composition>
 </html>