1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-25 07:42:22 +00:00

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

View File

@ -6,6 +6,7 @@ from threading import local
from django.contrib.sessions.backends.db import SessionStore
from member.models import TFJMUser
from tournament.models import Pool
USER_ATTR_NAME = getattr(settings, 'LOCAL_USER_ATTR_NAME', '_current_user')
SESSION_ATTR_NAME = getattr(settings, 'LOCAL_SESSION_ATTR_NAME', '_current_session')
@ -75,6 +76,11 @@ class ExtraAccessMiddleware(object):
def __call__(self, request):
if "extra_access_token" in request.GET:
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:
request.session.setdefault("extra_access_token", "")
return self.get_response(request)