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,19 +1,17 @@
|
|||
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 allauth.account.forms import SignupForm
|
||||
|
||||
|
||||
class RegistrationForm(UserCreationForm):
|
||||
email = forms.EmailField(
|
||||
label=_("Email address"),
|
||||
widget=forms.TextInput(),
|
||||
required=True,
|
||||
help_text=_(
|
||||
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):
|
||||
"""
|
||||
|
|
@ -25,7 +23,3 @@ class RegistrationForm(UserCreationForm):
|
|||
_("Must end with `@crans.org` or `@ens-paris-saclay.fr`.")
|
||||
)
|
||||
return email
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["username", "password1", "password2", "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'
|
||||
|
|
|
|||
4
tox.ini
4
tox.ini
|
|
@ -18,7 +18,7 @@ deps =
|
|||
-r{toxinidir}/requirements.txt
|
||||
coverage
|
||||
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
|
||||
|
||||
[testenv:linters]
|
||||
|
|
@ -32,7 +32,7 @@ deps =
|
|||
pep8-naming
|
||||
pyflakes
|
||||
commands =
|
||||
flake8 photo21 photologue_custom accounts
|
||||
flake8 photo21 photologue_custom
|
||||
|
||||
[flake8]
|
||||
ignore = W503, I100, I101
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue