3. (Optional) Add ``"UNIQUE_SESSION_BLOCK_TIME = <seconds>"`` to enable the timeout.
-4. Run syncdb.
+4. (Optional) Add ``"UNIQUE_SESSION_WHITELIST = (<uid1>, <uid2>,...)"`` to whitelist some users (from their numeric id) so that they'll be exempt to the blocking mechanism.
+
+5. Run syncdb.
License
=======
TIME_DELTA = getattr(settings, 'UNIQUE_SESSION_BLOCK_TIME', None)
TIME_DELTA = TIME_DELTA and datetime.timedelta(seconds = TIME_DELTA)
+WHITELIST = set(getattr(settings, 'UNIQUE_SESSION_WHITELIST', []))
+
class SessionStore(SessionStoreBase):
"""
Implements database session store.
sid = transaction.savepoint(using=using)
try:
# Also delete all other sessions of that user
- if user_id:
+ if user_id and not user_id in WHITELIST:
exitsing = Session.objects.filter(user_id = user_id)
exitsing.exclude(session_key = obj.session_key).delete()
obj.save(force_insert=must_create, using=using)
to log in as long as there is a session updated that number of
seconds ago
"""
- limit = timezone.now() + TIME_DELTA
- s = Session.objects.filter(user_id = user.id,
- updated_date__lt = limit)
- if s.exists():
- raise PermissionDenied
+ if not user.id in UNIQUE_SESSION_WHITELIST:
+ limit = timezone.now() + TIME_DELTA
+ s = Session.objects.filter(user_id = user.id,
+ updated_date__lt = limit)
+ if s.exists():
+ raise PermissionDenied
if TIME_DELTA:
user_logged_in.connect(SessionStore.ensure_unique_login)