We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18938
    • 2 Posts
    I would like to create a way for users who click a direct link to a protected resource to be automatically sent to the resource after they login.

    The basic idea is:


    • Intercept the requested resource ID upon request
    • Store the ID in a session variable
    • Redirect to login page
    • After login, check to see if the session variable is set, redirect to resource if it is set

    Does anyone have a recommendation on how to intercept this resource ID prior to redirecting to the Unauthorized resource?

    Is there already a plugin that does this?

    I have done a good deal of searching but have not located any solutions.

    Thank You.
      • 3749
      • 24,544 Posts
      There's probably a way to do it as you describe, but it might be simpler to just send them to the product page and put a snippet at the top of that page (or in the template) that redirects not-logged-in users to the Login page. Then user &redirectToPrior=`1` in the login page to send them back to the product page after logging in.



        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
        • 18938
        • 2 Posts
        Thank you for your reply. That gets me a bit closer, but leave one glaring question:

        Would that not circumvent the ACL in ModX? I was trying to avoid doing so.

        What I would like to accomplish, without circumventing the ACL system, is:

        IF
        unauthenticated user attempted to access restricted page
        THEN
        redirect to login page
        AFTER LOGIN
        redirect user back to initially requested page

        ELSE IF
        unauthenticated user logs in from standard login form and has not attempted to access a restricted page
        THEN
        send the user to the standard "post login" page


        What I was thinking is, if I could set a session variable storing the ID number of the unauthorized page, I could then redirect them back there instead of to the standard page that is shown after login.

        If this value was not set, it would simply send them through to their "account" page where they would normally be sent.

        I am trying to avoid forcing them to find the link they wanted to visit for a second time and instead just send them there after they authenticate.

        Any ideas?
          • 3749
          • 24,544 Posts
          You're right that what I was suggesting wouldn't work with the page restricted by an ACL entry and if it's not protected that way, any logged-in user could see it.

          The problem is that pages the user is not authorized to see don't exist as far as the browser is concerned and they don't show up in Wayfinder menus or getResources output. Unless you give all users "load" permission for all pages, they'll go to the error page rather than the unauthorized page.

          I'm not saying that what you want to do is impossible, but offhand I can't think of an easy way to do it.

            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
            • 36525
            • 47 Posts
            Have you figured out this part?

            IF
            unauthenticated user attempted to access restricted page
            THEN
            redirect to login page
            AFTER LOGIN
            redirect user back to initially requested page

            ELSE IF
            unauthenticated user logs in from standard login form and has not attempted to access a restricted page
            THEN
            send the user to the standard "post login" page



            I need to do the same thing. Basically be able to show a link or teaser on the homepage, if not logged in then login, then redirect to originally requested resource.
              Robert Tobys
              Managing Partner
              Green Goat Media
              916.405.1279

              Skype: roberttobys
              • 3749
              • 24,544 Posts
              One step in the right direction is to make the login page your error page (by setting the error_page) System Setting, and using this in the Login tag:


              &redirectToPrior=`1`



                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