We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30319
    • 406 Posts
    I put Bob Ray's snippet from The MODx Book into a protected page, after following the instructions to set up basic login:
    <?php
    /* checkStatus snippet */
    $ctx = $modx->context->get('key');
    $isAuthenticated = $modx->user->hasSessionContext($ctx);
    if (!isAuthenticated) {
    $modx->sendRedirect($modx->makeUrl( 38 ));
    }

    spaces before after 38 to make it not a smiley smiley

    38 is the login page and the snippet call is in the 'context' / body of the start page for now.
    The snippet call is [[!checkStatus]].
    When testing it goes to the context's 404 page, why??

    Thank you, Tom [ed. note: TomMLS last edited this post 14 years, 8 months ago.]
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Is resource 38 protected by any resource groups / context acls?
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 30319
        • 406 Posts
        The documentation shows an access permissions tab, which must be in an older MODx version because Revo 2.2-pl shows no access permissions tab for the document, and only Resource Groups, and no Resource Groups were checked though one was created according to the documentation.

        Login documentation may need updating??

        Thank you, Tom
          • 30319
          • 406 Posts
          Weird thing is it works perfectly in one localhost server (don't need and not in the one I'm presently testing, same code, only different Resource IDs.

          I now know there exists an isLoggedIn snippet but now to find where/how to use it, it's not in the docs.
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            Quote from: TomMLS at Jan 22, 2012, 01:52 PM
            The documentation shows an access permissions tab, which must be in an older MODx version because Revo 2.2-pl shows no access permissions tab for the document, and only Resource Groups, and no Resource Groups were checked though one was created according to the documentation.

            Login documentation may need updating??

            Thank you, Tom

            Looks like it was renamed from Access Permissions to Resource Groups in 2.2, that's the one you need. I updated the docs to note the new name.
              Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

              Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
              • 30319
              • 406 Posts
              I find this information from Bob's Guides: In a snippet, the API function $modx->userLoggedIn() returns true if the user is logged in, now to figure out how to use it?????
                • 30319
                • 406 Posts
                Quote from: markh at Jan 22, 2012, 02:01 PM


                Looks like it was renamed from Access Permissions to Resource Groups in 2.2, that's the one you need. I updated the docs to note the new name.

                So it should be checked or not checked???? smiley
                  • 18373 ☆ A M B ☆
                  • 3,141 Posts
                  Quote from: TomMLS at Jan 22, 2012, 01:57 PM
                  Weird thing is it works perfectly in one localhost server (don't need and not in the one I'm presently testing, same code, only different Resource IDs.

                  I now know there exists an isLoggedIn snippet but now to find where/how to use it, it's not in the docs.

                  There's this:
                  [[!+modx.user.id:gte=`1`:then=`
                    Welcome [[!+modx.user.id:userinfo=`fullname`]]
                  `:else=``]]
                  


                  From a quick look your code should work. You can try to chang
                  $modx->sendRedirect($modx->makeUrl( 38 ));

                  to
                  $modx->sendUnauthorizedPage()

                  to send the user to an unauthorized page you set up.

                  I find this information from Bob's Guides: In a snippet, the API function $modx->userLoggedIn() returns true if the user is logged in, now to figure out how to use it??
                   if ($modx->userLoggedIn()) {
                    //do something
                  } else {
                    // not logged in do somethign else
                  }
                    Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                    Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    Quote from: TomMLS at Jan 22, 2012, 02:02 PM
                    Quote from: markh at Jan 22, 2012, 02:01 PM


                    Looks like it was renamed from Access Permissions to Resource Groups in 2.2, that's the one you need. I updated the docs to note the new name.

                    So it should be checked or not checked???? smiley

                    Resources that should be publicly accessible should (normally) NOT be a part of a resource group.
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                      • 30319
                      • 406 Posts
                      Then it should be checked -- these are to be private pages.

                      if ($modx->userLoggedIn()) {
                      //do something

                      How in php do I make the above IF statement an if NOT -- where does the bang go??
                      Does modx have a redirect to page that is redirect to a specific page??

                      Thank you...