We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15469
    • 64 Posts
    Hi folks.
    I´m trying to figure out whether a manager-enabled user is logged in backend or not.
    With that info provided, I´d use a PHx-call to write a <quickedit:variable /> (if user is logged in) into my site when being parsed.

    Is there any snippet/plugin which gives me that functionality?

    Any help would be greatly appreciated!

    Greetings from Germany
      $cd /pub
      $more beer
      • 15469
      • 64 Posts
      $modx->getLoginUserName();
      Isn´t getting me useful data (no data at all).
      Did I overlook something in the API that would solve my issue?

      What I was trying to do:
      I´m trying to check if a manager is logged into the backend when viewing the site (frontend), so that i can view the manager some additional functions like quickedit and stuff.

      Any help appreciated...
        $cd /pub
        $more beer
        • 7231
        • 4,205 Posts
        There is a snippet that will load a chunk if you are logged in to the manager. I don’t remember the name but I have used it in the past (will need to look it up).

        The api call that I think is appropriate is userLoggedIn. It returns an array.
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 15469
          • 64 Posts
          Thanks a lot for your quick reply.
          I tried what you depicted to me.
          I tried to get that array back from "userLoggedIn()", but there was no output even if I was logged in twice via Safari and Firefox, held two sessions of two admin-accounts...

          What I first tried was this: having a snippet for a PHx-call.
          When returning 1, the PHx would include a <quickedit:... />.
          Otherwise do nothing.

          <?php
          if(isset($_SESSION[’mgrValidated’]) && $_SESSION[’mgrValidated’] == 1) {
          return 1;
          }
          else
          {
          return -1;
          }
          ?>

          Unfortunately, this session is set even if I´m logged off MODx, so all <quickedits:... /> are written to the source.

          My task is to avoid that <quickedit:... /> is being written to the source when the manager isn´t logged in.
          I´m a bit confused about that API-call that wouldn´t give me the information needed...

          Edit:
          Even this should work with the session being unset when logging off MODx.

          if ($this->isFrontend() && isset ($_SESSION[’mgrValidated’])) {
          ...
          }
            $cd /pub
            $more beer
            • 15469
            • 64 Posts
            I´m getting more and more confused.

            I set up a snippet to test whether I´m getting insane...

            So I did this:

            <?php
            echo function_exists($modx->userLoggedIn());
            ?>

            And, as you might (not!) expect, this one returned false to me.
            I was wondering why... and I´m still!!
            Even if that function exists in a rather deprecated way in 0.9.6, it does exist!

            Please help me out of this!
              $cd /pub
              $more beer
              • 3749
              • 24,544 Posts
              The userLoggedIn() function exists, but it isn’t part of the $modx object, it’s part of the DocumentParser object.

              I’m pretty sure it won’t do what you want anyway. It will only detect logged in manager users when actually in the manager (back-end). It sounds like you want to detect this from the front end. From the front end, it will only report whether the current user is a logged-in web user, not a manager user.

              Also, it would only give information about the current user, so it won’t tell you if another manager user is logged in in the back end.

              I’m not sure there is an easy way to do what you want. Someone else may have a better idea, but the only thing I can think of is to create a new table in the DB to list online Manager users and create a plugin that writes to it when they log in. If they close the browser without logging off, I think they might still show as logged in, though.

                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
                • 7231
                • 4,205 Posts
                This snippet does what you want. It will load a chunk if a manager is logged in:
                http://modxcms.com/forums/index.php?topic=21343.0

                It simply checks the $_SESSION[’mgrValidated’]
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 3749
                  • 24,544 Posts
                  That snppet should do what you want if you just want to know about the current viewer of the page being logged in as a manager. I had the idea from the original post that you wanted to know if *any* manager user was logged in the back end. Sorry if I misunderstood your question.
                    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