Events done

This commit is contained in:
ix 2021-10-22 11:45:50 +02:00
parent c98e89b5ca
commit 86cc6070e1
8 changed files with 196 additions and 94 deletions

View File

@ -6,7 +6,7 @@
<div class="ctf-block"> <div class="ctf-block">
<a href="{% url 'events:event_info' event_slug=event.slug %}">< Back to event</a> <a href="{% url 'events:event_info' event_slug=event.slug %}">< Back to event</a>
<div class="ctf-head"> <div class="ctf-head">
<h2>Event - {{ event.name }}</h2> <h2>{% trans "Event" %} - {{ event.name }}</h2>
<h4>{{ ctf.name }}</h4> <h4>{{ ctf.name }}</h4>
<small>{% trans "Published date" %} : {{ ctf.pub_date }}</small> <small>{% trans "Published date" %} : {{ ctf.pub_date }}</small>
</div> </div>
@ -19,17 +19,31 @@
</div> </div>
<div class="ctf-footer"> <div class="ctf-footer">
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
{% if valitated == True %}
{% 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 %}
<p>{% trans "Congratulation !" %}</p> <p>{% trans "Congratulation !" %}</p>
{% elif alvalitated == True %} {% elif alreadyflag == True %}
<p>{% trans "Already flagged" %}</p> <p>{% trans "Already flagged" %}</p>
{% elif eventisover == True %}
<p>{% trans "This event is over." %}</p>
{% elif errorform == True %}
<p>{% trans "Error while processing your request. (Invalid Form)" %}</p>
{% 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>
{% 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 %}
<a class="begin-ctf-link" target="_blank" href="{{ ctf.file.url }}">{% trans "Download" %}</a></br> <a class="begin-ctf-link" target="_blank" href="{{ ctf.file.url }}">{% trans "Download" %}</a></br>
{% endif %} {% endif %}
{% else %} {% else %}
{% if failed %} {% if wrongflag == True %}
<p>{% trans "Wrong flag ! You can do it !" %}</p> <p>{% trans "Wrong flag ! You can do it !" %}</p>
{% endif %} {% endif %}
{% if ctf.ctf_url %} {% if ctf.ctf_url %}

View File

@ -4,8 +4,14 @@
{% load is_flagged %} {% load is_flagged %}
<div class="row"> <div class="row">
<div class="col-sm-12 col-md-9"> <div class="col-sm-12 col-md-9">
<div class="ctf-block"> {% if subisover == True %}
<div class="ctf-head"> <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 %}
<div class="event-block">
<div class="event-head">
<h3>{{ event.name }}</h3> <h3>{{ event.name }}</h3>
{% if ended == True %} {% if ended == True %}
<small>{% trans "This event is over." %}</small> <small>{% trans "This event is over." %}</small>
@ -13,17 +19,17 @@
<small>{% trans "This event start at" %} : {{ event.start_date }}</small> <small>{% trans "This event start at" %} : {{ event.start_date }}</small>
{% endif %} {% endif %}
</div> </div>
<div class="ctf-body"> <div class="event-body">
{% if event.description %} {% if event.description %}
{{ event.description|safe }} {{ event.description|safe }}
{% endif %} {% endif %}
</div> </div>
<div class="ctf-footer"> <div class="event-footer">
{% if begun == True %} {% if begun == True %}
<h4>{% trans "Challenges" %}</h4> <h4>{% trans "Challenges" %}</h4>
<div class="row">
{% if ctfs %} {% if ctfs %}
<div class="row">
{% for ctf in ctfs %} {% for ctf in ctfs %}
<div class="col-md-4"> <div class="col-md-4">
{% isflagged request.user ctf as flagged%} {% isflagged request.user ctf as flagged%}
@ -35,11 +41,11 @@
</a> </a>
</div> </div>
{% endfor %} {% endfor %}
{% endif %}
</div> </div>
{% if request.user.is_authenticated %} {% else %}
<small>{% trans "No challenges available." %}</small>
{% endif %} {% endif %}
{% else %} {% else %}
<h4>{% trans "The event has not started yet." %}</h4> <h4>{% trans "The event has not started yet." %}</h4>
@ -72,7 +78,7 @@
</tbody> </tbody>
</table> </table>
{% else %} {% else %}
<p>{% trans "Nobody have solved this CTF." %}</p> <p>{% trans "No one have earn point yet, you gonna be the first ?" %}</p>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -11,6 +11,12 @@
<div class="ctf-footer"> <div class="ctf-footer">
{% if logged == True %} {% if logged == True %}
{% if wrongpwd == True %}
<span class="message error-msg">{% trans "Wrong password submited." %}</span>
{% endif %}
{% if alreadyregistered == True %}
<span class="message error-msg">{% trans "You're already registered to this event." %}</span>
{% endif %}
<h4>{% trans "This event is password protected" %}</h4> <h4>{% trans "This event is password protected" %}</h4>
<small>{% trans "You need to submit the event password to gain access to this event." %}</small> <small>{% trans "You need to submit the event password to gain access to this event." %}</small>
<form method="post" action="{% url 'events:submit_pwd' event_slug=event.slug %}" class="submitflag-form"> <form method="post" action="{% url 'events:submit_pwd' event_slug=event.slug %}" class="submitflag-form">

