I have a simple question/request.
Currently MODX allows many login sessions for the same user account.
(logging in from different browsers/devices on the same account doesn't end the previous session)
Is there any way to limit the session to only one active at a time (per user), and how?
I'm using the Login extra for MODX, the logging would only be for (protected) front-end context (default web).
Perhaps some kind of hook for the login, snippet or plugin would do it, but I don't have much experience with it.
I apologize for not having much knowledge on the matter.
Thank you for your time, I'm new to MODX but its a really great tool.
You could use a plugin, and if the user is already logged in, redirect to a message.
I see that the Login snippet has pre-hooks, it should be possible to do this with a pre-hook rather than a plugin.
Thanks for your response.
I don't want to be ungrateful, but could you show some example snippet on how the hook would work?
I'll have to think about it. It will involve the username, and the active_users table, I think... Let me take a look at the Who's Online dashboard widget to see how it does it for the list of online users.
No, what I was thinking isn't going to work. I don't see any way to do this.
I think, you would need to store it by yourself into a custom-table with a plugin, when a user logs in and logs out and maybe check, if the modSession-entry still exists.
[ed. note: Bruno17 last edited this post 3 years, 2 months ago.]
It's possible to query the session table for a session belonging to that user ID, but it can't be a Login pre-hook because those get fired after the session is set. So it will need to be a plugin.
$session = $modx->getObject('modSession', array('id' => $id));
Are you sure, the id of the modSession is allways the same for the same user?
any luck finding the solution?
I'm willing to make a contribution to whoever finds the solution.
Thanks for the time.