|
|
|
@ -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'] |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|