From bcf0c51ba5fb35ce14b4cc12c35755b1dcc5a3a9 Mon Sep 17 00:00:00 2001 From: Danhia Date: Tue, 8 Feb 2022 15:36:06 +0100 Subject: [PATCH] added option to open team to automatching --- src/events/templates/events/ctf_info.html | 10 ++------ src/events/templates/events/manage_team.html | 24 +++++++++++++---- src/events/urls.py | 2 ++ src/events/views/events.py | 11 +++++--- src/events/views/teams.py | 27 ++++++++++++++++++-- 5 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/events/templates/events/ctf_info.html b/src/events/templates/events/ctf_info.html index 3a95a52..8984a7b 100644 --- a/src/events/templates/events/ctf_info.html +++ b/src/events/templates/events/ctf_info.html @@ -20,14 +20,6 @@ {% endblock %} diff --git a/src/events/urls.py b/src/events/urls.py index 30818c8..80a3b78 100644 --- a/src/events/urls.py +++ b/src/events/urls.py @@ -17,4 +17,6 @@ urlpatterns = [ path('/manage_team', views.manage_team, name='manage_team'), path('/leave_team', views.leave_team, name='leave_team'), path('find_team/', views.find_team, name='find_team'), + path('/open_team', views.open_team, name='open_team'), + path('/close_team', views.close_team, name='close_team'), ] diff --git a/src/events/views/events.py b/src/events/views/events.py index 85c4737..ad41ac5 100644 --- a/src/events/views/events.py +++ b/src/events/views/events.py @@ -29,6 +29,7 @@ def events(request): def chall_event_info(request, event_slug, chall_slug): event_info = get_object_or_404(Event, slug=event_slug) ctf_info = get_object_or_404(CTF, event__slug=event_info.slug, slug=chall_slug) + if timezone.now() < ctf_info.pub_date: return redirect('events:event_info', event_slug=event_slug) eventisover = False @@ -37,6 +38,7 @@ def chall_event_info(request, event_slug, chall_slug): wrongflag = False errorform = False notsub = False + noteam = False player = None if request.user.is_authenticated and not request.user.is_staff: player = EventPlayer.objects.filter(event=event_info, user=request.user) @@ -56,6 +58,8 @@ def chall_event_info(request, event_slug, chall_slug): errorform = True if request.GET.get('NotRegistered'): notsub = True + if request.GET.get('NoTeam'): + noteam = True solved_challs = CTF_flags.objects.filter(ctf=ctf_info).order_by('flag_date') solved_list = [] for s in solved_challs: @@ -65,7 +69,7 @@ def chall_event_info(request, event_slug, chall_slug): solved_list.append([s.user, s.flag_date]) description = get_description_by_lang(ctf_info) return render(request, 'events/ctf_info.html', { 'ctf' : ctf_info, 'event':event_info, 'solved_list': solved_list, 'description': description, 'eventisover': eventisover, 'alreadyflag': alreadyflag, - 'congrat': congrat, 'wrongflag': wrongflag, 'errorform': errorform, 'notsub': notsub}) + 'congrat': congrat, 'wrongflag': wrongflag, 'errorform': errorform, 'notsub': notsub, 'noteam':noteam}) def event(request, event_slug): event_info = get_object_or_404(Event, slug=event_slug) @@ -126,6 +130,9 @@ def submit_event_flag(request, event_slug, chall_slug): player = EventPlayer.objects.get(user=request.user, event=ev) if player: + if ev.team_size > 1 and player.team is None: + response['Location'] += '?NoTeam=1' + return response if ev.team_size == 1 and CTF_flags.objects.filter(user=request.user, ctf=ctf_info): flagged = True else: @@ -187,8 +194,6 @@ def submit_pwd(request, event_slug): else: new = EventPlayer(user=request.user, event=ev) new.save() - # if event_info.team_size > 1: - # return render(request, 'events/create_team.html', {'event' : event_info, 'logged': True, 'wrongpwd': False, 'registered' : True, 'notexist' : False}) return redirect('events:event_info', event_slug=event_slug) diff --git a/src/events/views/teams.py b/src/events/views/teams.py index 07c1ef5..b7268a8 100644 --- a/src/events/views/teams.py +++ b/src/events/views/teams.py @@ -48,7 +48,6 @@ def join_team(request, event_slug): player.save() else: return render(request, 'events/join_team.html', {'event' : ev, 'logged': True, 'wrongpwd': False, 'registered' : True, 'notexist' : False}) - return redirect('events:event_info', event_slug=event_slug) @login_required def team_info(request, name, event_slug): @@ -175,4 +174,28 @@ def find_team(request, event_slug): player.team = team player.save() - return redirect('events:event_info', event_slug=event_slug) \ No newline at end of file + return redirect('events:event_info', event_slug=event_slug) + +@login_required +def open_team(request, event_slug): + event_info = get_object_or_404(Event, slug=event_slug) + player = EventPlayer.objects.get(user=request.user, event=event_info) + + if not player.team: + return render(request, 'events/create_team.html', {'event' : event_info, 'logged': True, 'wrongpwd': False, 'registered' : True, 'notexist' : False}) + + player.team.auto = True + player.team.save() + return redirect('events:manage_team', event_slug=event_slug) + +@login_required +def close_team(request, event_slug): + event_info = get_object_or_404(Event, slug=event_slug) + player = EventPlayer.objects.get(user=request.user, event=event_info) + + if not player.team: + return render(request, 'events/create_team.html', {'event' : event_info, 'logged': True, 'wrongpwd': False, 'registered' : True, 'notexist' : False}) + + player.team.auto = False + player.team.save() + return redirect('events:manage_team', event_slug=event_slug) \ No newline at end of file