From 4db29063cf05d9c1379d89d8f8f71d2bf68874bd Mon Sep 17 00:00:00 2001 From: Raz Date: Fri, 15 Nov 2024 15:33:02 +0100 Subject: [PATCH] improve registering stuff --- tournaments/forms.py | 10 +++ tournaments/static/tournaments/css/style.css | 11 +++ .../templates/register_tournament.html | 23 ++++- tournaments/templates/registration/login.html | 26 +++--- .../templates/registration/profile.html | 2 +- .../templates/registration/signup.html | 15 ++-- .../tournaments/acc_active_email.html | 4 +- .../tournaments/tournament_info.html | 20 ++++- tournaments/views.py | 86 +++++++++++++------ 9 files changed, 145 insertions(+), 52 deletions(-) diff --git a/tournaments/forms.py b/tournaments/forms.py index 49895d9..34d2a36 100644 --- a/tournaments/forms.py +++ b/tournaments/forms.py @@ -96,6 +96,16 @@ class AddPlayerForm(forms.Form): self.cleaned_data['last_name'] = 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): cleaned_data = super().clean() diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css index 202669b..51e96dd 100644 --- a/tournaments/static/tournaments/css/style.css +++ b/tournaments/static/tournaments/css/style.css @@ -689,3 +689,14 @@ h-margin { .right-content { 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 */ +} diff --git a/tournaments/templates/register_tournament.html b/tournaments/templates/register_tournament.html index af45377..fd477dc 100644 --- a/tournaments/templates/register_tournament.html +++ b/tournaments/templates/register_tournament.html @@ -54,17 +54,34 @@ {% if current_players|length < 2 %}
+ + {% if user_without_licence %} +
+ Une licence est obligatoire pour vous inscrire : +
+ {% endif %} + {{ add_player_form.licence_id.label_tag }} {{ add_player_form.licence_id }} - {% if add_player_form.first_tournament %} - Précisez les informations du joueur : + {% if add_player_form.first_tournament or user_without_licence %} + {% if not user_without_licence %} +
+ Précisez les informations du joueur : +
+ {% endif %} {{ add_player_form.first_name.label_tag }} {{ add_player_form.first_name }} {{ add_player_form.last_name.label_tag }} {{ add_player_form.last_name }} {% endif %} - +
{% endif %} diff --git a/tournaments/templates/registration/login.html b/tournaments/templates/registration/login.html index 6e4e449..ab2e224 100644 --- a/tournaments/templates/registration/login.html +++ b/tournaments/templates/registration/login.html @@ -1,30 +1,32 @@ {% extends 'tournaments/base.html' %} -{% block head_title %} {% endblock %} -{% block first_title %}{% endblock %} -{% block second_title %}{% endblock %} +{% block head_title %} Connexion {% endblock %} +{% block first_title %} Padel Club {% endblock %} +{% block second_title %} Connexion {% endblock %} {% block content %} {% load static %} {% load tz %}
+
{% csrf_token %} - - + + + - - + +
-

Pas encore de compte ? Créer le tout de suite !.

+

Pas encore de compte ? Créer le tout de suite !

+ {% for message in messages %} +
{{ message }}
+ {% endfor %} +
- -{% for message in messages %} -
{{ message }}
-{% endfor %} {% endblock %} diff --git a/tournaments/templates/registration/profile.html b/tournaments/templates/registration/profile.html index 842435f..e1d2c5b 100644 --- a/tournaments/templates/registration/profile.html +++ b/tournaments/templates/registration/profile.html @@ -1,7 +1,7 @@ {% extends 'tournaments/base.html' %} {% block head_title %} Mon Compte {% endblock %} {% block first_title %} Mon Compte Padel Club {% endblock %} -{% block second_title %} Mes tournois {% endblock %} +{% block second_title %} {{ user.user_name }} {% endblock %} {% block content %} diff --git a/tournaments/templates/registration/signup.html b/tournaments/templates/registration/signup.html index 6f5d96f..7cdcee6 100644 --- a/tournaments/templates/registration/signup.html +++ b/tournaments/templates/registration/signup.html @@ -1,13 +1,15 @@ {% extends 'tournaments/base.html' %} -{% block first_title %}{% endblock %} -{% block second_title %}{% endblock %} +{% block head_title %} Création de compte {% endblock %} +{% block first_title %} Padel Club {% endblock %} +{% block second_title %} Création de compte {% endblock %} {% block content %} {% load static %} {% load tz %}
+
{% csrf_token %} @@ -15,10 +17,11 @@
-
-{% for message in messages %} -
{{ message }}
-{% endfor %} + {% for message in messages %} +
{{ message }}
+ {% endfor %} +
+ {% endblock %} diff --git a/tournaments/templates/tournaments/acc_active_email.html b/tournaments/templates/tournaments/acc_active_email.html index 9a7d516..bd85592 100644 --- a/tournaments/templates/tournaments/acc_active_email.html +++ b/tournaments/templates/tournaments/acc_active_email.html @@ -2,10 +2,10 @@ Bienvenue {{ user.username }} ! 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 : -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. diff --git a/tournaments/templates/tournaments/tournament_info.html b/tournaments/templates/tournaments/tournament_info.html index fd03226..abde129 100644 --- a/tournaments/templates/tournaments/tournament_info.html +++ b/tournaments/templates/tournaments/tournament_info.html @@ -46,11 +46,29 @@

+ {% if user.is_authenticated and user.is_active %} +

- S'inscrire + S'inscrire

+ {% else %} + + {% for message in messages %} +
{{ message }}
+ {% endfor %} + +

+

+ Vous avez besoin d'un compte Padel Club pour pouvoir vous inscrire en ligne. + Créer le tout de suite ! +
+

+ {% endif %} + + + {% endif %} diff --git a/tournaments/views.py b/tournaments/views.py index 7ddf151..490ed09 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -358,7 +358,8 @@ def activate(request, uidb64, token): user.is_active = True user.save() 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: return HttpResponse('Le lien est invalide.') @@ -529,6 +530,9 @@ def send_email(mail, name): @csrf_exempt 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': form = SimpleCustomUserCreationForm(request.POST) if form.is_valid(): @@ -537,26 +541,28 @@ def signup(request): user.save() # Send verification email - send_verification_email(request, user) - request.session['pre_login_username'] = user.username - request.session['pre_login_password'] = user.password # Store hashed password, or handle with caution + send_verification_email(request, user, next_url) 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: form = SimpleCustomUserCreationForm() 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) mail_subject = 'Activez votre compte Padel Club !' + # Prepare the email subject and message message = render_to_string('tournaments/acc_active_email.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), '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.send() @@ -599,21 +605,23 @@ def register_tournament(request, tournament_id): registration_successful = False # Flag for registration status team_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 if request.method == 'POST': team_form = TournamentRegistrationForm(request.POST) - add_player_form = AddPlayerForm(request.POST) # 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(): player_data = add_player_form.cleaned_data - # Validate the license ID before adding the player licence_id = player_data['licence_id'].upper() # Instantiate your custom validator and validate the license ID validator = LicenseValidator(licence_id) - 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}") return render(request, 'register_tournament.html', { @@ -622,34 +630,43 @@ def register_tournament(request, tournament_id): 'tournament': tournament, 'registration_successful': registration_successful, '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 existing_players = [player['licence_id'] for player in request.session['team_registration']] 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', { 'team_form': team_form, 'add_player_form': add_player_form, 'tournament': tournament, 'registration_successful': registration_successful, 'current_players': request.session['team_registration'], + 'user_without_licence': user_without_licence }) else: # Check if a PlayerRegistration with the same licence_id already exists in the database stripped_license = validator.stripped_license 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', { 'team_form': team_form, 'add_player_form': add_player_form, 'tournament': tournament, 'registration_successful': registration_successful, 'current_players': request.session['team_registration'], + 'user_without_licence': user_without_licence }) elif add_player_form.names_is_valid(): + add_player_form = AddPlayerForm() 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 + else: if add_player_form.first_tournament is False: # 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 request.session['team_registration'].append(player_data) request.session.modified = True # Ensure session is updated + add_player_form = AddPlayerForm() else: add_player_form.first_tournament = True @@ -702,43 +720,57 @@ def register_tournament(request, tournament_id): request.session['team_registration'] = [] registration_successful = True else: + add_player_form = AddPlayerForm() + request.session['team_registration'] = [] + user_licence_id = request.user.licence_id initial_data = {} + player_data = {} + # Add the authenticated user to the session as the first player if not already added if request.user.is_authenticated: initial_data = { 'email': request.user.email, '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: - # Add the authenticated user as the first player in the session + + if user_licence_id is not None: + 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 = { 'first_name': request.user.first_name, 'last_name': request.user.last_name.upper(), - 'email': request.user.email, - 'phone': request.user.phone, - 'licence_id': request.user.licence_id, } - - first_name, last_name, rank = get_player_name_from_csv(request.user.licence_id) - 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 + add_player_form = AddPlayerForm(initial=player_data) + request.session['user_without_licence'] = True request.session.modified = True # Ensure session is updated + user_without_licence = True team_form = TournamentRegistrationForm(initial=initial_data) - add_player_form = AddPlayerForm() - return render(request, 'register_tournament.html', { 'team_form': team_form, 'add_player_form': add_player_form, 'tournament': tournament, 'registration_successful': registration_successful, 'current_players': request.session['team_registration'], + 'user_without_licence': request.session['user_without_licence'] })