6 Replies Latest reply on Jan 31, 2008 10:06 AM by Fernando Montaño

    [NEWBIE Q] redirecting to a certain page if already logged i

    Rey Jexter Bumalay Newbie

      After successfully validating the account, I'm redirected to the next page which correct but when I try to access the login page again, the login form is displayed. What I want to do here is to redirect the user to another page and not display the login page. I'm using the Identity btw to authenticate the account.


      regards,
      rey

        • 1. Re: [NEWBIE Q] redirecting to a certain page if already logg
          Pete Muir Master

          You can use a page action for this - check if the user is logged in, if they are, direct them to a different page.

          • 2. Re: [NEWBIE Q] redirecting to a certain page if already logg
            Alexander Seitz Newbie

            Hi,

            here is a wiki-article about the topic:

            http://wiki.jboss.org/wiki/Wiki.jsp?page=AutomaticLoginRedirection

            It works but I have the problem, that I get an infinite loop when trying to I enter the application directly calling login.seam page. If I do this an enter my login/passwd the NotLoggenInException is thrown in a loop and the browser displays some kind of redirection error.

            What I want is the following:
            - call my login.seam page, login and be redirected to the page defined in pages.xml
            - if I am logged in and call the login.seam page I want to be redirected to the page defined in pages.xml

            Has anybody a working example of the pages.xml to do this? It seems to be a bit tricky and not trivial otherwise this kind of dummy-function in the wiki-article wouldn't be needed. But as mentioned even with this I don't get it working for 100%.

            Greetings,

            Alexander

            • 3. Re: [NEWBIE Q] redirecting to a certain page if already logg
              Fernando Montaño Expert

              How your pages.xml login page is configured?

              Does it have login-required="false"?


              like:

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



              BTW, you can invoke to any action you want when the page is loaded and then use the rules in order to forward to any page you want.

              • 4. Re: [NEWBIE Q] redirecting to a certain page if already logg
                Daniel Wachter Newbie

                hello together

                what is with manualy entered urls?
                if the user types in: http://server/application/login.seam

                no action is fired and this cause that the doesnt apply!

                any suggestions?
                daniel

                • 5. Re: [NEWBIE Q] redirecting to a certain page if already logg
                  Rey Jexter Bumalay Newbie

                  hey thanks for all the replies.

                  anyway this is my login.page.xml (just the same as the pages.xml but specifically for login page. i just use this because this is generated by seam-gen):

                  <?xml version="1.0" encoding="UTF-8"?>
                  <page xmlns="http://jboss.com/products/seam/pages"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd"
                   login-required="false" action="#{userAuthenticator.checkLogin}">
                  
                   <navigation>
                   <rule if="#{identity.loggedIn}">
                   <redirect view-id="/dashboard1234.xhtml"/>
                   </rule>
                   </navigation>
                  
                   <navigation from-action="#{identity.logout}">
                   <redirect view-id="/login.xhtml" />
                   </navigation>
                  
                   <navigation from-action="#{identity.login}">
                   <rule if="#{identity.loggedIn}">
                   <redirect view-id="/dashboard.xhtml"/>
                   </rule>
                   </navigation>
                  
                  </page>


                  i agree with wachtda that the page action doesnt fire if you try to access the login.seam directly. when i use the base url instead, i am redirected to login.seam and the page action for login page is executed.


                  rey


                  • 6. Re: [NEWBIE Q] redirecting to a certain page if already logg
                    Fernando Montaño Expert

                    Try the following change:

                    
                    <?xml version="1.0" encoding="UTF-8"?>
                    <page xmlns="http://jboss.com/products/seam/pages"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd"
                     login-required="false" action="#{userAuthenticator.checkLogin}">
                    
                     <navigation from-action="#{userAuthenticator.checkLogin}">
                     <rule if="#{identity.loggedIn}">
                     <redirect view-id="/dashboard1234.xhtml"/>
                     </rule>
                     </navigation>
                    
                     <navigation from-action="#{identity.logout}">
                     <redirect view-id="/login.xhtml" />
                     </navigation>
                    
                     <navigation from-action="#{identity.login}">
                     <rule if="#{identity.loggedIn}">
                     <redirect view-id="/dashboard.xhtml"/>
                     </rule>
                     </navigation>
                    
                    </page>