We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10405
    • 288 Posts
    I've tried to ask about this before but I suspect my explanation wasn't clear enough as no one had a working answer- so this is the problem / issue.

    I'm using the Login snippet and users are required to log in to access certain pages. However, what I want is for the login form people to direct them NOT to the default landing page for their user group, but instead to the page they requested.

    Now, I have a snippet in my nav menu which tests for whether the user is logged in or not. If they're not, then many of the submenu links will just point to the login page instead of the page they want to get to. So they log in, but then of course they get redirected to the landing page for their user group. I need them to be sent to the page they wanted.

    I tried to figure if this could be done by adding a variable to the login page link in the menu for each page they need to log in to get to, i.e login.html?pagerequest=restrictedpage.html, login.html?pagerequest=restrictedpage2.html, and so on. The problem is I can't see how to integrate this into the Login snippet.

    So does anyone have any idea how this can be done?

    Thanks!

    This question has been answered by galahad5. See the first response.

      • 40706
      • 128 Posts
      This is the default behavior when configured correctly.

      To get this:

      anonymous Users need to have "Load" priviliges to this resource group. So When you click em, you get an 301 Unauthorized instead of an 404 Not Found.
      You need to configure the unauthorized_page to your Login-Page
      The Login Page Form, should not have an action
      The Login Snippet should have no loginResourceId

      Then you just Link to the member Pages, or users click them out of their favorites, history, etc.
      Modx uses an sendForward to display the login Page, with the url of the previous Page. As Soon as the Users is logged in, they will stay on the url, seeing the member content.
        • 3749
        • 24,544 Posts
        Have you tried using &redirectToPrior=`1` in the Login snippet tag? If I'm understanding you, it may do what you want.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 10405
          • 288 Posts
          Quote from: BobRay at Sep 19, 2016, 08:39 PM
          Have you tried using &redirectToPrior=`1` in the Login snippet tag? If I'm understanding you, it may do what you want.
          Thanks, but I already had that in the snippet. The complete call is as follows, it includes some Discuss hooks so that the user can also go into the Discuss forums on the site from a link, if they want to. I wonder, is there anything wrong with the snippet code?

          [[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`lgnLogoutTpl` &errTpl=`lgnErrTpl` &loginResourceId=`19` &logoutResourceId=`18` &preHooks=`preHook.DiscussLogin` &postHooks=`postHook.DiscussLogin` &redirectToPrior=`1`]]
          


          Thinking about it, I don't see how the snippet can redirect to the prior page, because the user would not have been able to load the requested page before logging in- for example if they were on some accessible page (e.g home), then tried to go to some-restricted-page.html, the system wouldn't load this at all, instead it would send them to login.html. So I guess redirectToPrior can't load the requested page (because it's not in the browser cache)?? [ed. note: galahad5 last edited this post 7 years, 7 months ago.]
            • 10405
            • 288 Posts
            Quote from: m.engel at Sep 19, 2016, 12:01 PM
            This is the default behavior when configured correctly.

            To get this:

            anonymous Users need to have "Load" priviliges to this resource group. So When you click em, you get an 301 Unauthorized instead of an 404 Not Found.
            You need to configure the unauthorized_page to your Login-Page
            The Login Page Form, should not have an action
            The Login Snippet should have no loginResourceId

            Then you just Link to the member Pages, or users click them out of their favorites, history, etc.
            Modx uses an sendForward to display the login Page, with the url of the previous Page. As Soon as the Users is logged in, they will stay on the url, seeing the member content.
            Unfortunately I don't see any way of applying Load permissions to a resource Group. I can apply the permission in general for Anonymous, but not for a Resource Group by the looks of it.

            That said, I followed the other steps, but all that happens now if I try to to a restricted page is that I get to the login page, but then after logging in I just get taken to the home page- the request for the restricted page is ignored. [ed. note: galahad5 last edited this post 7 years, 7 months ago.]
              • 3749
              • 24,544 Posts
              Do you have &redirectToPrior=`1` in the Login snippet tag?
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 3749
                • 24,544 Posts
                Do you have &redirectToPrior=`1` in the Login snippet tag?
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 10405
                  • 288 Posts
                  I do- as per my code I posted earlier in this thread. I can only think it isn't working because the prior page isn';t the one the user was trying to get to- because they don't have permission to it unless they are logged in. It's probably trying to reload the login page instead, as that's the "prior" page in this case.

                  So I don't see a way around this...
                    • 40706
                    • 128 Posts
                    Quote from: galahad5 at Sep 23, 2016, 05:08 PM

                    Unfortunately I don't see any way of applying Load permissions to a resource Group. I can apply the permission in general for Anonymous, but not for a Resource Group by the looks of it.

                    Edit The Usergroup Anonymous
                    Tab Permissions
                    Vertical Tab "Resource Group Access"
                    Add the Resource Group, the documents are in, with the ACL "Load Only"

                    After this, modx responses to Anonymous Users, that the URL exists. But nothing more.
                      • 3749
                      • 24,544 Posts
                      Michael's method is probably a better choice, but I think it would also work to protect the page with a snippet rather than access control.The snippet would forward unauthorized users to the login page. I think the redirect to prior would then work.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting