Check email address domain when signing up
This commit is contained in:
parent
5728b9a18e
commit
f992c88152
6 changed files with 11 additions and 48 deletions
25
photo21/forms.py
Normal file
25
photo21/forms.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from allauth.account.forms import SignupForm
|
||||
|
||||
|
||||
class CustomSignupForm(SignupForm):
|
||||
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 `@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
|
||||
|
|
@ -48,7 +48,6 @@ INSTALLED_APPS = [
|
|||
'crispy_forms',
|
||||
'photologue_custom',
|
||||
'photologue',
|
||||
'accounts',
|
||||
'sortedm2m',
|
||||
'taggit',
|
||||
]
|
||||
|
|
@ -204,6 +203,7 @@ MESSAGE_TAGS = {
|
|||
ACCOUNT_EMAIL_REQUIRED = True
|
||||
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
|
||||
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
|
||||
ACCOUNT_FORMS = {'signup': 'photo21.forms.CustomSignupForm'}
|
||||
|
||||
# Use Bootstrap forms
|
||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue