Authenticated juries get access with the extra token access

This commit is contained in:
Yohann D'ANELLO 2020-05-25 22:12:05 +02:00
parent 4a7d3c5604
commit 6d01298e24
1 changed files with 6 additions and 0 deletions

View File

@ -6,6 +6,7 @@ from threading import local
from django.contrib.sessions.backends.db import SessionStore from django.contrib.sessions.backends.db import SessionStore
from member.models import TFJMUser from member.models import TFJMUser
from tournament.models import Pool
USER_ATTR_NAME = getattr(settings, 'LOCAL_USER_ATTR_NAME', '_current_user') USER_ATTR_NAME = getattr(settings, 'LOCAL_USER_ATTR_NAME', '_current_user')
SESSION_ATTR_NAME = getattr(settings, 'LOCAL_SESSION_ATTR_NAME', '_current_session') SESSION_ATTR_NAME = getattr(settings, 'LOCAL_SESSION_ATTR_NAME', '_current_session')
@ -75,6 +76,11 @@ class ExtraAccessMiddleware(object):
def __call__(self, request): def __call__(self, request):
if "extra_access_token" in request.GET: if "extra_access_token" in request.GET:
request.session["extra_access_token"] = request.GET["extra_access_token"] request.session["extra_access_token"] = request.GET["extra_access_token"]
if request.user.is_authenticated:
pool = Pool.objects.filter(extra_access_token=request.GET["extra_access_token"])
if pool.exists():
pool.juries.add(request.user)
pool.save()
else: else:
request.session.setdefault("extra_access_token", "") request.session.setdefault("extra_access_token", "")
return self.get_response(request) return self.get_response(request)