events added, need to smooth html and css

This commit is contained in:
ix 2021-10-21 15:02:02 +02:00
parent 0f231a4988
commit 06dc8188a0
33 changed files with 851 additions and 181 deletions

View File

@ -1,5 +1,12 @@
from .models import UserProfileInfo
from django.contrib import admin
admin.site.register(UserProfileInfo)
#admin.site.register(UserProfileInfo)
# Register your models here.
@admin.register(UserProfileInfo)
class userprofile(admin.ModelAdmin):
#list display
list_display = ['user', 'score', 'last_submission_date']
# search list
search_fields = ['score', 'user__username']

View File

@ -121,11 +121,11 @@ def profile(request, user_name):
for cat in cats:
# prepare categories
solved_count = CTF_flags.objects.filter(user=user_obj, ctf__category__name=cat.name).count()
max_count = CTF.objects.filter(category__name=cat.name).count()
solved_count = CTF_flags.objects.filter(user=user_obj, ctf__event=None , ctf__category__name=cat.name).count()
max_count = CTF.objects.filter(category__name=cat.name, event=None).count()
# get datas
somme = 0
solved = CTF_flags.objects.filter(user=user_obj, ctf__category__name=cat.name).order_by('flag_date')
solved = CTF_flags.objects.filter(user=user_obj, ctf__category__name=cat.name, ctf__event=None).order_by('flag_date')
pointDatas[cat.name] = []
pointDatas[cat.name].append([user_obj.date_joined.timestamp() * 1000, 0])
percent = (solved_count / max_count) * 100
@ -134,7 +134,7 @@ def profile(request, user_name):
somme += flag.ctf.points
pointDatas[cat.name].append([flag.flag_date.timestamp() * 1000, somme])
solves = CTF_flags.objects.filter(user=user_obj).order_by('-flag_date')
solves = CTF_flags.objects.filter(user=user_obj, ctf__event=None).order_by('-flag_date')
solved = []
somme = 0
solved.append([user_obj.date_joined.timestamp() * 1000, 0])

View File

@ -2,7 +2,24 @@ from django.contrib import admin
from .models import Category, CTF, CTF_flags
admin.site.register(Category)
admin.site.register(CTF)
admin.site.register(CTF_flags)
#admin.site.register(CTF)
#admin.site.register(CTF_flags)
@admin.register(CTF_flags)
class ctf_flags(admin.ModelAdmin):
#list display
list_display = ['user', 'ctf', 'flag_date']
#list Filter
list_filter = ('ctf__category', 'ctf', 'user','flag_date')
# search list
search_fields = ['ctf__category__name', 'ctf__name', 'user__username']
@admin.register(CTF)
class ctf(admin.ModelAdmin):
#list display
list_display = ['name', 'event', 'category']
#list Filter
list_filter = ('category', 'event')
# search list
search_fields = ['category__name', 'name', 'author__username']
# Register your models here.

View File

@ -0,0 +1,20 @@
# Generated by Django 3.2.7 on 2021-10-18 14:23
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('events', '0001_initial'),
('ctfs', '0004_auto_20210907_1407'),
]
operations = [
migrations.AddField(
model_name='ctf',
name='event',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='events.event'),
),
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.2.7 on 2021-10-19 15:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('events', '0002_alter_event_password'),
('ctfs', '0005_ctf_event'),
]
operations = [
migrations.AlterField(
model_name='ctf',
name='event',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='events.event'),
),
]

View File

@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import User
from events.models import Event
class Category(models.Model):
name = models.CharField(max_length=200)
@ -17,6 +18,7 @@ class CTF(models.Model):
description_de = models.TextField(blank=True)
file = models.FileField(blank=True, upload_to='challenges')
ctf_url = models.URLField(blank=True)
event = models.ForeignKey(Event, null=True, blank=True, on_delete=models.CASCADE)
points = models.PositiveSmallIntegerField()
slug = models.SlugField(max_length=55)
pub_date = models.DateTimeField('Date published')

View File

