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

    I'm trying to give access to some contexts based on whether the visitor is logged into the manager. Using my custom context switcher plugin.

    I have tried $modx->user->get('username') but that returns (anonymous) even when the user is logged into the manager.
    $modx->user->hasSessionContext($modx->context->get('mgr')) doesn't return anything.
    $_SESSION['mgrValidated'] doesn't return anything.

    I'm using MODX 2.1.2.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That would be
      $modx->user->hasSessionContext('mgr');
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 8830
        • 98 Posts
        if ($modx->user->hasSessionContext('mgr')) {
             $modx->log(modX::LOG_LEVEL_ERROR, '[has session context mgr TRUE] ');
        }


        doesn't work.
          • 8830
          • 98 Posts
          Also I should say, it's a plugin executing OnHandleRequest. If that matters.
            • 22303 MODX Staff
            • 10,725 Posts
            I just tested this OnHandleRequest in 2.2.9 and it is working flawlessly, logging that my user does indeed have that session context.

            <?php
            $modx->log(modX::LOG_LEVEL_ERROR, "User has session context for mgr: " . ($modx->user->hasSessionContext('mgr')));


            Does your manager and your front-end context you are testing this from share the exact same domain? Could you be visiting the www URL for the front-end and non-www URL for the manager? Or vice versa? If so, those requests would have different sessions, and that could explain your issue.
              • 8830
              • 98 Posts
              Quote from: opengeek at Oct 05, 2013, 09:19 AM
              Does your manager and your front-end context you are testing this from share the exact same domain? (...) If so, those requests would have different sessions, and that could explain your issue.

              Spot on. Totally different domains.
              Is there a solution for this?
              I guess I could just log into the manager from that other domain. I will try that.
              Thank you.
                • 38290
                • 712 Posts
                This sounds somewhat related to reports that QuickBar, which uses hasSessionContent, is always displaying in 2.2.9
                https://forums.modx.com/thread/87029/quickbar-always-shows-in-2-2-9
                  jpdevries
                  • 3749
                  • 24,544 Posts
                  If you want to check for logged-in status in the current context, you want:

                  if ($modx->user->hasSessionContext($modx->context->get('key'))) {
                      /* user is logged 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
                    • 22303 MODX Staff
                    • 10,725 Posts
                    This is a problem anytime your manager session is on a different domain than your front-end web site( s ). There is simply no way to share those sessions. If it was a subdomain, you could solve it by changing the session_cookie_domain to allow all subdomains by prefixing the main domain with a period, e.g.
                    .domain.tld


                    You need a way, from the domain of the front-end site you need access to, to log the user into the mgr Context.