forked from 42CTF/website
Compare commits
No commits in common. "7b9dfad15d2cd78f9861275679a7d8129158e013" and "87efa03ed0ec9b612f7114806cb039d7682f2d71" have entirely different histories.
7b9dfad15d
...
87efa03ed0
|
@ -2,40 +2,42 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<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">
|
<div class="ctf-block">
|
||||||
<div class="ctf-head">
|
<div class="ctf-head">
|
||||||
<h3>Register</h3>
|
<h3>Register</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="ctf-body sign-body">
|
|
||||||
<div class="col-sm-8 col-md-6 mx-auto">
|
<div class="ctf-body sign-body">
|
||||||
{% if registered %}
|
<div class="col-sm-8 col-md-6 mx-auto">
|
||||||
<h1>{% trans "Welcome !" %}</h1>
|
{% if registered %}
|
||||||
<span class="message success-msg">{% trans "Your account has been created." %}</span>
|
<h1>{% trans "Welcome !" %}</h1>
|
||||||
{% else %}
|
<span class="message success-msg">{% trans "Your account has been created." %}</span>
|
||||||
{% if registered_failed %}
|
{% else %}
|
||||||
<span class="message error-msg">{{ registered_failed }}</span>
|
{% if registered_failed %}
|
||||||
{% endif %}
|
<span class="message error-msg">{{ registered_failed }}</span>
|
||||||
<form enctype="multipart/form-data" method="POST">
|
{% endif %}
|
||||||
{% csrf_token %}
|
<form enctype="multipart/form-data" method="POST">
|
||||||
<div class="form-group">
|
{% csrf_token %}
|
||||||
<input class="form-control" type="text" name="username" placeholder="{% trans "Username" %} *" maxlength="150" required="" id="id_username" value="{{ old_username }}"></br>
|
<div class="form-group">
|
||||||
<input class="form-control" type="password" name="password" placeholder="{% trans "Password" %} *" required="" id="id_password"></br>
|
<input class="form-control" type="text" name="username" placeholder="{% trans "Username" %} *" maxlength="150" required="" id="id_username" value="{{ old_username }}"></br>
|
||||||
<input class="form-control" type="email" name="email" placeholder="pleasedontgivemy@private.infos*" required="" maxlength="254" id="id_email" value="{{ old_email }}"></br>
|
<input class="form-control" type="password" name="password" placeholder="{% trans "Password" %} *" required="" id="id_password"></br>
|
||||||
<input class="form-control" type="url" name="portfolio_site" placeholder="{% trans "Personal website" %}"maxlength="200" id="id_portfolio_site" value="{{ old_website }}"></br>
|
<input class="form-control" type="email" name="email" placeholder="pleasedontgivemy@private.infos*" required="" maxlength="254" id="id_email" value="{{ old_email }}"></br>
|
||||||
<input type="submit" name="" class="form-control" value="{% trans "Register" %}">
|
<input class="form-control" type="url" name="portfolio_site" placeholder="{% trans "Personal website" %}"maxlength="200" id="id_portfolio_site" value="{{ old_website }}"></br>
|
||||||
</div>
|
<input type="submit" name="" class="form-control" value="{% trans "Register" %}">
|
||||||
</form>
|
</div>
|
||||||
{% endif %}
|
</form>
|
||||||
</div>
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-3 right-sidebar">
|
|
||||||
<ul class="list-group">
|
<div class="col-sm-12 col-md-3 right-sidebar">
|
||||||
<a href="/accounts/signup" class="list-group-item">{% trans "Sign up" %}</a>
|
<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>
|
||||||
</ul>
|
<a href="/accounts/signin" class="list-group-item">{% trans "Login" %}</a>
|
||||||
</div>
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ def profile(request, user_name):
|
||||||
for s in solves.reverse():
|
for s in solves.reverse():
|
||||||
somme += s.ctf.points
|
somme += s.ctf.points
|
||||||
solved.append([s.flag_date.timestamp() * 1000,somme])
|
solved.append([s.flag_date.timestamp() * 1000,somme])
|
||||||
created = CTF.objects.filter(author=user_obj, event=None)
|
created = CTF.objects.filter(author=user_obj)
|
||||||
return render(request,'accounts/profile.html', {'user':user_obj, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas,
|
return render(request,'accounts/profile.html', {'user':user_obj, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas,
|
||||||
'rank': rank, 'score' : somme, 'member' : member, 'cats':cats, 'created':created})
|
'rank': rank, 'score' : somme, 'member' : member, 'cats':cats, 'created':created})
|
||||||
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
# Generated by Django 3.2.11 on 2022-05-30 07:30
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('accounts', '0011_migration_campus'),
|
|
||||||
('events', '0009_auto_20220215_1706'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='event',
|
|
||||||
name='campus',
|
|
||||||
field=models.ManyToManyField(blank=True, to='accounts.Campus'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -2,7 +2,6 @@ from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.models import timezone
|
from django.contrib.auth.models import timezone
|
||||||
import uuid
|
import uuid
|
||||||
from accounts.models import Campus
|
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
|
@ -18,7 +17,6 @@ class Event(models.Model):
|
||||||
team_size = models.PositiveIntegerField(default=1)
|
team_size = models.PositiveIntegerField(default=1)
|
||||||
auto_match = models.BooleanField(default=False)
|
auto_match = models.BooleanField(default=False)
|
||||||
dynamic = models.BooleanField(default=False)
|
dynamic = models.BooleanField(default=False)
|
||||||
campus = models.ManyToManyField(Campus, blank=True)
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -30,7 +28,7 @@ class Team(models.Model):
|
||||||
last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now)
|
last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now)
|
||||||
auto = models.BooleanField(default=False)
|
auto = models.BooleanField(default=False)
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class EventPlayer(models.Model):
|
class EventPlayer(models.Model):
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
|
|
@ -8,38 +8,22 @@
|
||||||
<h3>{{ event.name }}</h3>
|
<h3>{{ event.name }}</h3>
|
||||||
<small>{% trans "This event start at" %} : {{ event.start_date }}</small>
|
<small>{% trans "This event start at" %} : {{ event.start_date }}</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ctf-footer">
|
<div class="ctf-footer">
|
||||||
{% if logged == True %}
|
{% if logged == True %}
|
||||||
{% if userHasCampus == False %}
|
{% if wrongpwd == True %}
|
||||||
<span class="message error-msg">
|
<span class="message error-msg">{% trans "Wrong password submited." %}</span>
|
||||||
{% trans "This event is reserved for one or more 42 campuses. If you have not connected your intranet to 42CTF, you can do so with this button: " %}
|
|
||||||
<form action="{% url 'accounts:connections-connect-intra42' %}" method='POST' class="form-inline p-2">
|
|
||||||
{%csrf_token%}
|
|
||||||
<button class="btn btn-dark" type="submit">{% trans "Connect 42" %}</button>
|
|
||||||
</form>
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if campusCanJoin == False %}
|
{% if alreadyregistered == True %}
|
||||||
<span class="message error-msg">
|
<span class="message error-msg">{% trans "You're already registered to this event." %}</span>
|
||||||
{% trans "This event is reserved for one or more 42 campuses. And unfortunately your campus can't participate. Do not hesitate to contact us to organize an event on your campus!" %}
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
{% if userHasCampus == True and campusCanJoin == 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>
|
|
||||||
<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>
|
|
||||||
{% endif %}
|
{% 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 %}
|
{% else %}
|
||||||
<h4>{% trans "You need to be logged to access this event." %}</h4>
|
<h4>{% trans "You need to be logged to access this event." %}</h4>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -51,7 +35,7 @@
|
||||||
<li class="list-group-item">{{ event.name }}</li>
|
<li class="list-group-item">{{ event.name }}</li>
|
||||||
<li class="list-group-item">{% trans "Starts at" %} : {{ event.start_date | date:'H:i d-m-y'}}</li>
|
<li class="list-group-item">{% trans "Starts at" %} : {{ event.start_date | date:'H:i d-m-y'}}</li>
|
||||||
<li class="list-group-item">{% trans "Ends at" %} : {{ event.end_date | date:'H:i d-m-y'}}</li>
|
<li class="list-group-item">{% trans "Ends at" %} : {{ event.end_date | date:'H:i d-m-y'}}</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,7 +4,6 @@ from django.contrib.auth.models import timezone
|
||||||
from ..forms import submit_flag
|
from ..forms import submit_flag
|
||||||
from ..models import Event, EventPlayer, Team
|
from ..models import Event, EventPlayer, Team
|
||||||
from ctfs.models import CTF, CTF_flags, Category
|
from ctfs.models import CTF, CTF_flags, Category
|
||||||
from accounts.models import UserProfileInfo
|
|
||||||
from django.utils.translation import get_language
|
from django.utils.translation import get_language
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
@ -110,23 +109,13 @@ def event(request, event_slug):
|
||||||
player = None
|
player = None
|
||||||
if player:
|
if player:
|
||||||
IsRegistered = True
|
IsRegistered = True
|
||||||
if event_info.campus.all():
|
|
||||||
if request.user.is_authenticated:
|
|
||||||
if request.user.is_staff is False:
|
|
||||||
user = UserProfileInfo.objects.get(user=request.user)
|
|
||||||
if user.campus is None:
|
|
||||||
return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': True, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered, 'userHasCampus': False, 'campusCanJoin': True})
|
|
||||||
elif user.campus not in event_info.campus.all():
|
|
||||||
return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': True, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered, 'userHasCampus': True, 'campusCanJoin': False})
|
|
||||||
else:
|
|
||||||
return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': False, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered, 'userHasCampus': True, 'campusCanJoin': True})
|
|
||||||
if event_info.password:
|
if event_info.password:
|
||||||
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 player:
|
if not player:
|
||||||
return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': True, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered, 'userHasCampus': True, 'campusCanJoin': 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, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered, 'userHasCampus': True, 'campusCanJoin': True})
|
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
|
||||||
|
@ -138,7 +127,7 @@ def event(request, event_slug):
|
||||||
solved_list = EventPlayer.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'user__username')
|
solved_list = EventPlayer.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'user__username')
|
||||||
else:
|
else:
|
||||||
solved_list = Team.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'name')
|
solved_list = Team.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'name')
|
||||||
return render(request, 'events/event_info.html', {'event' : event_info, 'IsRegistered': IsRegistered, 'ctfs': challenges, 'solved_list':solved_list,
|
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})
|
'ended': ended, 'begun': begun, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered, 'subisover': subisover})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -156,12 +145,12 @@ def submit_event_flag(request, event_slug, chall_slug):
|
||||||
if not ctf_info:
|
if not ctf_info:
|
||||||
response['Location'] += '?ChallengeNotFound=1'
|
response['Location'] += '?ChallengeNotFound=1'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
try:
|
try:
|
||||||
player = EventPlayer.objects.get(event=ev, user=request.user)
|
player = EventPlayer.objects.get(event=ev, user=request.user)
|
||||||
except:
|
except:
|
||||||
player = None
|
player = None
|
||||||
|
|
||||||
if player:
|
if player:
|
||||||
if ev.team_size > 1 and player.team is None:
|
if ev.team_size > 1 and player.team is None:
|
||||||
response['Location'] += '?NoTeam=1'
|
response['Location'] += '?NoTeam=1'
|
||||||
|
@ -230,7 +219,7 @@ def submit_pwd(request, event_slug):
|
||||||
new = EventPlayer(user=request.user, event=ev)
|
new = EventPlayer(user=request.user, event=ev)
|
||||||
new.save()
|
new.save()
|
||||||
return redirect('events:event_info', event_slug=event_slug)
|
return redirect('events:event_info', event_slug=event_slug)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def register_to_event(request, event_slug):
|
def register_to_event(request, event_slug):
|
||||||
|
|
Loading…
Reference in New Issue