@ -21,7 +21,7 @@ def get_description_by_lang(ctf):
def category(request, cat_slug):
cat = get_object_or_404(Category, slug=cat_slug)
ctfs = CTF.objects.filter(category=cat).order_by('points')
ctfs = CTF.objects.filter(category=cat, event=None).order_by('points')
for ex in ctfs:
ex.solved_num = CTF_flags.objects.filter(ctf=ex).count()
ex.solved = ex.solved_by(request.user)
@ -46,18 +46,12 @@ def ctf(request, cat_slug, ctf_slug):
profil.last_submission_date = timezone.now()
profil.score += ctf_info.points
profil.save()
return render(request, 'ctfs/ctf_info.html', {'form' : form, 'ctf' : ctf_info, 'solved_list': solved_list, 'valitated': True, 'description': description})
return render(request, 'ctfs/ctf_info.html', { 'ctf' : ctf_info, 'solved_list': solved_list, 'valitated': True, 'description': description})
else:
return render(request, 'ctfs/ctf_info.html', {'form' : form, 'ctf' : ctf_info, 'solved_list': solved_list, 'failed': True, 'description': description})
return render(request, 'ctfs/ctf_info.html', { 'ctf' : ctf_info, 'solved_list': solved_list, 'failed': True, 'description': description})
else:
form = submit_flag()
return render(request, 'ctfs/ctf_info.html', {'form' : form, 'ctf' : ctf_info, 'solved_list': solved_list, 'alvalitated': True, 'description': description})
return render(request, 'ctfs/ctf_info.html', { 'ctf' : ctf_info, 'solved_list': solved_list, 'alvalitated': True, 'description': description})
else:
form = submit_flag()
return render(request, 'ctfs/ctf_info.html', {'form' : form, 'ctf' : ctf_info, 'solved_list': solved_list, 'description': description})
return render(request, 'ctfs/ctf_info.html', { 'ctf' : ctf_info, 'solved_list': solved_list, 'description': description})
else:
form = submit_flag()
return render(request, 'ctfs/ctf_info.html', {'form' : form, 'ctf' : ctf_info, 'solved_list': solved_list, 'alvalitated': flagged, 'description': description})
# Create your views here.
return render(request, 'ctfs/ctf_info.html', { 'ctf' : ctf_info, 'solved_list': solved_list, 'alvalitated': flagged, 'description': description})

0
src/events/__init__.py Normal file
View File

23
src/events/admin.py Normal file
View File

@ -0,0 +1,23 @@
from django.contrib import admin
from .models import Event, Scores
#admin.site.register(Event)
#admin.site.register(Scores)
@admin.register(Event)
class event(admin.ModelAdmin):
#list display
list_display = ['name', 'start_date', 'end_date']
# search list
search_fields = ['name', 'slug', 'description', 'password']
@admin.register(Scores)
class score(admin.ModelAdmin):
#list display
list_display = ['user', 'event', 'score']
#list Filter
list_filter = ('event',)
# search list
search_fields = ['user__username', 'score', 'event__name']
# Register your models here.

6
src/events/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class EventsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'events'

4
src/events/forms.py Normal file
View File

@ -0,0 +1,4 @@
from django import forms
class submit_flag(forms.Form):
flag = forms.CharField(label="Flag", max_length=100)

View File

@ -0,0 +1,46 @@
# Generated by Django 3.2.7 on 2021-10-18 14:19
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Event',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=200)),
('logo', models.CharField(max_length=200)),
('img', models.CharField(max_length=200)),
('description', models.TextField()),
('start_date', models.DateTimeField()),
('end_date', models.DateTimeField()),
('password', models.CharField(max_length=200)),
('slug', models.SlugField(max_length=55)),
],
),
migrations.CreateModel(
name='Scores',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('score', models.PositiveIntegerField(db_index=True, default=0)),
('last_submission_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Last Submission Date')),
('event', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='events.event')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-score', 'last_submission_date', 'user__username'],
},
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.7 on 2021-10-18 14:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='event',
name='password',
field=models.CharField(blank=True, max_length=200),
),
]

View File

