diff --git a/accounts/apps.py b/accounts/apps.py deleted file mode 100644 index c0bd956..0000000 --- a/accounts/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class Accounts(AppConfig): - name = 'accounts' diff --git a/accounts/urls.py b/accounts/urls.py deleted file mode 100644 index 445f6aa..0000000 --- a/accounts/urls.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.urls import path - -from .views import signup -urlpatterns = [ - path('registration/', signup, name='registration'), -] diff --git a/accounts/views.py b/accounts/views.py deleted file mode 100644 index df26fd4..0000000 --- a/accounts/views.py +++ /dev/null @@ -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}) diff --git a/accounts/forms.py b/photo21/forms.py similarity index 60% rename from accounts/forms.py rename to photo21/forms.py index d11c888..3ab1880 100644 --- a/accounts/forms.py +++ b/photo21/forms.py @@ -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"] diff --git a/photo21/settings.py b/photo21/settings.py index 3dcdc22..ed6fa19 100644 --- a/photo21/settings.py +++ b/photo21/settings.py @@ -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' diff --git a/tox.ini b/tox.ini index 03d6b2a..30d8c12 100644 --- a/tox.ini +++ b/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