View File

@ -3,14 +3,10 @@
{% load i18n %} {% load i18n %}
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<h3>Events</h3> <h3>{% trans "Events" %}</h3>
</div> </div>
{% if events %} {% if events %}
{% for ev in events %} {% for ev in events %}
{% if request.user.is_authenticated %}
{% else %}
{% endif %}
{% if curdate > ev.end_date %} {% if curdate > ev.end_date %}
<div class="col-md-3 is-over"> <div class="col-md-3 is-over">
{% else %} {% else %}
@ -23,17 +19,23 @@
alt="..." alt="..."
/> />
<div class="card-body"> <div class="card-body">
<h5 class="card-title">{{ ev.name }}</h5> <h5 class="card-title">
<p class="card-text"> {{ ev.name }}
Some quick example text to build on the card title and make up the bulk of the </h5>
card's content.
</p>
</div> </div>
<ul class="list-group list-group-flush text-center"> <ul class="list-group list-group-flush text-center">
<li class="list-group-item">{{ ev.start_date }} <br> - <br> {{ ev.end_date }}</li> <li class="list-group-item">
{{ ev.start_date }} <br> - <br> {{ ev.end_date }}
<br>
{% if curdate > ev.end_date %}
<span class="badge badge-pill badge-secondary">Finished</span>
{% else %}
<span class="badge badge-pill badge-success">Open</span>
{% endif %}
</li>
</ul> </ul>
<div class="card-body text-center"> <div class="card-body text-center">
<a href="{% url 'events:event_info' event_slug=ev.slug %}" class="card-link">See more</a> <a href="{% url 'events:event_info' event_slug=ev.slug %}" class="card-link">{% trans "See more" %}</a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -27,17 +27,44 @@ 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)
eventisover = False
alreadyflag = False
congrat = False
wrongflag = False
errorform = False
notsub = False
if request.user.is_authenticated and not request.user.is_staff: if request.user.is_authenticated and not request.user.is_staff:
userScore = Scores.objects.filter(event=event_info, user=request.user) userScore = Scores.objects.filter(event=event_info, user=request.user)
if not userScore: if not userScore:
return redirect('/') return redirect('/')
if request.GET.get('EventIsOver'):
eventisover = True
if request.GET.get('AlreadyFlagged'):
alreadyflag = True
if request.GET.get('Congrat'):
congrat = True
if request.GET.get('WrongFlag'):
wrongflag = True
if request.GET.get('ErrorInForm'):
errorform = True
if request.GET.get('NotRegistered'):
notsub = True
solved_list = CTF_flags.objects.filter(ctf=ctf_info).order_by('flag_date') solved_list = CTF_flags.objects.filter(ctf=ctf_info).order_by('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}) 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})
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)
IsRegistered = False IsRegistered = False
wrongpwd = False
alreadyregistered = False
subisover = False
if request.GET.get('WrongPassword'):
wrongpwd = True
if request.GET.get('AlreadyRegistered'):
alreadyregistered = True
if request.GET.get('SubscriptionIsOver'):
subisover = True
if request.user.is_authenticated: if request.user.is_authenticated:
userScore = Scores.objects.filter(event=event_info, user=request.user) userScore = Scores.objects.filter(event=event_info, user=request.user)
if userScore: if userScore:
@ -46,9 +73,9 @@ def event(request, event_slug):
if request.user.is_authenticated: if request.user.is_authenticated:
if request.user.is_staff is False: if request.user.is_staff is False:
if not userScore: if not userScore:
return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': True}) return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': True, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered})
else: else:
return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': False}) return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': False, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered})
ended = False ended = False
if timezone.now() >= event_info.end_date: if timezone.now() >= event_info.end_date:
ended = True ended = True
@ -57,25 +84,25 @@ def event(request, event_slug):
begun = True begun = True
challenges = CTF.objects.filter(event=event_info).order_by('category', 'points') challenges = CTF.objects.filter(event=event_info).order_by('category', 'points')
solved_list = Scores.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'user__username') solved_list = Scores.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'user__username')
return render(request, 'events/event_info.html', {'event' : event_info, 'IsRegistered': IsRegistered, 'ctfs': challenges, 'solved_list':solved_list, 'ended': ended, 'begun': begun}) return render(request, 'events/event_info.html', {'event' : event_info, 'IsRegistered': IsRegistered, 'ctfs': challenges, 'solved_list':solved_list, 'ended': ended, 'begun': begun, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered, 'subisover': subisover})
@login_required @login_required
def submit_event_flag(request, event_slug, chall_slug): def submit_event_flag(request, event_slug, chall_slug):
ev = get_object_or_404(Event, slug=event_slug) ev = get_object_or_404(Event, slug=event_slug)
response = redirect('events:event_chall_info', event_slug=event_slug, chall_slug=chall_slug) response = redirect('events:event_chall_info', event_slug=event_slug, chall_slug=chall_slug)
if timezone.now() >= ev.end_date: if timezone.now() >= ev.end_date:
response['Location'] += '?EventIsOver' response['Location'] += '?EventIsOver=1'
return response return response
if request.method == 'POST': if request.method == 'POST':
ctf_info = CTF.objects.get(event=ev, slug=chall_slug) ctf_info = CTF.objects.get(event=ev, slug=chall_slug)
if not ctf_info: if not ctf_info:
response['Location'] += '?ChallengeNotFound' response['Location'] += '?ChallengeNotFound=1'
return response return response
flagged = False flagged = False
if CTF_flags.objects.filter(user=request.user, ctf=ctf_info): if CTF_flags.objects.filter(user=request.user, ctf=ctf_info):
flagged = True flagged = True
response['Location'] += '?AlreadyFlagged' response['Location'] += '?AlreadyFlagged=1'
return response return response
try: try:
score = Scores.objects.get(user=request.user, event=ev) score = Scores.objects.get(user=request.user, event=ev)
@ -90,13 +117,16 @@ def submit_event_flag(request, event_slug, chall_slug):
score.last_submission_date = timezone.now() score.last_submission_date = timezone.now()
score.score += ctf_info.points score.score += ctf_info.points
score.save() score.save()
response['Location'] += '?Congrat' response['Location'] += '?Congrat=1'
return response return response
else: else:
response['Location'] += '?WrongFlag' response['Location'] += '?WrongFlag=1'
return response return response
else: else:
response['Location'] += '?ErrorInForm' response['Location'] += '?ErrorInForm=1'
return response
else:
response['Location'] += '?NotRegistered=1'
return response return response
return response return response
@ -107,15 +137,15 @@ def submit_pwd(request, event_slug):
if request.user.is_authenticated: if request.user.is_authenticated:
ev = get_object_or_404(Event, slug=event_slug) ev = get_object_or_404(Event, slug=event_slug)
if ev == False: if ev == False:
response['Location'] += '?NoEventFound' response['Location'] += '?NoEventFound=1'
return response return response
if request.POST.get('password') != ev.password: if request.POST.get('password') != ev.password:
response['Location'] += '?WrongPassword' response['Location'] += '?WrongPassword=1'
return response return response
if Scores.objects.filter(user=request.user, event=ev).exists(): if Scores.objects.filter(user=request.user, event=ev).exists():
response['Location'] += '?AlreadyRegistered' response['Location'] += '?AlreadyRegistered=1'
return response return response
else: else:
new = Scores(user=request.user, event=ev, score=0) new = Scores(user=request.user, event=ev, score=0)
@ -129,13 +159,13 @@ def subscribe_to_event(request, event_slug):
if request.user.is_authenticated: if request.user.is_authenticated:
ev = get_object_or_404(Event, slug=event_slug) ev = get_object_or_404(Event, slug=event_slug)
if ev == False: if ev == False:
response['Location'] += '?NoEventFound' response['Location'] += '?NoEventFound=1'
return response return response
if timezone.now() >= ev.end_date: if timezone.now() >= ev.end_date:
response['Location'] += '?SubscriptionIsOver' response['Location'] += '?SubscriptionIsOver=1'
return response return response
if Scores.objects.filter(user=request.user, event=ev).exists(): if Scores.objects.filter(user=request.user, event=ev).exists():
response['Location'] += '?AlreadyRegistered' response['Location'] += '?AlreadyRegistered=1'
return response return response
else: else:
new = Scores(user=request.user, event=ev, score=0) new = Scores(user=request.user, event=ev, score=0)

