5 Replies Latest reply on Apr 4, 2007 10:44 AM by Tony Herstell

    12.3.6 Login Redirection

    Tony Herstell Master

       

      <event type="org.jboss.seam.postAuthenticate">
      <action expression="#{redirect.returnToCapturedView}"/>
      </event>
      


      After a successful login I want to send my user to a specific page (not only the page they came from!).


      Basically I have a login page supported by a controller
       /* (non-Javadoc)
       * @see de.co.clickstream.actions.user.LoginController#startLogin()
       */
       @Begin
       public String startLogin() {
       log.info(">startLogin");
       log.info("Starting Login conversation.");
       if (conversation != null) {
       log.info("Conversation. (" + conversation.getId() + ")");
       }
       log.info("<startLogin");
       return "login";
       }
      
       public String switchToRegistration() {
       log.info(">switchToRegistration");
       log.info("<switchToRegistration");
       return "registration";
       }
      
       /* (non-Javadoc)
       * @see de.co.clickstream.actions.user.LoginController#cancel()
       */
       @End
       public String cancel() {
       log.info(">cancel");
       log.info("<cancel");
       return "mainPage";
       }
      
       /* (non-Javadoc)
       * @see de.co.clickstream.actions.user.LoginController#destroy()
       */
       @Remove @Destroy
       public void destroy() {
       log.info(">destroy");
       log.info("<destroy");
       }
      


      I want to send them to a "members" page after login.




      Is it possible to do something like:

      <event type="org.jboss.seam.postAuthenticate">
      <action expression="#{membresPageController.startXXX}"/>
      </event>
      



      or just for a "menu page":
      <event type="org.jboss.seam.postAuthenticate">
      <action page="membersPage" activeConversation="die"/>
      </event>
      


      where membersPage is a navigation rule:
      [page]
      <navigation-rule>
      <navigation-case>
      <from-outcome>membersPage</from-outcome>
      <to-view-id>/pages/membersPage.xhtml</to-view-id>

      </navigation-case>
      [/page]



      Of course I would want to complete the authentication conversation if there was one so I may actually want to go to my loginController and call a routine to go somewhere (this seems nicer):

       /* (non-Javadoc)
       * @see xxx.user.LoginController#handleSuccessfulLogin()
       */
       @End
       public String handleSuccessfulLogin() {
       log.info(">handleSuccessfulLogin");
       log.info("<handleSuccessfulLogin");
       return "membersPage";
       }
      


      Please advise...

      Very tired so make be %(*&(*&^ obvious by the morning!



        • 1. Re: 12.3.6 Login Redirection
          Shane Bryzak Master

          The recommended way to achieve this is with pages.xml. Here's a snippet from pages.xml from the seamspace example that redirects to the users profile page after logging in:


          <page view-id="/home.xhtml">
           <navigation from-action="#{identity.login}">
           <rule if-outcome="loggedIn">
           <redirect view-id="/profile.xhtml"/>
           </rule>
           </navigation>


          • 2. Re: 12.3.6 Login Redirection
            Tony Herstell Master

             

             <!-- Tell the system where to send the user after login -->
             <page view-id="/login.xhtml">
             <navigation from-action="#{identity.login}">
             <rule if-outcome="loggedIn">
             <redirect view-id="/pages/mainpage.xhtml"/>
             </rule>
             </navigation>
             </page>
            


            How do I get the outcome to be
            loggedIn
            ???

            I have added the code above and it doesnt fire.

            I will look at the example 2morrow.

            THanks.


            • 3. Re: 12.3.6 Login Redirection
              Shane Bryzak Master

              Identity.login() returns a "loggedIn" outcome if authentication is successful. Alternatively you can use:

              <rule if="#{identity.loggedIn}">
              


              • 4. Re: 12.3.6 Login Redirection
                Tony Herstell Master

                 

                 <!-- Tell the system where to send the user after login -->
                 <page view-id="/login.xhtml">
                 <navigation from-action="#{identity.login}">
                 <rule if="#{identity.loggedIn}">
                 <redirect view-id="/pages/mainpage.xhtml"/>
                 </rule>
                 </navigation>
                 </page>
                


                I must be doing summat silly...
                I still cant get it to fire.
                I will come back after some sleeps... its 02:36 and unlike Gavin I needs sleep!

                Thanks for your help.

                • 5. Re: 12.3.6 Login Redirection
                  Tony Herstell Master

                  aha!
                  the page was actually:

                   <!-- Tell the system where to send the user after login -->
                   <page view-id="/pages/user/login.xhtml">
                   <navigation from-action="#{identity.login}">
                   <rule if="#{identity.loggedIn}">
                   <redirect view-id="/pages/mainpage.xhtml"/>
                   </rule>
                   </navigation>
                   </page>
                  


                  Thanks.

                  Fixed now.

                  Perhaps could be added to the doco in the login section!