Hi everybody,
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.
-
☆ A M B ☆
- 24,524 Posts
You could use a plugin, and if the user is already logged in, redirect to a message.
-
☆ A M B ☆
- 24,524 Posts
I see that the Login snippet has pre-hooks, it should be possible to do this with a pre-hook rather than a plugin.
https://rtfm.modx.com/extras/revo/login/login.tutorials/login.using-pre-and-post-hooks
Thanks for your response.
I don't want to be ungrateful, but could you show some example snippet on how the hook would work?
-
☆ A M B ☆
- 24,524 Posts
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.
-
☆ A M B ☆
- 24,524 Posts
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.
user_id,context,session_id,is_logged
[ed. note: Bruno17 last edited this post 10 years, 5 months ago.]
-
☆ A M B ☆
- 24,524 Posts
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?
Hi guys,
any luck finding the solution?
I'm willing to make a contribution to whoever finds the solution.
Thanks for the time.