View File

@ -1,5 +1,7 @@
body {background-color: #121212;color: #D9D9D9} body {background-color: #121212;color: #D9D9D9}
.card-body {background-color: #1D1D1D;} .card-body {background-color: #1D1D1D;}
a{color:#cecece;}
a:hover{color:#a9a9a9;text-decoration: none;}
.main-div{margin-top: 40px;} .main-div{margin-top: 40px;}
footer {text-align: center;} footer {text-align: center;}
.news-card {margin-bottom: 20px; border: none;} .news-card {margin-bottom: 20px; border: none;}
@ -27,6 +29,9 @@ pre {background-color: #000; color: #cecece; padding-left: 15px; font-weight: bo
.ctf-body {margin-top: 50px;} .ctf-body {margin-top: 50px;}
.bloc-body {margin-top: 25px;} .bloc-body {margin-top: 25px;}
.ctf-footer {margin-top: 15px;text-align: center;} .ctf-footer {margin-top: 15px;text-align: center;}
.event-block{background-color: #1D1D1D; min-height: 235px; margin-bottom: 20px;}
.event-body {padding:15px;margin-top: 50px;}
.event-footer{margin-top: 15px;text-align: center; padding: 15px;}
input[type=text], input[type=password], input[type=url], input[type=email] {transition: 0.2s;border: 2px solid #2d2d2d;background-color: #2d2d2d;padding: 3px; border-radius: 4px;} input[type=text], input[type=password], input[type=url], input[type=email] {transition: 0.2s;border: 2px solid #2d2d2d;background-color: #2d2d2d;padding: 3px; border-radius: 4px;}
input[type=submit] {padding: 0px; margin-left: 5px; border-bottom: 3px solid #000;} input[type=submit] {padding: 0px; margin-left: 5px; border-bottom: 3px solid #000;}
.begin-ctf-link {display:inline-block;margin-bottom: 15px;text-align:center;text-transform: uppercase;text-decoration:none;font-weight: bold;color:#fff;background-color:#121212; width: 125px; border-bottom: 3px solid #000;padding:5px;} .begin-ctf-link {display:inline-block;margin-bottom: 15px;text-align:center;text-transform: uppercase;text-decoration:none;font-weight: bold;color:#fff;background-color:#121212; width: 125px; border-bottom: 3px solid #000;padding:5px;}
@ -41,9 +46,35 @@ input[type=submit]:hover {background-color:#000}
.submitflag-form input[type=submit]:hover {background-color:#000} .submitflag-form input[type=submit]:hover {background-color:#000}
.edit-infos-grp input{width: 100%;} .edit-infos-grp input{width: 100%;}
.message {display: block; padding:5px; text-align:center;margin-bottom: 10px;} .message {display: block; padding:5px; text-align:center;margin-bottom: 10px;}
.success-msg {background-color: #42b35e4f;} .success-msg {background-color: #42b35e4f!important;}
.error-msg {background-color: #9542428c;} .error-msg {background-color: #9542428c;}
.progress {background-color: #2d2d2d;color:#000} .progress {background-color: #2d2d2d;}
.bg-success { .bg-success {
background-color: #d9d9d9 !important; background-color: #d9d9d9 !important;color: #000;
}
.event-card {
background-color: #1d1d1d;
min-height: 30vh;
margin-bottom: 13.37px;
}
.card-img-top{
height:150px;
}
.chall-card{
background-color: #131313;
min-height: 100px;
border-radius: 2px;
margin-bottom: 13.37px;
}
.is-over {opacity: 50%;}
.event-head{
background-image:
linear-gradient(180deg, rgba(102,102,102,0.48501407398897056) 0%, rgba(29,29,29,1) 100%),
url('https://media.lesechos.com/api/v1/images/view/616957f83e45460bec299207/1280x720-webp/0611458970965-web-tete.webp');
height: 20vh;
background-size: cover;
color: white;
padding: 20px;
padding-top: 40px;
} }

View File

@ -29,6 +29,9 @@ pre {background-color: #000; color: #cecece; padding-left: 15px; font-weight: bo
.ctf-body {margin-top: 50px;} .ctf-body {margin-top: 50px;}
.bloc-body {margin-top: 25px;} .bloc-body {margin-top: 25px;}
.ctf-footer {margin-top: 15px;text-align: center;} .ctf-footer {margin-top: 15px;text-align: center;}
.event-block{background-color: #1D1D1D; min-height: 235px; margin-bottom: 20px;}
.event-body {padding:15px;margin-top: 50px;}
.event-footer{margin-top: 15px;text-align: center; padding: 15px;}
input[type=text], input[type=password], input[type=url], input[type=email] {transition: 0.2s;border: 2px solid #2d2d2d;background-color: #2d2d2d;padding: 3px; border-radius: 4px;} input[type=text], input[type=password], input[type=url], input[type=email] {transition: 0.2s;border: 2px solid #2d2d2d;background-color: #2d2d2d;padding: 3px; border-radius: 4px;}
input[type=submit] {padding: 0px; margin-left: 5px; border-bottom: 3px solid #000;} input[type=submit] {padding: 0px; margin-left: 5px; border-bottom: 3px solid #000;}
.begin-ctf-link {display:inline-block;margin-bottom: 15px;text-align:center;text-transform: uppercase;text-decoration:none;font-weight: bold;color:#fff;background-color:#121212; width: 125px; border-bottom: 3px solid #000;padding:5px;} .begin-ctf-link {display:inline-block;margin-bottom: 15px;text-align:center;text-transform: uppercase;text-decoration:none;font-weight: bold;color:#fff;background-color:#121212; width: 125px; border-bottom: 3px solid #000;padding:5px;}
@ -52,7 +55,7 @@ input[type=submit]:hover {background-color:#000}
.event-card { .event-card {
background-color: #1d1d1d; background-color: #1d1d1d;
min-height: 50vh; min-height: 30vh;
margin-bottom: 13.37px; margin-bottom: 13.37px;
} }
.card-img-top{ .card-img-top{
@ -65,3 +68,13 @@ input[type=submit]:hover {background-color:#000}
margin-bottom: 13.37px; margin-bottom: 13.37px;
} }
.is-over {opacity: 50%;} .is-over {opacity: 50%;}
.event-head{
background-image:
linear-gradient(180deg, rgba(102,102,102,0.48501407398897056) 0%, rgba(29,29,29,1) 100%),
url('https://media.lesechos.com/api/v1/images/view/616957f83e45460bec299207/1280x720-webp/0611458970965-web-tete.webp');
height: 20vh;
background-size: cover;
color: white;
padding: 20px;
padding-top: 40px;
}