From dac078f7dbf5d6cebd286eb62370f124cc934790 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Mon, 11 Oct 2021 12:55:46 +0200 Subject: [PATCH 1/8] Add Django-AllAuth app --- photo21/settings.py | 17 ++++++++++++++++- photo21/urls.py | 3 +-- requirements.txt | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/photo21/settings.py b/photo21/settings.py index df7257a..fefc612 100644 --- a/photo21/settings.py +++ b/photo21/settings.py @@ -41,6 +41,9 @@ INSTALLED_APPS = [ 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', 'crispy_forms', 'photologue_custom', 'photologue', @@ -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' @@ -168,7 +179,11 @@ SESSION_COOKIE_AGE = 60 * 60 * 3 # Use only one Django Sites SITE_ID = 1 -# use Bootstrap forms +# Allauth configuration +ACCOUNT_EMAIL_REQUIRED = True +ACCOUNT_EMAIL_VERIFICATION = "mandatory" + +# Use Bootstrap forms CRISPY_TEMPLATE_PACK = 'bootstrap4' # Photologue diff --git a/photo21/urls.py b/photo21/urls.py index 311d17b..d3ffe9d 100644 --- a/photo21/urls.py +++ b/photo21/urls.py @@ -25,8 +25,7 @@ urlpatterns = [ path('', IndexView.as_view(), name='index'), path('photologue/', include('photologue_custom.urls')), path('photologue/', include('photologue.urls', namespace='photologue')), - path('accounts/', include('django.contrib.auth.urls')), - path('accounts/', include('accounts.urls')), + path('accounts/', include('allauth.urls')), path('i18n/', include('django.conf.urls.i18n')), path('admin/', admin.site.urls), path('admin/doc/', include('django.contrib.admindocs.urls')), diff --git a/requirements.txt b/requirements.txt index 64cb7df..9dc17a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Django~=2.2.20 django-photologue~=3.13 django-taggit>=0.24.0 django-crispy-forms~=1.7 +django-allauth>=0.44 From 403002812e42042af12853e764b476303ec3fb97 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Mon, 11 Oct 2021 12:56:30 +0200 Subject: [PATCH 2/8] Update AllAuth templates --- accounts/templates/accounts/registration.html | 20 --------- photo21/templates/account/base.html | 13 ++++++ photo21/templates/account/login.html | 45 +++++++++++++++++++ photo21/templates/account/signup.html | 26 +++++++++++ photo21/templates/base.html | 16 +++++-- .../templates/registration/logged_out.html | 17 ------- photo21/templates/registration/login.html | 40 ----------------- .../registration/password_change_done.html | 16 ------- .../registration/password_change_form.html | 20 --------- .../registration/password_reset_complete.html | 19 -------- .../registration/password_reset_confirm.html | 26 ----------- .../registration/password_reset_done.html | 17 ------- .../registration/password_reset_form.html | 22 --------- 13 files changed, 97 insertions(+), 200 deletions(-) delete mode 100644 accounts/templates/accounts/registration.html create mode 100644 photo21/templates/account/base.html create mode 100644 photo21/templates/account/login.html create mode 100644 photo21/templates/account/signup.html delete mode 100644 photo21/templates/registration/logged_out.html delete mode 100644 photo21/templates/registration/login.html delete mode 100644 photo21/templates/registration/password_change_done.html delete mode 100644 photo21/templates/registration/password_change_form.html delete mode 100644 photo21/templates/registration/password_reset_complete.html delete mode 100644 photo21/templates/registration/password_reset_confirm.html delete mode 100644 photo21/templates/registration/password_reset_done.html delete mode 100644 photo21/templates/registration/password_reset_form.html 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/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..c170ee5 --- /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 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 %}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..c01eac0 100644 --- a/photo21/templates/base.html +++ b/photo21/templates/base.html @@ -43,7 +43,17 @@ SPDX-License-Identifier: GPL-3.0-or-later From 0c9aae7e66b9aef8e10393751fedf0b28056a8c2 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Mon, 11 Oct 2021 13:40:34 +0200 Subject: [PATCH 5/8] Authorize login by email --- photo21/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/photo21/settings.py b/photo21/settings.py index 903d7d2..1fcfcec 100644 --- a/photo21/settings.py +++ b/photo21/settings.py @@ -193,6 +193,7 @@ SITE_ID = 1 # Allauth configuration ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_VERIFICATION = "mandatory" +ACCOUNT_AUTHENTICATION_METHOD = "username_email" # Use Bootstrap forms CRISPY_TEMPLATE_PACK = 'bootstrap4' From 49bf9465d76644947da7b88091467168359548db Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Mon, 11 Oct 2021 13:46:19 +0200 Subject: [PATCH 6/8] Show Django messages --- photo21/settings.py | 10 ++++++++++ photo21/templates/base.html | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/photo21/settings.py b/photo21/settings.py index 1fcfcec..3dcdc22 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__))) @@ -190,6 +191,15 @@ SESSION_COOKIE_AGE = 60 * 60 * 3 # Use only one Django Sites SITE_ID = 1 +# 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" diff --git a/photo21/templates/base.html b/photo21/templates/base.html index 2b48942..2bc7a99 100644 --- a/photo21/templates/base.html +++ b/photo21/templates/base.html @@ -87,6 +87,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
+ {% for message in messages %} + + {% endfor %} {% block content %}

Default content...

{% endblock %} From 5728b9a18e560981211c760272c3f0c1b923df2e Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Mon, 11 Oct 2021 13:49:11 +0200 Subject: [PATCH 7/8] Account button --- photo21/locale/fr/LC_MESSAGES/django.po | 26 +++++++++++-------------- photo21/templates/base.html | 10 ++++------ 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/photo21/locale/fr/LC_MESSAGES/django.po b/photo21/locale/fr/LC_MESSAGES/django.po index 7c65869..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-11 11:21+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,19 +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`." -#: photo21/settings.py:143 +#: photo21/settings.py:144 msgid "German" msgstr "" -#: photo21/settings.py:144 +#: photo21/settings.py:145 msgid "English" msgstr "" -#: photo21/settings.py:145 +#: photo21/settings.py:146 msgid "Spanish" msgstr "" -#: photo21/settings.py:146 +#: photo21/settings.py:147 msgid "French" msgstr "" @@ -158,23 +158,19 @@ msgstr "Galeries" msgid "Manage" msgstr "Gestion" -#: photo21/templates/base.html:47 -msgid "Change E-mail" -msgstr "" +#: photo21/templates/base.html:50 +msgid "Account" +msgstr "Compte" -#: photo21/templates/base.html:52 -msgid "Social connections" -msgstr "" - -#: photo21/templates/base.html:61 +#: photo21/templates/base.html:59 msgid "Log out" msgstr "" -#: photo21/templates/base.html:71 +#: photo21/templates/base.html:69 msgid "Log in" msgstr "" -#: photo21/templates/base.html:80 +#: photo21/templates/base.html:78 msgid "Sign up" msgstr "Inscription" diff --git a/photo21/templates/base.html b/photo21/templates/base.html index 2bc7a99..97ecbb8 100644 --- a/photo21/templates/base.html +++ b/photo21/templates/base.html @@ -44,12 +44,10 @@ SPDX-License-Identifier: GPL-3.0-or-later {% if request.user.is_authenticated %} -