From a6095cc5c4d968171e41d14877bd79bbe5b1c55f Mon Sep 17 00:00:00 2001 From: Danhia Date: Fri, 14 Jan 2022 23:41:59 +0100 Subject: [PATCH] removed 500 when user is not connected and want to access public event --- src/events/templatetags/is_flagged.py | 2 ++ src/events/views.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/events/templatetags/is_flagged.py b/src/events/templatetags/is_flagged.py index 0f50904..49d84e9 100644 --- a/src/events/templatetags/is_flagged.py +++ b/src/events/templatetags/is_flagged.py @@ -9,6 +9,8 @@ def isflagged(user, ctf): flagged = False event_info = ctf.event + if user.is_authenticated == False: + return "" if event_info.team_size == 1: if CTF_flags.objects.filter(user=user, ctf=ctf): flagged = True diff --git a/src/events/views.py b/src/events/views.py index 6857621..5a28310 100644 --- a/src/events/views.py +++ b/src/events/views.py @@ -222,10 +222,10 @@ def subscribe_to_event(request, event_slug): @login_required def create_team(request, event_slug): - response = redirect('events:create_team', event_slug=event_slug) + response = redirect('events:create_team', event_slug=event_slug) + ev = get_object_or_404(Event, slug=event_slug) if request.method == 'POST': - if request.user.is_authenticated: - ev = get_object_or_404(Event, slug=event_slug) + if request.user.is_authenticated and ev.team_size > 1: if Team.objects.filter(name=request.POST.get('teamname'), event=ev).exists(): return render(request, 'events/create_team.html', {'event' : ev, 'logged': True, 'wrongpwd': False, 'registered' : True, 'exist' : True}) new = Team(name=request.POST.get('teamname'), password=request.POST.get('password'), event=ev) @@ -237,10 +237,10 @@ def create_team(request, event_slug): @login_required def join_team(request, event_slug): - response = redirect('events:join_team', event_slug=event_slug) + response = redirect('events:join_team', event_slug=event_slug) + ev = get_object_or_404(Event, slug=event_slug) if request.method == 'POST': - if request.user.is_authenticated: - ev = get_object_or_404(Event, slug=event_slug) + if request.user.is_authenticated and ev.team_size > 1: try: team = Team.objects.get(name=request.POST.get('teamname'), event=ev) except: