Events done

This commit is contained in:
ix 2021-10-22 11:45:50 +02:00
parent 06dc8188a0
commit 6997aaf93b
8 changed files with 196 additions and 94 deletions

View File

@ -8,28 +8,28 @@
<h3>Login</h3>
</div>
<div class="ctf-body">
<div class="col-sm-8 col-md-6 mx-auto">
{% if error %}
<span class="message error-msg">{% trans "Please, verify your infos." %}</span>
{% endif %}
<form method="post">
{% csrf_token %}
<div class="form-group">
<input class="form-control" type="text" name="username" placeholder="{% trans "Username" %}"></br>
<input class="form-control" type="password" name="password" placeholder="{% trans "Password" %}"></br>
<input class="form-control" type="submit" value="login">
</div>
<a href="{% url 'password_reset' %}">{% trans "Reset password" %}</a>
</form>
</div>
<div class="col-sm-8 col-md-6 mx-auto">
{% if error %}
<span class="message error-msg">{% trans "Please, verify your infos." %}</span>
{% endif %}
<form method="post">
{% csrf_token %}
<div class="form-group">
<input class="form-control" type="text" name="username" placeholder="{% trans "Username" %}"></br>
<input class="form-control" type="password" name="password" placeholder="{% trans "Password" %}"></br>
<input class="form-control" type="submit" value="login">
</div>
<a href="{% url 'password_reset' %}">{% trans "Reset password" %}</a>
</form>
</div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-3 right-sidebar">
<ul class="list-group">
<a href="/accounts/signin" class="list-group-item">{% trans "Login" %}</a>
<a href="/accounts/signup" class="list-group-item">{% trans "Sign up" %}</a>
<a href="/accounts/signin" class="list-group-item">{% trans "Login" %}</a>
<a href="/accounts/signup" class="list-group-item">{% trans "Sign up" %}</a>
</ul>
</div>
</div>

View File

@ -6,32 +6,46 @@
<div class="ctf-block">
<a href="{% url 'events:event_info' event_slug=event.slug %}">< Back to event</a>
<div class="ctf-head">
<h2>Event - {{ event.name }}</h2>
<h2>{% trans "Event" %} - {{ event.name }}</h2>
<h4>{{ ctf.name }}</h4>
<small>{% trans "Published date" %} : {{ ctf.pub_date }}</small>
</div>
<div class="ctf-body">
{% if description %}
{{ description|safe }}
{{ description|safe }}
{% else %}
{% trans "No translation available. Please try another language (English or French)." %}
{% trans "No translation available. Please try another language (English or French)." %}
{% endif %}
</div>
<div class="ctf-footer">
{% if request.user.is_authenticated %}
{% if valitated == True %}
<p>{% trans "Congratulation !" %}</p>
{% elif alvalitated == True %}
<p>{% trans "Already flagged" %}</p>
{% if ctf.ctf_url %}
<a class="begin-ctf-link" target="_blank" href="{{ ctf.ctf_url }}">{% trans "Start the challenge" %}</a></br>
{% elif ctf.file %}
<a class="begin-ctf-link" target="_blank" href="{{ ctf.file.url }}">{% trans "Download" %}</a></br>
{% endif %}
{% 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>
{% elif alreadyflag == True %}
<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 %}
<a class="begin-ctf-link" target="_blank" href="{{ ctf.ctf_url }}">{% trans "Start the challenge" %}</a></br>
{% elif ctf.file %}
<a class="begin-ctf-link" target="_blank" href="{{ ctf.file.url }}">{% trans "Download" %}</a></br>
{% endif %}
{% else %}
{% if failed %}
<p>{% trans "Wrong flag ! You can do it !" %}</p>
{% endif %}
{% if wrongflag == True %}
<p>{% trans "Wrong flag ! You can do it !" %}</p>
{% endif %}
{% if ctf.ctf_url %}
<a class="begin-ctf-link" target="_blank" href="{{ ctf.ctf_url }}">{% trans "Start the challenge" %}</a></br>
{% elif ctf.file %}

View File

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

View File

@ -11,13 +11,19 @@
<div class="ctf-footer">
{% if logged == True %}
<h4>{% trans "This event is password protected" %}</h4>
<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">
{% csrf_token %}
<input type="text" name="password" maxlength="48" required="">
<input class="form-control" type="submit" value=">">
</form>
{% 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>
<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">
{% csrf_token %}
<input type="text" name="password" maxlength="48" required="">
<input class="form-control" type="submit" value=">">
</form>
{% else %}
<h4>{% trans "You need to be logged to access this event." %}</h4>
{% endif %}

View File

@ -3,14 +3,10 @@
{% load i18n %}
<div class="row">
<div class="col-12">
<h3>Events</h3>
<h3>{% trans "Events" %}</h3>
</div>
{% if events %}
{% for ev in events %}
{% if request.user.is_authenticated %}
{% else %}
{% endif %}
{% if curdate > ev.end_date %}
<div class="col-md-3 is-over">
{% else %}
@ -23,17 +19,23 @@
alt="..."
/>
<div class="card-body">
<h5 class="card-title">{{ ev.name }}</h5>
<p class="card-text">
Some quick example text to build on the card title and make up the bulk of the
card's content.
</p>
<h5 class="card-title">
{{ ev.name }}
</h5>
</div>
<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>
<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>

View File

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

View File

@ -1,5 +1,7 @@
body {background-color: #121212;color: #D9D9D9}
.card-body {background-color: #1D1D1D;}
a{color:#cecece;}
a:hover{color:#a9a9a9;text-decoration: none;}
.main-div{margin-top: 40px;}
footer {text-align: center;}
.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;}
.bloc-body {margin-top: 25px;}
.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=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;}
@ -41,9 +46,35 @@ input[type=submit]:hover {background-color:#000}
.submitflag-form input[type=submit]:hover {background-color:#000}
.edit-infos-grp input{width: 100%;}
.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;}
.progress {background-color: #2d2d2d;color:#000}
.progress {background-color: #2d2d2d;}
.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;}
.bloc-body {margin-top: 25px;}
.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=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;}
@ -52,7 +55,7 @@ input[type=submit]:hover {background-color:#000}
.event-card {
background-color: #1d1d1d;
min-height: 50vh;
min-height: 30vh;
margin-bottom: 13.37px;
}
.card-img-top{
@ -64,4 +67,14 @@ input[type=submit]:hover {background-color:#000}
border-radius: 2px;
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;
}