added option to open team to automatching

This commit is contained in:
Danhia 2022-02-08 15:36:06 +01:00
parent dae0a87548
commit c8a171fa76
5 changed files with 56 additions and 18 deletions

View File

@ -20,14 +20,6 @@
</div> </div>
<div class="ctf-footer"> <div class="ctf-footer">
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
{% if subisover == True %}
<span class="message error-msg">{% trans "Subscriptions is over." %}</span>
{% endif %}
{% if alreadyregistered == True %}
<span class="message error-msg">{% trans "You're already registered to this event." %}</span>
{% endif %}
{% if congrat == True %} {% if congrat == True %}
<p>{% trans "Congratulation !" %}</p> <p>{% trans "Congratulation !" %}</p>
{% elif alreadyflag == True %} {% elif alreadyflag == True %}
@ -38,6 +30,8 @@
<p>{% trans "Error while processing your request. (Invalid Form)" %}</p> <p>{% trans "Error while processing your request. (Invalid Form)" %}</p>
{% elif notsub == True %} {% elif notsub == True %}
<span class="message error-msg">{% trans "Error: you're not registered to this event, so you can't register scores, fucking logic." %}</span> <span class="message error-msg">{% trans "Error: you're not registered to this event, so you can't register scores, fucking logic." %}</span>
{% elif noteam == True %}
<span class="message error-msg">{% trans "This is a team event, please create or join a team before submitting flags." %}</span>
{% if ctf.ctf_url %} {% if ctf.ctf_url %}
<a class="begin-ctf-link" target="_blank" href="{{ ctf.ctf_url }}">{% trans "Start the challenge" %}</a></br> <a class="begin-ctf-link" target="_blank" href="{{ ctf.ctf_url }}">{% trans "Start the challenge" %}</a></br>
{% elif ctf.file %} {% elif ctf.file %}

View File

@ -45,14 +45,28 @@
{% for p in members %} {% for p in members %}
<li class="list-group-item"><a class="profile_link" href="{% url 'accounts:profile' user_name=p.user.username %}">{{ p.user.username }}</a></li> <li class="list-group-item"><a class="profile_link" href="{% url 'accounts:profile' user_name=p.user.username %}">{{ p.user.username }}</a></li>
{% endfor %} {% endfor %}
</ul>
<form method='POST' action="{% url 'events:leave_team' event_slug=player.event.slug %}"> <form method='POST' action="{% url 'events:leave_team' event_slug=player.event.slug %}">
{%csrf_token%} {%csrf_token%}
<li class="list-group-item"> <li class="list-group-item">
<input class="form-control" type="submit" value="{% trans "Leave Team" %}"> <input class="form-control" type="submit" value="{% trans "Leave Team" %}">
</li> </li>
</form> </form>
{% if player.team.auto == False and player.event.auto_match == True %}
</ul> <form method='POST' action="{% url 'events:open_team' event_slug=player.event.slug %}">
{%csrf_token%}
<li class="list-group-item">
<input class="form-control" type="submit" value="{% trans "Open to automatching" %}">
</li>
</form>
{% elif player.event.auto_match == True %}
<form method='POST' action="{% url 'events:close_team' event_slug=player.event.slug %}">
{%csrf_token%}
<li class="list-group-item">
<input class="form-control" type="submit" value="{% trans "Close to automatching" %}">
</li>
</form>
{% endif %}
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -17,4 +17,6 @@ urlpatterns = [
path('<str:event_slug>/manage_team', views.manage_team, name='manage_team'), path('<str:event_slug>/manage_team', views.manage_team, name='manage_team'),
path('<str:event_slug>/leave_team', views.leave_team, name='leave_team'), path('<str:event_slug>/leave_team', views.leave_team, name='leave_team'),
path('find_team/<str:event_slug>', views.find_team, name='find_team'), path('find_team/<str:event_slug>', views.find_team, name='find_team'),
path('<str:event_slug>/open_team', views.open_team, name='open_team'),
path('<str:event_slug>/close_team', views.close_team, name='close_team'),
] ]

View File

@ -29,6 +29,7 @@ def events(request):
def chall_event_info(request, event_slug, chall_slug): def chall_event_info(request, event_slug, chall_slug):
event_info = get_object_or_404(Event, slug=event_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) ctf_info = get_object_or_404(CTF, event__slug=event_info.slug, slug=chall_slug)
if timezone.now() < ctf_info.pub_date: if timezone.now() < ctf_info.pub_date:
return redirect('events:event_info', event_slug=event_slug) return redirect('events:event_info', event_slug=event_slug)
eventisover = False eventisover = False
@ -37,6 +38,7 @@ def chall_event_info(request, event_slug, chall_slug):
wrongflag = False wrongflag = False
errorform = False errorform = False
notsub = False notsub = False
noteam = False
player = None player = None
if request.user.is_authenticated and not request.user.is_staff: if request.user.is_authenticated and not request.user.is_staff:
player = EventPlayer.objects.filter(event=event_info, user=request.user) 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 errorform = True
if request.GET.get('NotRegistered'): if request.GET.get('NotRegistered'):
notsub = True notsub = True
if request.GET.get('NoTeam'):
noteam = True
solved_challs = CTF_flags.objects.filter(ctf=ctf_info).order_by('flag_date') solved_challs = CTF_flags.objects.filter(ctf=ctf_info).order_by('flag_date')
solved_list = [] solved_list = []
for s in solved_challs: 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]) solved_list.append([s.user, s.flag_date])
description = get_description_by_lang(ctf_info) 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, 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): def event(request, event_slug):
event_info = get_object_or_404(Event, slug=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) player = EventPlayer.objects.get(user=request.user, event=ev)
if player: 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): if ev.team_size == 1 and CTF_flags.objects.filter(user=request.user, ctf=ctf_info):
flagged = True flagged = True
else: else:
@ -187,8 +194,6 @@ def submit_pwd(request, event_slug):
else: else:
new = EventPlayer(user=request.user, event=ev) new = EventPlayer(user=request.user, event=ev)
new.save() 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) return redirect('events:event_info', event_slug=event_slug)

View File

@ -48,7 +48,6 @@ def join_team(request, event_slug):
player.save() player.save()
else: else:
return render(request, 'events/join_team.html', {'event' : ev, 'logged': True, 'wrongpwd': False, 'registered' : True, 'notexist' : False}) 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 @login_required
def team_info(request, name, event_slug): def team_info(request, name, event_slug):
@ -176,3 +175,27 @@ def find_team(request, event_slug):
player.save() player.save()
return redirect('events:event_info', event_slug=event_slug) 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)