@ -0,0 +1,26 @@
# Generated by Django 3.2.7 on 2021-10-19 15:19
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('events', '0002_alter_event_password'),
]
operations = [
migrations.AlterField(
model_name='scores',
name='event',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.event'),
),
migrations.AlterField(
model_name='scores',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View File

26
src/events/models.py Normal file
View File

@ -0,0 +1,26 @@
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import timezone
import uuid
# Create your models here.
class Event(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=200)
logo = models.CharField(max_length=200)
img = models.CharField(max_length=200)
description = models.TextField()
start_date = models.DateTimeField()
end_date = models.DateTimeField()
password = models.CharField(max_length=200, blank=True)
slug = models.SlugField(max_length=55)
def __str__(self):
return self.name
class Scores(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
event = models.ForeignKey(Event, on_delete=models.CASCADE)
score = models.PositiveIntegerField(default=0, db_index=True)
last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now)
class Meta:
ordering = ['-score', 'last_submission_date', 'user__username']

View File

@ -0,0 +1,87 @@
{% extends 'base.html' %}
{% block content %}
{% load i18n %}
<div class="row">
<div class="col-sm-12 col-md-9">
<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>
<h4>{{ ctf.name }}</h4>
<small>{% trans "Published date" %} : {{ ctf.pub_date }}</small>
</div>
<div class="ctf-body">
{% if description %}
{{ description|safe }}
{% else %}
{% 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 %}
{% else %}
{% if failed %}
<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 %}
<a class="begin-ctf-link" target="_blank" href="{{ ctf.file.url }}">{% trans "Download" %}</a></br>
{% endif %}
<form method="post" action="{% url 'events:submit_event_flag' event_slug=event.slug chall_slug=ctf.slug %}" class="submitflag-form">
{% csrf_token %}
<input type="text" name="flag" maxlength="48" required="" id="id_flag">
<input class="form-control" type="submit" value=">">
</form>
{% endif %}
{% endif %}
</div>
</div>
<div>
<h4>{% trans "Solved by" %}</h4>
{% if solved_list %}
<table class="table table-dark">
<thead>
<tr>
<th scope="col">{% trans "Username" %}</th>
<th scope="col">{% trans "Website" %}</th>
<th scope="col">{% trans "Score" %}</th>
<th scope="col">{% trans "Date" %}</th>
</tr>
</thead>
<tbody>
{% for s in solved_list %}
<tr>
<th scope="row"><a class="profile_link" href="{% url 'accounts:profile' user_name=s.user.username %}"> {{ s.user.username }}</a></th>
<td>{{ s.user.userprofileinfo.portfolio_site }}</td>
<td>{{ s.user.userprofileinfo.score }}</td>
<td>{{ s.flag_date }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>{% trans "Nobody have solved this CTF." %}</p>
{% endif %}
</div>
</div>
<div class="d-none d-md-block col-10 col-md-3 right-sidebar">
<ul class="list-group">
<li class="list-group-item">{% trans "Author" %} : {{ ctf.author.username }}</li>
<li class="list-group-item">{% trans "Point reward" %} : {{ ctf.points }}</li>
</ul>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,96 @@
{% extends 'base.html' %}
{% block content %}
{% load i18n %}
{% load is_flagged %}
<div class="row">
<div class="col-sm-12 col-md-9">
<div class="ctf-block">
<div class="ctf-head">
<h3>{{ event.name }}</h3>
{% if ended == True %}
<small>{% trans "This event is over." %}</small>
{% else %}
<small>{% trans "This event start at" %} : {{ event.start_date }}</small>
{% endif %}
</div>
<div class="ctf-body">
{% if event.description %}
{{ event.description|safe }}
{% endif %}
</div>
<div class="ctf-footer">
{% if begun == True %}
<h4>{% trans "Challenges" %}</h4>
<div class="row">
{% 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>
{% endfor %}
{% endif %}
</div>
{% if request.user.is_authenticated %}
{% endif %}
{% else %}
<h4>{% trans "The event has not started yet." %}</h4>
{% endif %}
</div>
</div>
<div>
<h4>{% trans "ScoreBoard" %}</h4>
{% if solved_list %}
<table class="table table-dark">
<thead>
<tr>
<th scope="col">{% trans "Rank" %}</th>
<th scope="col">{% trans "Username" %}</th>
<th scope="col">{% trans "Website" %}</th>
<th scope="col">{% trans "Score" %}</th>
</tr>
</thead>
<tbody>
{% for s in solved_list %}
<tr>
<th scope="row"># {{ forloop.counter0|add:1 }}</th>
<th scope="row">
<a class="profile_link" href="{% url 'accounts:profile' user_name=s.user.username %}"> {{ s.user.username }}</a>
</th>
<td>{{ s.user.userprofileinfo.site }}</td>
<td>{{ s.score }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>{% trans "Nobody have solved this CTF." %}</p>
{% endif %}
</div>
</div>
<div class="d-none d-md-block col-10 col-md-3 right-sidebar">
<ul class="list-group">
<li class="list-group-item">{{ event.name }}</li>
<li class="list-group-item">{% trans "Start at" %} : {{ event.start_date }}</li>
<li class="list-group-item">{% trans "End at" %} : {{ event.end_date }}</li>
{% if ended == False and IsRegistered == False %}
<form method='POST' action="{% url 'events:subscribe_event' event_slug=event.slug %}">
{%csrf_token%}
<li class="list-group-item">
<input class="form-control" type="submit" value="{% trans "Subscribe" %}">
</li>
</form>
{% endif %}
</ul>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,37 @@
{% extends 'base.html' %}
{% block content %}
{% load i18n %}
<div class="row">
<div class="col-sm-12 col-md-9">
<div class="ctf-block">
<div class="ctf-head">
<h3>{{ event.name }}</h3>
<small>{% trans "This event start at" %} : {{ event.start_date }}</small>
</div>
<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>
{% else %}
<h4>{% trans "You need to be logged to access this event." %}</h4>
{% endif %}
</div>
</div>
</div>
<div class="d-none d-md-block col-10 col-md-3 right-sidebar">
<ul class="list-group">
<li class="list-group-item">{{ event.name }}</li>
<li class="list-group-item">{% trans "Start at" %} : {{ event.start_date }}</li>
<li class="list-group-item">{% trans "End at" %} : {{ event.end_date }}</li>
</ul>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,47 @@
{% extends 'base.html' %}
{% block content %}
{% load i18n %}
<div class="row">
<div class="col-12">
<h3>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 %}
<div class="col-md-3">
{% endif %}
<div class="event-card">
<img
src="{{ev.img}}"
class="card-img-top"
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>
</div>
<ul class="list-group list-group-flush text-center">
<li class="list-group-item">{{ ev.start_date }} <br> - <br> {{ ev.end_date }}</li>
</ul>
<div class="card-body text-center">
<a href="{% url 'events:event_info' event_slug=ev.slug %}" class="card-link">See more</a>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p>{% trans "No events available." %}</p>
{% endif %}
</div>
</div>
{% endblock %}

View File

View File

@ -0,0 +1,10 @@
from django import template
from ctfs.models import CTF_flags
register = template.Library()
@register.simple_tag
def isflagged(user, ctf):
if CTF_flags.objects.filter(user=user, ctf=ctf):
return "success-msg"
return ""

3
src/events/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

13
src/events/urls.py Normal file
View File

@ -0,0 +1,13 @@
from django.urls import path
from . import views
app_name = "events"
urlpatterns = [
path('', views.events, name='events'),
path('<str:event_slug>', views.event, name='event_info'),
path('<str:event_slug>/challenge/<str:chall_slug>', views.chall_event_info, name='event_chall_info'),
path('pwd/<str:event_slug>', views.submit_pwd, name='submit_pwd'),
path('submitEventFlag/<str:event_slug>/<str:chall_slug>', views.submit_event_flag, name='submit_event_flag'),
path('subscribe/<str:event_slug>', views.subscribe_to_event, name='subscribe_event')
]

143
src/events/views.py Normal file
View File

@ -0,0 +1,143 @@
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import timezone
from .forms import submit_flag
from .models import Event, Scores
from ctfs.models import CTF, CTF_flags
from django.utils.translation import get_language
def get_description_by_lang(ctf):
lang = get_language()
ret = None
if lang == "fr":
ret = ctf.description
elif lang == "en":
ret = ctf.description_en
elif lang == "de":
ret = ctf.description_de
elif lang == "ru":
ret = ctf.description_ru
return ret
# Create your views here.
def events(request):
list_events = Event.objects.filter().order_by('-end_date', 'start_date')
return render(request, 'events/events_list.html', {'events' : list_events, 'curdate': timezone.now()})
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 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('/')
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})
def event(request, event_slug):
event_info = get_object_or_404(Event, slug=event_slug)
IsRegistered = False
if request.user.is_authenticated:
userScore = Scores.objects.filter(event=event_info, user=request.user)
if userScore:
IsRegistered = True
if event_info.password:
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})
else:
return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': False})
ended = False
if timezone.now() >= event_info.end_date:
ended = True
begun = False
if timezone.now() >= event_info.start_date:
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})
@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'
return response
if request.method == 'POST':
ctf_info = CTF.objects.get(event=ev, slug=chall_slug)
if not ctf_info:
response['Location'] += '?ChallengeNotFound'
return response
flagged = False
if CTF_flags.objects.filter(user=request.user, ctf=ctf_info):
flagged = True
response['Location'] += '?AlreadyFlagged'
return response
try:
score = Scores.objects.get(user=request.user, event=ev)
except:
score = None
if score:
form = submit_flag(data=request.POST)
if flagged == False and form.is_valid():
if ctf_info.flag == request.POST.get('flag'):
new = CTF_flags(user = request.user, ctf = ctf_info, flag_date = timezone.now())
new.save()
score.last_submission_date = timezone.now()
score.score += ctf_info.points
score.save()
response['Location'] += '?Congrat'
return response
else:
response['Location'] += '?WrongFlag'
return response
else:
response['Location'] += '?ErrorInForm'
return response
return response
@login_required
def submit_pwd(request, event_slug):
response = redirect('events:event_info', event_slug=event_slug)
if request.method == 'POST':
if request.user.is_authenticated:
ev = get_object_or_404(Event, slug=event_slug)
if ev == False:
response['Location'] += '?NoEventFound'
return response
if request.POST.get('password') != ev.password:
response['Location'] += '?WrongPassword'
return response
if Scores.objects.filter(user=request.user, event=ev).exists():
response['Location'] += '?AlreadyRegistered'
return response
else:
new = Scores(user=request.user, event=ev, score=0)
new.save()
return redirect('events:event_info', event_slug=event_slug)
@login_required
def subscribe_to_event(request, event_slug):
response = redirect('events:event_info', event_slug=event_slug)
if request.method == 'POST':
if request.user.is_authenticated:
ev = get_object_or_404(Event, slug=event_slug)
if ev == False:
response['Location'] += '?NoEventFound'
return response
if timezone.now() >= ev.end_date:
response['Location'] += '?SubscriptionIsOver'
return response
if Scores.objects.filter(user=request.user, event=ev).exists():
response['Location'] += '?AlreadyRegistered'
return response
else:
new = Scores(user=request.user, event=ev, score=0)
new.save()
return redirect('events:event_info', event_slug=event_slug)

