We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10405
    • 288 Posts
    Hello, I'm trying to find a way of making the Login snippet redirect the user after login, but not to the previous page they were on, instead to a page URL (for a restricted access page) that they clicked on in the nav menu.

    For example, in a dropdown in the front end site I have a menu link to a certain page, let's say restricted.html. The user clicks on the link and gets redirected to the Login form page to validate themselves. Then after logging in (and this is the bit I can't work out) they need to be redirected to restricted.html (which they can now access).

    As far as I can see, the redirectToPrior setting won't work in this case because the user didn't come from the restricted.html page. Is there something else that can be used?

    Thanks!
      • 17301
      • 932 Posts
      &loginResourceId=`18`


      Where '18' is would be the id to your restricted.html smiley
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 10405
        • 288 Posts
        Quote from: lkfranklin at Jul 13, 2016, 06:19 PM
        &loginResourceId=`18`


        Where '18' is would be the id to your restricted.html smiley
        That won't work I'm afraid- If I add that to the login snippet, it will always redirect people to the same page regardless of which restricted page they requested in the menu (there are several)
        Any ideas?
          • 3749
          • 24,544 Posts
          Is the page you're sending them to in another context? That requires the &contexts property in the login snippet tag.

          If you put a link to the protected page on the Login page and remove the redirect so the user stays on the Login page after logging in, does the link work? If not, your permissions may not be set up correctly.
            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 Jul 14, 2016, 06:58 AM
            Is the page you're sending them to in another context? That requires the &contexts property in the login snippet tag.

            If you put a link to the protected page on the Login page and remove the redirect so the user stays on the Login page after logging in, does the link work? If not, your permissions may not be set up correctly.
            The pages are all in the web (front end) context. I added a static link to the protected page on the login page, and that works whether or not the user is logged in.

            I've seen other sites where after a user logs in it "remembers" the restricted page they were trying to access- so I thought there must be a way of doing this in MODX...
              • 36926
              • 701 Posts
              &redirectToPrior=`1` should work.

              When the user clicks the restricted page is the url the correct one for that page but showing the unauthorizes page. Or is it showing the url to the login page?
                • 44922
                • 131 Posts
                If I've understood correctly, you could use the 'If' snippet on your restricted pages. It's downloadable in Package Manger. So something like:
                [[!If?
                   &subject=`[[profile]][[+username]]`
                   &operator=`EQ`
                   &operand=``
                   &then=` ** Insert HTML or chunk to display if NOT logged in ** `
                   &else=` ** Insert HTML, tv or chunk to display if logged in ** `
                ]]


                So if the user is logged in already, they see your permitted page content. If not, then show them a link to your Register / LogIn resource and redirect to prior once they've logged in.
                  • 36926
                  • 701 Posts
                  Yeah you could do that, take a look at Bobs personlize snippet:
                  http://bobsguides.com/personalize-tutorial.html

                  But if you've set up an unauthorized page then you shouldn't need that. On the unauthorized page just have the login snippet with redirectToPrior=1 then when a user visits a restricted page they are sent to this login. Once logged in they get redirected back to the page they were trying to access.

                    • 10405
                    • 288 Posts
                    I've set the Unauthorized page to be the Login page. So this is how the scenario should go:

                    User clicks on link for restricted.html in the dropdown menu. It's a restricted page so they get sent to login.html instead.
                    When they log in, they should be sent to restricted.html automatically.

                    But redirectToPrior won't work with this (I've tried) because it sends users back to the page they were on before they logged in (which could be any public page on the site, because they could have clicked the link on the menu from any of those pages). What I need is for the Login snippet to somehow know that they tried to access restricted.html, store that somewhere during login and then redirect to THAT page after they log in...
                      • 17301
                      • 932 Posts
                      have you tried the isloggedin snippet?
                      ' Will check to see if user is logged into the current or specific context. If not, redirects to unauthorized page.
                      '
                        ■ email: [email protected] | ■ website: https://alienbuild.uk

                        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.