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
$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
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
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
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.
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.