Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #295 from ropable/prod-oldui
Browse files Browse the repository at this point in the history
Alter core/views.py auth: avoid exception where UserSession does not exist
  • Loading branch information
ropable committed Jul 12, 2017
2 parents 4eba58c + b16c1b5 commit c798f07
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ def auth(request):

# store the access IP in the current user session
if request.user.is_authenticated():
usersession = UserSession.objects.get(
session_id=request.session.session_key)
try:
usersession = UserSession.objects.get(
session_id=request.session.session_key)
except UserSession.DoesNotExist:
# If the user does not have a UserSession, log them out and return 401 Unauthorised.
logout(request)
return HttpResponse('Unauthorized', status=401)
current_ip = get_ip(request)
if usersession.ip != current_ip:
usersession.ip = current_ip
Expand Down

0 comments on commit c798f07

Please sign in to comment.