photo26/photo21/forms.py
krek0 b57f9092aa
All checks were successful
Docker / build (release) Successful in 8s
Add display name (first_name) shown instead of username on user-facing UI
2026-05-17 07:11:37 +02:00

40 lines
1.2 KiB
Python

# This file is part of photo21
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from allauth.account.forms import SignupForm
from django import forms
from django.utils.translation import gettext_lazy as _
class CustomSignupForm(SignupForm):
first_name = forms.CharField(
label=_("Display name"),
max_length=150,
required=True,
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Add description on email field
self.fields["email"].help_text = _(
"Please enter a valid email address ending with `@ens-rennes.fr`"
)
def save(self, request):
user = super().save(request)
user.first_name = self.cleaned_data["first_name"]
user.save()
return user
def clean_email(self):
"""
Check that the email address ends with a trusted domain.
"""
email = super().clean_email()
if not email.endswith("@ens-rennes.fr"):
raise forms.ValidationError(
_("Must end with `@ens-rennes.fr`.")
)
return email