diff --git a/tfjm/middlewares.py b/tfjm/middlewares.py index e19731f..b20051c 100644 --- a/tfjm/middlewares.py +++ b/tfjm/middlewares.py @@ -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)