How can I detect multiple logins into a Django web application from different locations? -
I want to allow only one authenticated session at a time for a personal login in my own app. Therefore, if a user is logged on the webpage at a given IP address, and those same user credentials are used with any other IP address, then I want to do something (either the first user is logged out or another user Denying access to.)
Not sure that it is still necessary but I thought I I will share my solution:
1) Diesgeng - Install Tracking (Thanks to that tip Van Gley, Google Maps + GeoIP is amazing!)
2) Add this middleware:
to django.contrib.sessions "" "More than one user prevents logging from one or more different IPs" def "process (request, request): ip_address = request .META.get ('REMOTE_ADDR', '') Try: last_login = Except request.user.last_login: last_login = 0 if Unicode (final_login) == Unicode (Datetime.now ()) [: 1 9]: previous_visitors = visitor.objects.filter (user = request.user). Previous_vid Exclugged for visitors (ip_address = ip_address): session.bjectfileter (session_key = visitor.session_key) .delete () visitor.user = none visitor.save () 3) Sure Do this visitortracking after the malware and when you log in to a new one, you should hit the previous login automatically.
Comments
Post a Comment