session limit enforcement

* upon creating a new session, invalidate oldest sessions
This commit is contained in:
Chris Meyers
2015-09-28 10:53:49 -04:00
parent 531fc4d8ed
commit 000d26d7e3
9 changed files with 731 additions and 28 deletions

View File

@@ -524,9 +524,18 @@ class AuthTokenView(APIView):
try:
token = AuthToken.objects.filter(user=serializer.object['user'],
request_hash=request_hash,
expires__gt=now())[0]
expires__gt=now(),
reason='')[0]
token.refresh()
except IndexError:
# Get user un-expired tokens that are not invalidated that are
# over the configured limit.
# Mark them as invalid and inform the user
invalid_tokens = AuthToken.get_tokens_over_limit(serializer.object['user'])
for t in invalid_tokens:
# TODO: send socket notification
t.invalidate(reason='limit_reached')
token = AuthToken.objects.create(user=serializer.object['user'],
request_hash=request_hash)
return Response({'token': token.key, 'expires': token.expires})