From 7080d589230966518311b7fd76bbfd755daf07e7 Mon Sep 17 00:00:00 2001 From: Will Gordon Date: Thu, 31 Jan 2019 14:55:00 -0500 Subject: [PATCH] Add setting to hide the intermediary logout page --- CHANGELOG.md | 5 +++++ docs/settings.rst | 2 ++ .../config/settings/base.py | 6 ++++++ .../templates/account/logout.html | 12 +++++++++++- .../users/context_processors.py | 8 ++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/context_processors.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 304732b9f1b..71a6d409ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All enhancements and patches to Cookiecutter Django will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [2019-01-31] +### Added +- Added `DJANGO_ACCOUNT_HIDE_INTERMEDIARY_LOGOUT` environment variable to hide the intermediary logout form and instead auto-submit via JavaScript + + ## [2018-02-16] ### Changed - Upgraded to Django 2.0 (@epicwhale) diff --git a/docs/settings.rst b/docs/settings.rst index 26b161a093d..fea951edb79 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -57,3 +57,5 @@ Other Environment Settings DJANGO_ACCOUNT_ALLOW_REGISTRATION (=True) Allow enable or disable user registration through `django-allauth` without disabling other characteristics like authentication and account management. (Django Setting: ACCOUNT_ALLOW_REGISTRATION) +DJANGO_ACCOUNT_HIDE_INTERMEDIARY_LOGOUT (=False) + Hide the intermediary logout form and instead auto-submit via JavaScript. This degrades back to using the form in case JavaScript is disabled. (Django Setting: ACCOUNT_ALLOW_REGISTRATION) diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index 950b9ed7fa5..abdbb6a9639 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -195,6 +195,7 @@ 'django.template.context_processors.static', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', + '{{cookiecutter.project_slug}}.users.context_processors.expose_settings', ], }, }, @@ -275,6 +276,11 @@ # https://django-allauth.readthedocs.io/en/latest/configuration.html SOCIALACCOUNT_ADAPTER = '{{cookiecutter.project_slug}}.users.adapters.SocialAccountAdapter' +# Configuration options +# ------------------------------------------------------------------------------ +# https://cookiecutter-django.readthedocs.io/en/latest/settings.html#other-environment-settings +ACCOUNT_HIDE_INTERMEDIARY_LOGOUT = env.bool('DJANGO_ACCOUNT_HIDE_INTERMEDIARY_LOGOUT', False) + {% if cookiecutter.use_compressor == 'y' -%} # django-compressor # ------------------------------------------------------------------------------ diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/logout.html b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/logout.html index baa8183c97e..2fcfc7ed1ac 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/logout.html +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/logout.html @@ -5,11 +5,17 @@ {% block head_title %}{% trans "Sign Out" %}{% endblock %} {% block inner %} + +{% if ACCOUNT_HIDE_INTERMEDIARY_LOGOUT %} + {# Hide form - prevents user confusion by seeing an auto-submitting form #} + +{% endif %} +

{% trans "Sign Out" %}

{% trans 'Are you sure you want to sign out?' %}

-
+ {% csrf_token %} {% if redirect_field_value %} @@ -17,6 +23,10 @@

{% trans "Sign Out" %}

+{% if ACCOUNT_HIDE_INTERMEDIARY_LOGOUT %} + {# submit form automatically #} + +{% endif %} {% endblock %} {% endraw %} diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/context_processors.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/context_processors.py new file mode 100644 index 00000000000..9e93ddff5bf --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/context_processors.py @@ -0,0 +1,8 @@ +from django.conf import settings + + +def exposed_settings(request): + # expose any necessary settings + return { + 'ACCOUNT_HIDE_INTERMEDIARY_LOGOUT': settings.ACCOUNT_HIDE_INTERMEDIARY_LOGOUT + }