View File

@ -32,7 +32,7 @@ def home(request):
response = HttpResponseRedirect(url_translated)
return response
news = new.objects.order_by('-pub_date')[:5]
latest_ctfs = CTF.objects.order_by('-pub_date')[:5]
latest_ctfs = CTF.objects.filter(event=None).order_by('-pub_date')[:5]
top10 = UserProfileInfo.objects.select_related().order_by('-score', 'last_submission_date', 'user__username')[:10]
nb_flags = CTF_flags.objects.count()
nb_users = UserProfileInfo.objects.count()

View File

@ -33,6 +33,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'home.apps.HomeConfig',
'ctfs.apps.CtfsConfig',
'events.apps.EventsConfig',
'accounts.apps.AccountsConfig',
'scoreboard.apps.ScoreboardConfig',
'django.contrib.sites',

View File

@ -32,5 +32,6 @@ urlpatterns += i18n_patterns(
re_path('^accounts/login/', defaults.page_not_found, {'exception': Exception()}),
path('accounts/', include('accounts.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('scoreboard/', include('scoreboard.urls'))
path('scoreboard/', include('scoreboard.urls')),
path('events/', include('events.urls'))
)

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;}
@ -41,9 +43,25 @@ 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;}
.bg-success {
background-color: #d9d9d9 !important;color: #000;
}
.event-card {
background-color: #1d1d1d;
min-height: 50vh;
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%;}

View File

@ -57,6 +57,10 @@
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'scoreboard:scoreboard' %}">{% translate "Scoreboard" %}</a>
<li class="nav-item">
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'events:events' %}">{% translate "Events" %}</a>
</li>
</ul>
<ul class="navbar-nav ">
@ -109,3 +113,4 @@
</body>
</html>