improve registering stuff

online_registration
Raz 12 months ago
parent ed0dfedd61
commit 4db29063cf
  1. 10
      tournaments/forms.py
  2. 11
      tournaments/static/tournaments/css/style.css
  3. 23
      tournaments/templates/register_tournament.html
  4. 26
      tournaments/templates/registration/login.html
  5. 2
      tournaments/templates/registration/profile.html
  6. 15
      tournaments/templates/registration/signup.html
  7. 4
      tournaments/templates/tournaments/acc_active_email.html
  8. 20
      tournaments/templates/tournaments/tournament_info.html
  9. 86
      tournaments/views.py

@ -96,6 +96,16 @@ class AddPlayerForm(forms.Form):
self.cleaned_data['last_name'] = last_name self.cleaned_data['last_name'] = last_name
return last_name return last_name
def clean_first_name(self):
first_name = self.cleaned_data.get('first_name')
# Convert to capitalize
first_name = first_name.capitalize()
# Update the cleaned_data with the modified licence_id
self.cleaned_data['first_name'] = first_name
return first_name
def clean(self): def clean(self):
cleaned_data = super().clean() cleaned_data = super().clean()

@ -689,3 +689,14 @@ h-margin {
.right-content { .right-content {
margin-left: auto; margin-left: auto;
} }
.styled-link {
text-decoration: underline; /* Ensures the link is underlined */
color: #f39200; /* Use your main color variable if defined */
font-weight: bold; /* Optional: To make the link more prominent */
}
.styled-link:hover {
color: #f39200; /* Optional: Define a hover color */
text-decoration: none; /* Optional: Remove underline on hover */
}

@ -54,17 +54,34 @@
<!-- Add Player Form --> <!-- Add Player Form -->
{% if current_players|length < 2 %} {% if current_players|length < 2 %}
<div> <div>
{% if user_without_licence %}
<div class="semibold">
Une licence est obligatoire pour vous inscrire :
</div>
{% endif %}
{{ add_player_form.licence_id.label_tag }} {{ add_player_form.licence_id.label_tag }}
{{ add_player_form.licence_id }} {{ add_player_form.licence_id }}
{% if add_player_form.first_tournament %} {% if add_player_form.first_tournament or user_without_licence %}
Précisez les informations du joueur : {% if not user_without_licence %}
<div class="semibold">
Précisez les informations du joueur :
</div>
{% endif %}
{{ add_player_form.first_name.label_tag }} {{ add_player_form.first_name.label_tag }}
{{ add_player_form.first_name }} {{ add_player_form.first_name }}
{{ add_player_form.last_name.label_tag }} {{ add_player_form.last_name.label_tag }}
{{ add_player_form.last_name }} {{ add_player_form.last_name }}
{% endif %} {% endif %}
<button type="submit" name="add_player" class="button">Ajouter un joueur</button> <button type="submit" name="add_player" class="button">
{% if user_without_licence %}
Ajouter-vous à l'équipe
{% else %}
Ajouter un partenaire
{% endif %}
</button>
</div> </div>
{% endif %} {% endif %}

@ -1,30 +1,32 @@
<!-- templates/registration/login.html --> <!-- templates/registration/login.html -->
{% extends 'tournaments/base.html' %} {% extends 'tournaments/base.html' %}
{% block head_title %} {% endblock %} {% block head_title %} Connexion {% endblock %}
{% block first_title %}{% endblock %} {% block first_title %} Padel Club {% endblock %}
{% block second_title %}{% endblock %} {% block second_title %} Connexion {% endblock %}
{% block content %} {% block content %}
{% load static %} {% load static %}
{% load tz %} {% load tz %}
<div class="grid-x"> <div class="grid-x">
<div class="bubble">
<div class="cell medium-6 large-6 my-block"> <div class="cell medium-6 large-6 my-block">
<form method="post" action="{% url 'login' %}"> <form method="post" action="{% url 'login' %}">
{% csrf_token %} {% csrf_token %}
<label for="username">Username:</label> <input type="hidden" name="next" value="{{ request.GET.next }}">
<input type="text" name="username" id="username" value="{{ pre_login_username }}" required> <label for="username">Identifiant ou e-mail </label>
<input type="text" name="username" id="username" required>
<label for="password">Password:</label> <label for="password">Mot de passe :</label>
<input type="password" name="password" id="password" value="{{ pre_login_password }}" required> <input type="password" name="password" id="password" required>
<button type="submit" class="button">Se connecter</button> <button type="submit" class="button">Se connecter</button>
</form> </form>
<p>Pas encore de compte ? <a href="{% url 'signup' %}"">Créer le tout de suite !</a>.</p> <p>Pas encore de compte ? <a href="{% url 'signup' %}" class="styled-link">Créer le tout de suite !</a></p>
</div> </div>
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">{{ message }}</div>
{% endfor %}
</div>
</div> </div>
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">{{ message }}</div>
{% endfor %}
{% endblock %} {% endblock %}

@ -1,7 +1,7 @@
{% extends 'tournaments/base.html' %} {% extends 'tournaments/base.html' %}
{% block head_title %} Mon Compte {% endblock %} {% block head_title %} Mon Compte {% endblock %}
{% block first_title %} Mon Compte Padel Club {% endblock %} {% block first_title %} Mon Compte Padel Club {% endblock %}
{% block second_title %} Mes tournois {% endblock %} {% block second_title %} {{ user.user_name }} {% endblock %}
{% block content %} {% block content %}

@ -1,13 +1,15 @@
<!-- templates/registration/signup.html --> <!-- templates/registration/signup.html -->
{% extends 'tournaments/base.html' %} {% extends 'tournaments/base.html' %}
{% block first_title %}{% endblock %} {% block head_title %} Création de compte {% endblock %}
{% block second_title %}{% endblock %} {% block first_title %} Padel Club {% endblock %}
{% block second_title %} Création de compte {% endblock %}
{% block content %} {% block content %}
{% load static %} {% load static %}
{% load tz %} {% load tz %}
<div class="grid-x"> <div class="grid-x">
<div class="bubble">
<div class="cell medium-6 large-6 my-block"> <div class="cell medium-6 large-6 my-block">
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
@ -15,10 +17,11 @@
<button type="submit" class="button">Créer votre compte</button> <button type="submit" class="button">Créer votre compte</button>
</form> </form>
</div> </div>
</div>
{% for message in messages %} {% for message in messages %}
<div class="alert alert-{{ message.tags }}">{{ message }}</div> <div class="alert alert-{{ message.tags }}">{{ message }}</div>
{% endfor %} {% endfor %}
</div>
</div>
{% endblock %} {% endblock %}

@ -2,10 +2,10 @@
Bienvenue {{ user.username }} ! Bienvenue {{ user.username }} !
Veuillez cliquer sur le lien suivant pour activer votre compte: Veuillez cliquer sur le lien suivant pour activer votre compte:
padelclub://{{ domain }}{% url 'activate' uidb64=uid token=token %} padelclub://{{ domain }}{% url 'activate' uidb64=uid token=token %}?next={{ next }}
Si le lien ne marche pas, cliquer ici : Si le lien ne marche pas, cliquer ici :
http://{{ domain }}{% url 'activate' uidb64=uid token=token %} http://{{ domain }}{% url 'activate' uidb64=uid token=token %}?next={{ next }}
Une fois votre compte activé, connectez-vous dans l'app. Une fois votre compte activé, connectez-vous dans l'app.

@ -46,11 +46,29 @@
</div> </div>
</p> </p>
{% if user.is_authenticated and user.is_active %}
<p> <p>
<div> <div>
<a href="{% url 'register_tournament' tournament.id %}?reset=true" class="button">S'inscrire</a> <a href="{% url 'register_tournament' tournament.id %}" class="button">S'inscrire</a>
</div> </div>
</p> </p>
{% else %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">{{ message }}</div>
{% endfor %}
<p>
<div>
Vous avez besoin d'un compte Padel Club pour pouvoir vous inscrire en ligne.
<a href="{% url 'signup' %}?next={{ request.path }}" class="styled-link">Créer le tout de suite !</a>
</div>
</p>
{% endif %}
{% endif %} {% endif %}
</div> </div>

@ -358,7 +358,8 @@ def activate(request, uidb64, token):
user.is_active = True user.is_active = True
user.save() user.save()
login(request, user) login(request, user)
return redirect('index') # Redirect to the homepage or any other page you prefer next_url = request.GET.get('next', '/')
return redirect(next_url)
else: else:
return HttpResponse('Le lien est invalide.') return HttpResponse('Le lien est invalide.')
@ -529,6 +530,9 @@ def send_email(mail, name):
@csrf_exempt @csrf_exempt
def signup(request): def signup(request):
next_url = request.GET.get('next', '/') # Get the 'next' parameter from the request
print('next_url', next_url)
if request.method == 'POST': if request.method == 'POST':
form = SimpleCustomUserCreationForm(request.POST) form = SimpleCustomUserCreationForm(request.POST)
if form.is_valid(): if form.is_valid():
@ -537,26 +541,28 @@ def signup(request):
user.save() user.save()
# Send verification email # Send verification email
send_verification_email(request, user) send_verification_email(request, user, next_url)
request.session['pre_login_username'] = user.username
request.session['pre_login_password'] = user.password # Store hashed password, or handle with caution
messages.success(request, "Votre compte a été créé ! Veuillez vérifier votre e-mail pour confirmer votre compte.") messages.success(request, "Votre compte a été créé ! Veuillez vérifier votre e-mail pour confirmer votre compte.")
return redirect('login') # Redirect to login page or a custom message page return redirect(next_url) # Redirect directly to the 'next' URL
else: else:
form = SimpleCustomUserCreationForm() form = SimpleCustomUserCreationForm()
return render(request, 'registration/signup.html', {'form': form}) return render(request, 'registration/signup.html', {'form': form})
def send_verification_email(request, user): def send_verification_email(request, user, next_url):
print('next_url', next_url)
current_site = get_current_site(request) current_site = get_current_site(request)
mail_subject = 'Activez votre compte Padel Club !' mail_subject = 'Activez votre compte Padel Club !'
# Prepare the email subject and message
message = render_to_string('tournaments/acc_active_email.html', { message = render_to_string('tournaments/acc_active_email.html', {
'user': user, 'user': user,
'domain': current_site.domain, 'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user), 'token': account_activation_token.make_token(user),
'next': next_url, # Pass next URL to the template
}) })
email = EmailMessage(mail_subject, message, to=[user.email]) email = EmailMessage(mail_subject, message, to=[user.email])
email.send() email.send()
@ -599,21 +605,23 @@ def register_tournament(request, tournament_id):
registration_successful = False # Flag for registration status registration_successful = False # Flag for registration status
team_form = None team_form = None
add_player_form = None add_player_form = None
if 'user_without_licence' not in request.session:
request.session['user_without_licence'] = False
user_without_licence = request.session['user_without_licence']
# Process forms # Process forms
if request.method == 'POST': if request.method == 'POST':
team_form = TournamentRegistrationForm(request.POST) team_form = TournamentRegistrationForm(request.POST)
add_player_form = AddPlayerForm(request.POST)
# Check if the add player form is submitted # Check if the add player form is submitted
add_player_form = AddPlayerForm(request.POST)
if 'add_player' in request.POST and add_player_form.is_valid(): if 'add_player' in request.POST and add_player_form.is_valid():
player_data = add_player_form.cleaned_data player_data = add_player_form.cleaned_data
# Validate the license ID before adding the player # Validate the license ID before adding the player
licence_id = player_data['licence_id'].upper() licence_id = player_data['licence_id'].upper()
# Instantiate your custom validator and validate the license ID # Instantiate your custom validator and validate the license ID
validator = LicenseValidator(licence_id) validator = LicenseValidator(licence_id)
if validator.validate_license() is False: if validator.validate_license() is False:
messages.error(request, f"Le numéro de licence est invalide, la lettre ne correspond pas. {validator.computed_license_key}") messages.error(request, f"Le numéro de licence est invalide, la lettre ne correspond pas. {validator.computed_license_key}")
return render(request, 'register_tournament.html', { return render(request, 'register_tournament.html', {
@ -622,34 +630,43 @@ def register_tournament(request, tournament_id):
'tournament': tournament, 'tournament': tournament,
'registration_successful': registration_successful, 'registration_successful': registration_successful,
'current_players': request.session['team_registration'], 'current_players': request.session['team_registration'],
'user_without_licence': user_without_licence
}) })
# Check if the player with the same licence_id already exists in the session # Check if the player with the same licence_id already exists in the session
existing_players = [player['licence_id'] for player in request.session['team_registration']] existing_players = [player['licence_id'] for player in request.session['team_registration']]
if licence_id in existing_players: if licence_id in existing_players:
messages.error(request, 'This player is already added to the team.') messages.error(request, "Ce joueur est déjà dans l'équipe.")
return render(request, 'register_tournament.html', { return render(request, 'register_tournament.html', {
'team_form': team_form, 'team_form': team_form,
'add_player_form': add_player_form, 'add_player_form': add_player_form,
'tournament': tournament, 'tournament': tournament,
'registration_successful': registration_successful, 'registration_successful': registration_successful,
'current_players': request.session['team_registration'], 'current_players': request.session['team_registration'],
'user_without_licence': user_without_licence
}) })
else: else:
# Check if a PlayerRegistration with the same licence_id already exists in the database # Check if a PlayerRegistration with the same licence_id already exists in the database
stripped_license = validator.stripped_license stripped_license = validator.stripped_license
if validate_license_id(stripped_license, tournament): if validate_license_id(stripped_license, tournament):
messages.error(request, 'A player with this licence ID is already registered in a team.') messages.error(request, "Un joueur avec ce numéro de licence est déjà inscrit dans une équipe.")
return render(request, 'register_tournament.html', { return render(request, 'register_tournament.html', {
'team_form': team_form, 'team_form': team_form,
'add_player_form': add_player_form, 'add_player_form': add_player_form,
'tournament': tournament, 'tournament': tournament,
'registration_successful': registration_successful, 'registration_successful': registration_successful,
'current_players': request.session['team_registration'], 'current_players': request.session['team_registration'],
'user_without_licence': user_without_licence
}) })
elif add_player_form.names_is_valid(): elif add_player_form.names_is_valid():
add_player_form = AddPlayerForm()
request.session['team_registration'].append(player_data) request.session['team_registration'].append(player_data)
if request.user.licence_id is None:
request.session['user_without_licence'] = False
request.user.licence_id = validator.computed_licence_id
request.user.save()
request.session.modified = True # Ensure session is updated request.session.modified = True # Ensure session is updated
else: else:
if add_player_form.first_tournament is False: if add_player_form.first_tournament is False:
# Retrieve player names from the CSV file # Retrieve player names from the CSV file
@ -661,6 +678,7 @@ def register_tournament(request, tournament_id):
# If validation passes, add the player to the session without clearing previous ones # If validation passes, add the player to the session without clearing previous ones
request.session['team_registration'].append(player_data) request.session['team_registration'].append(player_data)
request.session.modified = True # Ensure session is updated request.session.modified = True # Ensure session is updated
add_player_form = AddPlayerForm()
else: else:
add_player_form.first_tournament = True add_player_form.first_tournament = True
@ -702,43 +720,57 @@ def register_tournament(request, tournament_id):
request.session['team_registration'] = [] request.session['team_registration'] = []
registration_successful = True registration_successful = True
else: else:
add_player_form = AddPlayerForm()
request.session['team_registration'] = [] request.session['team_registration'] = []
user_licence_id = request.user.licence_id
initial_data = {} initial_data = {}
player_data = {}
# Add the authenticated user to the session as the first player if not already added # Add the authenticated user to the session as the first player if not already added
if request.user.is_authenticated: if request.user.is_authenticated:
initial_data = { initial_data = {
'email': request.user.email, 'email': request.user.email,
'phone': request.user.phone, 'phone': request.user.phone,
} }
existing_players = [player['licence_id'] for player in request.session['team_registration']]
if request.user.licence_id not in existing_players: if user_licence_id is not None:
# Add the authenticated user as the first player in the session validator = LicenseValidator(user_licence_id)
existing_players = [player['licence_id'] for player in request.session['team_registration']]
if user_licence_id not in existing_players:
# Add the authenticated user as the first player in the session
player_data = {
'first_name': request.user.first_name,
'last_name': request.user.last_name.upper(),
'email': request.user.email,
'phone': request.user.phone,
'licence_id': validator.computed_licence_id
}
first_name, last_name, rank = get_player_name_from_csv(user_licence_id)
if first_name and last_name and rank:
player_data['rank'] = rank
request.session['team_registration'].insert(0, player_data) # Add them as the first player
request.session.modified = True # Ensure session is updated
else:
player_data = { player_data = {
'first_name': request.user.first_name, 'first_name': request.user.first_name,
'last_name': request.user.last_name.upper(), 'last_name': request.user.last_name.upper(),
'email': request.user.email,
'phone': request.user.phone,
'licence_id': request.user.licence_id,
} }
add_player_form = AddPlayerForm(initial=player_data)
first_name, last_name, rank = get_player_name_from_csv(request.user.licence_id) request.session['user_without_licence'] = True
if first_name and last_name and rank:
validator = LicenseValidator(request.user.licence_id)
player_data['licence_id'] = validator.computed_licence_id
player_data['rank'] = rank
request.session['team_registration'].insert(0, player_data) # Add them as the first player
request.session.modified = True # Ensure session is updated request.session.modified = True # Ensure session is updated
user_without_licence = True
team_form = TournamentRegistrationForm(initial=initial_data) team_form = TournamentRegistrationForm(initial=initial_data)
add_player_form = AddPlayerForm()
return render(request, 'register_tournament.html', { return render(request, 'register_tournament.html', {
'team_form': team_form, 'team_form': team_form,
'add_player_form': add_player_form, 'add_player_form': add_player_form,
'tournament': tournament, 'tournament': tournament,
'registration_successful': registration_successful, 'registration_successful': registration_successful,
'current_players': request.session['team_registration'], 'current_players': request.session['team_registration'],
'user_without_licence': request.session['user_without_licence']
}) })

Loading…
Cancel
Save