diff options
author | ankitjavalkar | 2015-11-05 15:31:56 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-01-15 17:12:09 +0530 |
commit | e6cc3a71a0c41c40e95b47d7f001a7d948dba9fc (patch) | |
tree | 19b85d1e0c01f52e3458610980f10f89e7ba0866 /yaksh/middleware | |
parent | 3f037c26bc5c09ddfbd24930148233535770b38b (diff) | |
download | online_test-e6cc3a71a0c41c40e95b47d7f001a7d948dba9fc.tar.gz online_test-e6cc3a71a0c41c40e95b47d7f001a7d948dba9fc.tar.bz2 online_test-e6cc3a71a0c41c40e95b47d7f001a7d948dba9fc.zip |
Allow single user session active at any given time
Diffstat (limited to 'yaksh/middleware')
-rw-r--r-- | yaksh/middleware/__init__.py | 0 | ||||
-rw-r--r-- | yaksh/middleware/one_session_per_user.py | 22 |
2 files changed, 22 insertions, 0 deletions
diff --git a/yaksh/middleware/__init__.py b/yaksh/middleware/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/yaksh/middleware/__init__.py diff --git a/yaksh/middleware/one_session_per_user.py b/yaksh/middleware/one_session_per_user.py new file mode 100644 index 0000000..d9e97bb --- /dev/null +++ b/yaksh/middleware/one_session_per_user.py @@ -0,0 +1,22 @@ +from django.contrib.auth.models import User +from django.contrib.sessions.models import Session + +from yaksh.models import Visitor + + +class OneSessionPerUserMiddleware(object): + def process_request(self, request): + if isinstance(request.user, User): + current_key = request.session.session_key + if hasattr(request.user, 'visitor'): + active_key = request.user.visitor.session_key + print active_key, current_key + if active_key != current_key: + Session.objects.filter(session_key=active_key).delete() + request.user.visitor.session_key = current_key + request.user.visitor.save() + else: + Visitor.objects.create( + visitor_user=request.user, + session_key=current_key, + )
\ No newline at end of file |