diff --git a/accounts/forms.py b/accounts/forms.py index 3b34969..d11c888 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -1,13 +1,31 @@ from django import forms from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User +from django.utils.translation import gettext_lazy as _ class RegistrationForm(UserCreationForm): - email = forms.EmailField(label="Email", widget=forms.TextInput(), required=True) - first_name = forms.CharField(label="Prénom", widget=forms.TextInput(), required=True) - last_name = forms.CharField(label="Nom", widget=forms.TextInput(), required=True) + email = forms.EmailField( + label=_("Email address"), + widget=forms.TextInput(), + required=True, + help_text=_( + "Please enter a valid email address ending with `@crans.org` or " + "`@ens-paris-saclay.fr`." + ), + ) + + def clean_email(self): + """ + Check that the email address ends with a trusted domain. + """ + email = self.cleaned_data.get("email") + if not email.endswith("@crans.org") and not email.endswith("@ens-paris-saclay.fr"): + raise forms.ValidationError( + _("Must end with `@crans.org` or `@ens-paris-saclay.fr`.") + ) + return email class Meta: model = User - fields = ["username", "password1", "password2", "email", "first_name", "last_name"] + fields = ["username", "password1", "password2", "email"] diff --git a/accounts/templates/accounts/registration.html b/accounts/templates/accounts/registration.html index c62b66e..ba48e03 100644 --- a/accounts/templates/accounts/registration.html +++ b/accounts/templates/accounts/registration.html @@ -1,9 +1,20 @@ {% extends "base.html" %} +{% comment %} +SPDX-License-Identifier: GPL-2.0-or-later +{% endcomment %} +{% load i18n crispy_forms_tags %} +{% block title %}{% trans "Sign up" %}{% endblock %} + {% block content %} -
{% trans "Please enter your new password twice so we can verify you typed it in correctly." %}
{% else %}diff --git a/photo21/templates/registration/password_reset_form.html b/photo21/templates/registration/password_reset_form.html index f419ff7..9a6a15c 100644 --- a/photo21/templates/registration/password_reset_form.html +++ b/photo21/templates/registration/password_reset_form.html @@ -2,7 +2,7 @@ {% comment %} SPDX-License-Identifier: GPL-3.0-or-later {% endcomment %} -{% load i18n %} +{% load i18n crispy_forms_tags %} {% block content %}