We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 52186
    • 3 Posts
    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.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could use a plugin, and if the user is already logged in, redirect to a message.
        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
        • 28042 ☆ 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
          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
          • 52186
          • 3 Posts
          Thanks for your response.

          I don't want to be ungrateful, but could you show some example snippet on how the hook would work?
            • 28042 ☆ 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.
              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
              • 28042 ☆ 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.
                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
                • 4172
                • 5,888 Posts
                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.]
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 28042 ☆ 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));
                    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
                    • 4172
                    • 5,888 Posts
                    Are you sure, the id of the modSession is allways the same for the same user?
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 52186
                      • 3 Posts
                      Hi guys,
                      any luck finding the solution?

                      I'm willing to make a contribution to whoever finds the solution.

                      Thanks for the time.