We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45434
    • 16 Posts
    Hi,

    Does anyone know how to redirect users/members who don't have access to certain resources, to a custom resource instead of them going to the unauthorized page? I've gotten this far but now I want to customize the unauthorized page.

    Thanks!
      • 45434
      • 16 Posts
      Here is the snippet I'm using on the private page template:

      <?php
      /* CheckStatus snippet */
       
      if (! $modx->user->hasSessionContext($modx->context->get('key'))) {
          $modx->sendUnauthorizedPage();
      }
       
      return "";
        • 45434
        • 16 Posts
        I've also tried this:

        <?php
        /* CheckStatus snippet */
         
        if (! $modx->user->hasSessionContext($modx->context->get('key'))) {
            $url = $modx->makeUrl(17, "", "", "full");
            $modx->sendRedirect($url);
        }
         
        return "";
          • 3749
          • 24,544 Posts
          Either of those should work unless the pages are protected with ACL entries -- in which case the snippet will never execute and the user will go to the page specified in the error_page System Setting.

          What happens when you try them?
            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
            • 45434
            • 16 Posts
            They both take me to the unauthorized page.
              • 45434
              • 16 Posts
              Also whenever I change from one script to the next, the second level of privacy doesn't show in my navigation menu
                • 3749
                • 24,544 Posts
                What's the ID of your unauthorized page?

                If you're getting sent to the unauthorized page, it's likely that there's an ACL entry operating. Is the resource you're sending them to in a Resource Group? If so, try removing it from all Resource Groups to see if that makes a difference.

                Are there any Resource Group Access ACL entries?
                  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
                  • 45434
                  • 16 Posts
                  Hey Bob,

                  The ID of my unauthorized page is 17. Yes I had an ACL entry operating so I removed that resource from the Resource Group.

                  I have a 1st level Resource Group Access ACL entry, where 1st level members can access the basic pages but the 2nd level is using the [[!PrivatePage]] snippet in its own template.

                  After removing the resource from the resource group, now all members have access to the 2nd level page. Doesn't seem like the snippet is working.
                    • 45434
                    • 16 Posts
                    I actually logged out and tried to access the 2nd level page and it works! It goes to a custom unauthorized page. The only thing is that I'd like it to do the same thing for the 1st level members as well. Is that possible?
                      • 3749
                      • 24,544 Posts
                      I'm not sure I understand what you're trying to do. You can't find out anything about a user who isn't logged in. Once a user is logged in, you can check for a permission that some users have and others don't with:

                      if ($modx->user->hasPermission('some_permission')) {
                         /* Do something */
                      }
                        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