Skip to content

Commit

Permalink
Restore session id if we try to login using TokenAuth.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Manovich committed Dec 5, 2019
1 parent 171a920 commit 8411d51
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cvat/apps/authentication/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.http import JsonResponse
from django.conf import settings
from rest_framework.authentication import TokenAuthentication
from django.contrib.auth import login

def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME,
login_url=None, redirect_methods=['GET']):
Expand All @@ -21,7 +22,8 @@ def _wrapped_view(request, *args, **kwargs):
tokenAuth = TokenAuthentication()
auth = tokenAuth.authenticate(request)
if auth is not None:
request.user = auth[0]
# If only token is available let's restore session id.
login(request, auth[0], 'django.contrib.auth.backends.ModelBackend')
return view_func(request, *args, **kwargs)

login_url = '{}/login'.format(settings.UI_URL)
Expand Down

0 comments on commit 8411d51

Please sign in to comment.