We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36926
    • 701 Posts
    When you get redirected to the login page, whats the URL as that should actually be displaying the url of the restricted page but the page contents is that of what you've set within the unauthorized page.

    Quote from: galahad5 at Jul 14, 2016, 05:19 PM
    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.
      • 10405
      • 288 Posts
      If I try to access the restricted page I get redirected to login.html and that's what shows in the URL. Then when I log in I get directed to the landing page (i.e landing.html) NOT the page I tried to access. It also shows landing.html in the URL.

      I'm sure this can be done because this actual forum seems able to return people to their posts when they log in. So there surely must be a way?? I know that other forum solutions also allow it, but I don't want to have to find another solution just because of this (the client really wants the "requested" page to be remembered and have the user sent to it after logging in.

      Anyone?
        • 17301
        • 932 Posts
        Did you try my suggestion?
          ■ 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
          Not sure how I'd use the isloggedin snippet, as I already have an "isloggedin" test- if the user is logged in and they try to access the restricted page, they're allowed. If they're not logged in and they try to access it, they get sent to the login page. So that's the first part of the process and is in place. What I need to do is get the system to remember the page they were trying to access, when they log in.
            • 22840
            • 1,572 Posts
            Could you not use javascript:history.go to send them back 2 pages once logged in, so they try to access the page and get redirected to the login page, they log in and land on a welcome back ( with a "were redirecting you message" ) page which redirects them back 2 pages in their history after 5 seconds ?

            Or even just a Continue link

            <p><a href="javascript:history.go(2);">Continue</a></p>


            Might work ! [ed. note: paulp last edited this post 7 years, 9 months ago.]
              • 10405
              • 288 Posts
              Quote from: paulp at Jul 19, 2016, 03:33 PM
              Could you not use javascript:history.go to send them back 2 pages once logged in, so they try to access the page and get redirected to the login page, they log in and land on a welcome back ( with a "were redirecting you message" ) page which redirects them back 2 pages in their history after 5 seconds ?

              Or even just a Continue link

              <p><a href="javascript:history.go(2);">Continue</a></p>


              Might work !
              Unfortunately that wouldn't work, because the restricted page wouldn't be in their history (because they were never able to access it until they logged in)
                • 3749
                • 24,544 Posts
                Quote from: galahad5 at Jul 19, 2016, 02:04 PM
                Not sure how I'd use the isloggedin snippet, as I already have an "isloggedin" test- if the user is logged in and they try to access the restricted page, they're allowed. If they're not logged in and they try to access it, they get sent to the login page. So that's the first part of the process and is in place. What I need to do is get the system to remember the page they were trying to access, when they log in.

                It really looks like &redirectToPrior=`1` in the Login tag would work here as long as the redirection to the Login page comes on the protected page. The trick would be *not* to protect the page with the MODX permissions system, since that keeps the user from ever reaching it. So, first, remove it from all Resource Groups.

                Instead, use isLoggedIn or Personalize *on the protected page* to redirect not-logged-in user to the Login page. &redirectToPrior=`1` in the Login snippet should then redirect them back to the protected page after they log in. Both of those snippet will do nothing if the user is already logged in.

                Actually, I would do this, since it would be a tiny bit faster:

                On the restricted page, or in its Template at the top of the body section:

                [[!CheckLoginStatus]]



                The CheckLoginStatus snippet:

                /* Do nothing if user is already logged in */
                if ($modx->user->hasSessionContext('web')) {
                   return '';
                }
                
                $loginPageId = 12;  /* Change to ID of Login page */
                $url = $modx->makeUrl(12, "", "", "full");
                $modx->sendRedirect($url);
                return;


                If the page is not protected in any other way, &redirectToPrior=`1` should 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
                  • 44922
                  • 131 Posts
                  I think Bob is giving you a good solution here, as your issue is created by protecting the page. Let them have the page but control the content they see. If you are worried about navigation on this page allowing users to access restricted areas, your navigation menus can be protected using 'Resource Group' settings in in Modx.

                  Using Bob's [[!CheckLoginStatus]] is also more elegant than the If snippet method I posted earlier.