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
|
|
@ -1,5 +0,0 @@
|
||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class Accounts(AppConfig):
|
|
||||||
name = 'accounts'
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
from django.urls import path
|
|
||||||
|
|
||||||
from .views import signup
|
|
||||||
urlpatterns = [
|
|
||||||
path('registration/', signup, name='registration'),
|
|
||||||
]
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
from django.contrib.auth import login
|
|
||||||
from django.shortcuts import redirect, render
|
|
||||||
|
|
||||||
from .forms import RegistrationForm
|
|
||||||
|
|
||||||
|
|
||||||
def signup(request):
|
|
||||||
if request.method == 'POST':
|
|
||||||
form = RegistrationForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
user = form.save()
|
|
||||||
user.first_name = form.cleaned_data.get('first_name')
|
|
||||||
user.last_name = form.cleaned_data.get('last_name')
|
|
||||||
user.email = form.cleaned_data.get('email')
|
|
||||||
login(request, user)
|
|
||||||
return redirect('/')
|
|
||||||
return render(request, 'accounts/registration.html', {'form': form})
|
|
||||||
else:
|
|
||||||
form = RegistrationForm()
|
|
||||||
return render(request, 'accounts/registration.html', {'form': form})
|
|
||||||
|
|
@ -1,18 +1,16 @@
|
||||||
from django import forms
|
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 _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from allauth.account.forms import SignupForm
|
||||||
|
|
||||||
|
|
||||||
class RegistrationForm(UserCreationForm):
|
class CustomSignupForm(SignupForm):
|
||||||
email = forms.EmailField(
|
def __init__(self, *args, **kwargs):
|
||||||
label=_("Email address"),
|
super().__init__(*args, **kwargs)
|
||||||
widget=forms.TextInput(),
|
|
||||||
required=True,
|
# Add description on email field
|
||||||
help_text=_(
|
self.fields["email"].help_text = _(
|
||||||
"Please enter a valid email address ending with `@crans.org` or "
|
"Please enter a valid email address ending with `@crans.org` or "
|
||||||
"`@ens-paris-saclay.fr`."
|
"`@ens-paris-saclay.fr`."
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def clean_email(self):
|
def clean_email(self):
|
||||||
|
|
@ -25,7 +23,3 @@ class RegistrationForm(UserCreationForm):
|
||||||
_("Must end with `@crans.org` or `@ens-paris-saclay.fr`.")
|
_("Must end with `@crans.org` or `@ens-paris-saclay.fr`.")
|
||||||
)
|
)
|
||||||
return email
|
return email
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = User
|
|
||||||
fields = ["username", "password1", "password2", "email"]
|
|
||||||
|
|
@ -48,7 +48,6 @@ INSTALLED_APPS = [
|
||||||
'crispy_forms',
|
'crispy_forms',
|
||||||
'photologue_custom',
|
'photologue_custom',
|
||||||
'photologue',
|
'photologue',
|
||||||
'accounts',
|
|
||||||
'sortedm2m',
|
'sortedm2m',
|
||||||
'taggit',
|
'taggit',
|
||||||
]
|
]
|
||||||
|
|
@ -204,6 +203,7 @@ MESSAGE_TAGS = {
|
||||||
ACCOUNT_EMAIL_REQUIRED = True
|
ACCOUNT_EMAIL_REQUIRED = True
|
||||||
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
|
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
|
||||||
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
|
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
|
||||||
|
ACCOUNT_FORMS = {'signup': 'photo21.forms.CustomSignupForm'}
|
||||||
|
|
||||||
# Use Bootstrap forms
|
# Use Bootstrap forms
|
||||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||||
|
|
|
||||||
4
tox.ini
4
tox.ini
|
|
@ -18,7 +18,7 @@ deps =
|
||||||
-r{toxinidir}/requirements.txt
|
-r{toxinidir}/requirements.txt
|
||||||
coverage
|
coverage
|
||||||
commands =
|
commands =
|
||||||
coverage run --omit='photo21/wsgi.py' --source=photo21,photologue_custom,accounts ./manage.py test
|
coverage run --omit='photo21/wsgi.py' --source=photo21,photologue_custom ./manage.py test
|
||||||
coverage report -m
|
coverage report -m
|
||||||
|
|
||||||
[testenv:linters]
|
[testenv:linters]
|
||||||
|
|
@ -32,7 +32,7 @@ deps =
|
||||||
pep8-naming
|
pep8-naming
|
||||||
pyflakes
|
pyflakes
|
||||||
commands =
|
commands =
|
||||||
flake8 photo21 photologue_custom accounts
|
flake8 photo21 photologue_custom
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
ignore = W503, I100, I101
|
ignore = W503, I100, I101
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue