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/templates/accounts/registration.html b/accounts/templates/accounts/registration.html deleted file mode 100644 index ba48e03..0000000 --- a/accounts/templates/accounts/registration.html +++ /dev/null @@ -1,20 +0,0 @@ -{% 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 "Sign up" %} -

-
-
{% csrf_token %} - {{ form|crispy }} - -
-
-
-{% endblock %} \ No newline at end of file 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/locale/fr/LC_MESSAGES/django.po b/photo21/locale/fr/LC_MESSAGES/django.po index c10a3f4..9dba126 100644 --- a/photo21/locale/fr/LC_MESSAGES/django.po +++ b/photo21/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-08 11:03+0000\n" +"POT-Creation-Date: 2021-10-11 11:48+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -34,25 +34,19 @@ msgstr "" msgid "Must end with `@crans.org` or `@ens-paris-saclay.fr`." msgstr "Doit finir par `@crans.org` ou `@ens-paris-saclay.fr`." -#: accounts/templates/accounts/registration.html:6 -#: accounts/templates/accounts/registration.html:11 -#: photo21/templates/base.html:70 -msgid "Sign up" -msgstr "Inscription" - -#: photo21/settings.py:132 +#: photo21/settings.py:144 msgid "German" msgstr "" -#: photo21/settings.py:133 +#: photo21/settings.py:145 msgid "English" msgstr "" -#: photo21/settings.py:134 +#: photo21/settings.py:146 msgid "Spanish" msgstr "" -#: photo21/settings.py:135 +#: photo21/settings.py:147 msgid "French" msgstr "" @@ -100,6 +94,58 @@ msgid "" "soon. You can now drink a beer." msgstr "" +#: photo21/templates/account/login.html:6 +#: photo21/templates/account/login.html:11 +#: photo21/templates/account/login.html:39 +msgid "Sign In" +msgstr "" + +#: photo21/templates/account/login.html:16 +#, python-format +msgid "" +"Please sign in with one of your existing third party accounts. Or, sign up for a %(site_name)s account and sign in below:" +msgstr "" +"Veuillez vous connectez avec un de vos comptes existants. Sinon, inscrivez-vous pour un compte sur %(site_name)s et " +"identifiez-vous ci-dessous :" + +#: photo21/templates/account/login.html:24 +msgid "or" +msgstr "" + +#: photo21/templates/account/login.html:30 +#, python-format +msgid "" +"If you have not created an account yet, then please sign up first." +msgstr "" +"Si vous n'avez pas déjà créé de compte, veuillez vous inscrire." + +#: photo21/templates/account/login.html:40 +msgid "Forgot Password?" +msgstr "" + +#: photo21/templates/account/login.html:44 +msgid "If any problem, please contact the server owners at" +msgstr "En cas de problème, contactez les administrateurs à" + +#: photo21/templates/account/signup.html:6 +msgid "Signup" +msgstr "" + +#: photo21/templates/account/signup.html:11 +#: photo21/templates/account/signup.html:22 +msgid "Sign Up" +msgstr "" + +#: photo21/templates/account/signup.html:14 +#, python-format +msgid "" +"Already have an account? Then please sign in." +msgstr "" + #: photo21/templates/base.html:12 msgid "The ENS Paris-Saclay pictures server." msgstr "" @@ -109,106 +155,29 @@ msgid "Galleries" msgstr "Galeries" #: photo21/templates/base.html:39 -msgid "Admin" -msgstr "" +msgid "Manage" +msgstr "Gestion" -#: photo21/templates/base.html:51 +#: photo21/templates/base.html:50 +msgid "Account" +msgstr "Compte" + +#: photo21/templates/base.html:59 msgid "Log out" msgstr "" -#: photo21/templates/base.html:61 photo21/templates/registration/login.html:6 -#: photo21/templates/registration/login.html:11 -#: photo21/templates/registration/login.html:33 -#: photo21/templates/registration/password_reset_complete.html:15 +#: photo21/templates/base.html:69 msgid "Log in" msgstr "" +#: photo21/templates/base.html:78 +msgid "Sign up" +msgstr "Inscription" + #: photo21/templates/index.html:53 msgid "Connected as" msgstr "Connecté en tant que" -#: photo21/templates/registration/logged_out.html:13 -msgid "Thanks for spending some quality time with the Web site today." -msgstr "" - -#: photo21/templates/registration/logged_out.html:14 -msgid "Log in again" -msgstr "" - -#: photo21/templates/registration/login.html:16 -#, python-format -msgid "" -"You are authenticated as %(username)s, but are not authorized to access this " -"page. Would you like to login to a different account?" -msgstr "" - -#: photo21/templates/registration/login.html:25 -msgid "" -"You must be logged with a staff account with the higher mask to access " -"Django Admin." -msgstr "" - -#: photo21/templates/registration/login.html:35 -msgid "Forgotten your password or username?" -msgstr "" - -#: photo21/templates/registration/login.html:39 -msgid "If any problem, please contact the server owners at" -msgstr "En cas de problème, contactez les administrateurs à" - -#: photo21/templates/registration/password_change_done.html:13 -msgid "Your password was changed." -msgstr "" - -#: photo21/templates/registration/password_change_form.html:14 -msgid "" -"Please enter your old password, for security's sake, and then enter your new " -"password twice so we can verify you typed it in correctly." -msgstr "" - -#: photo21/templates/registration/password_change_form.html:16 -#: photo21/templates/registration/password_reset_confirm.html:17 -msgid "Change my password" -msgstr "" - -#: photo21/templates/registration/password_reset_complete.html:13 -msgid "Your password has been set. You may go ahead and log in now." -msgstr "" - -#: photo21/templates/registration/password_reset_confirm.html:14 -msgid "" -"Please enter your new password twice so we can verify you typed it in " -"correctly." -msgstr "" - -#: photo21/templates/registration/password_reset_confirm.html:21 -msgid "" -"The password reset link was invalid, possibly because it has already been " -"used. Please request a new password reset." -msgstr "" - -#: photo21/templates/registration/password_reset_done.html:13 -msgid "" -"We've emailed you instructions for setting your password, if an account " -"exists with the email you entered. You should receive them shortly." -msgstr "" - -#: photo21/templates/registration/password_reset_done.html:14 -msgid "" -"If you don't receive an email, please make sure you've entered the address " -"you registered with, and check your spam folder." -msgstr "" - -#: photo21/templates/registration/password_reset_form.html:13 -msgid "" -"Forgotten your password? Enter your email address below, and we'll email " -"instructions for setting a new one." -msgstr "" - -#: photo21/templates/registration/password_reset_form.html:18 -msgid "Reset my password" -msgstr "" - #: photologue_custom/templates/photologue/gallery_archive.html:4 #: photologue_custom/templates/photologue/gallery_archive.html:9 msgid "Latest photo galleries" diff --git a/photo21/settings.py b/photo21/settings.py index df7257a..ed6fa19 100644 --- a/photo21/settings.py +++ b/photo21/settings.py @@ -13,6 +13,7 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ import os from django.utils.translation import gettext_lazy as _ +from django.contrib.messages import constants as messages # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -41,10 +42,12 @@ INSTALLED_APPS = [ 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', 'crispy_forms', 'photologue_custom', 'photologue', - 'accounts', 'sortedm2m', 'taggit', ] @@ -81,6 +84,14 @@ TEMPLATES = [ }, ] +AUTHENTICATION_BACKENDS = [ + # Needed to login by username in Django admin, regardless of `allauth` + 'django.contrib.auth.backends.ModelBackend', + + # `allauth` specific authentication methods, such as login by e-mail + 'allauth.account.auth_backends.AuthenticationBackend', +] + WSGI_APPLICATION = 'photo21.wsgi.application' @@ -155,6 +166,17 @@ LOCALE_PATHS = [os.path.join(BASE_DIR, 'photo21/locale')] FIXTURE_DIRS = [os.path.join(BASE_DIR, 'note_kfet/fixtures')] +# Email settings +if DEBUG: + EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +else: + EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +EMAIL_USE_SSL = os.getenv('EMAIL_USE_SSL', False) +EMAIL_HOST = os.getenv('EMAIL_HOST', 'smtp.crans.org') +EMAIL_PORT = os.getenv('EMAIL_PORT', 25) +EMAIL_HOST_USER = os.getenv('EMAIL_USER', None) +EMAIL_HOST_PASSWORD = os.getenv('EMAIL_PASSWORD', None) + # Mail will be sent from this address SERVER_EMAIL = "photos@crans.org" DEFAULT_FROM_EMAIL = f"Serveur photos <{SERVER_EMAIL}>" @@ -168,7 +190,22 @@ SESSION_COOKIE_AGE = 60 * 60 * 3 # Use only one Django Sites SITE_ID = 1 -# use Bootstrap forms +# Django message +MESSAGE_TAGS = { + messages.DEBUG: 'alert-secondary', + messages.INFO: 'alert-info', + messages.SUCCESS: 'alert-success', + messages.WARNING: 'alert-warning', + messages.ERROR: 'alert-danger', +} + +# Allauth configuration +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' # Photologue diff --git a/photo21/templates/account/base.html b/photo21/templates/account/base.html new file mode 100644 index 0000000..b166325 --- /dev/null +++ b/photo21/templates/account/base.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} +{% comment %} +SPDX-License-Identifier: GPL-2.0-or-later +{% endcomment %} + +{% block title %}{% block head_title %}{% endblock %}{% endblock title %} + +{% block extracss %} + +{% endblock %} \ No newline at end of file diff --git a/photo21/templates/account/login.html b/photo21/templates/account/login.html new file mode 100644 index 0000000..02422ce --- /dev/null +++ b/photo21/templates/account/login.html @@ -0,0 +1,45 @@ +{% extends "account/base.html" %} +{% comment %} +SPDX-License-Identifier: GPL-2.0-or-later +{% endcomment %} +{% load i18n crispy_forms_tags account socialaccount %} +{% block head_title %}{% trans "Sign In" %}{% endblock %} + +{% block content %} +
+

+ {% trans "Sign In" %} +

+
+ {% get_providers as socialaccount_providers %} + {% if socialaccount_providers %} +

{% blocktrans trimmed with site.name as site_name %}Please sign in with one + of your existing third party accounts. Or, sign up + for a {{ site_name }} account and sign in below:{% endblocktrans %}

+ +
+
    + {% include "socialaccount/snippets/provider_list.html" with process="login" %} +
+ +
+ + {% include "socialaccount/snippets/login_extra.html" %} + + {% else %} +

{% blocktrans trimmed %}If you have not created an account yet, then please + sign up first.{% endblocktrans %}

+ {% endif %} + +
{% csrf_token %} + {{ form|crispy }} + {% if redirect_field_value %} + + {% endif %} + + {% trans "Forgot Password?" %} +
+
+
+

{% trans "If any problem, please contact the server owners at" %} photos[at]crans.org.

+{% endblock %} diff --git a/photo21/templates/account/signup.html b/photo21/templates/account/signup.html new file mode 100644 index 0000000..16df347 --- /dev/null +++ b/photo21/templates/account/signup.html @@ -0,0 +1,26 @@ +{% extends "account/base.html" %} +{% comment %} +SPDX-License-Identifier: GPL-2.0-or-later +{% endcomment %} +{% load i18n crispy_forms_tags %} +{% block head_title %}{% trans "Signup" %}{% endblock %} + +{% block content %} +
+

+ {% trans "Sign Up" %} +

+
+

{% blocktrans %}Already have an account? Then please sign in.{% endblocktrans %}

+ + +
+
+{% endblock %} diff --git a/photo21/templates/base.html b/photo21/templates/base.html index d863a89..97ecbb8 100644 --- a/photo21/templates/base.html +++ b/photo21/templates/base.html @@ -36,14 +36,22 @@ SPDX-License-Identifier: GPL-3.0-or-later {% if request.user.is_staff %} {% endif %}