Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to hide the intermediary logout page #1922

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions {{cookiecutter.project_slug}}/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
},
},
Expand Down Expand Up @@ -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
# ------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
{% 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 #}
<script>document.getElementsByClassName('container')[0].style.display = 'none';</script>
{% endif %}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The document might have multiple container so if there is another container (e.g. in the header) this script will fail. I would suggest wrapping the form in a div

<div style='display:none'>
<form ...> </form>
</div>

instead.

<h1>{% trans "Sign Out" %}</h1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you indeed use a display:none div, this can be left out of the div and becomes something like

<h1>{% trans "Signing Out" %}</h1>

so that users can see a Sinning Out message instead of a blank page.


<p>{% trans 'Are you sure you want to sign out?' %}</p>

<form method="post" action="{% url 'account_logout' %}">
<form id="form-logout" method="post" action="{% url 'account_logout' %}">
{% csrf_token %}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
{% endif %}
<button class="btn btn-danger" type="submit">{% trans 'Sign Out' %}</button>
</form>

{% if ACCOUNT_HIDE_INTERMEDIARY_LOGOUT %}
{# submit form automatically #}
<script>document.getElementById('form-logout').submit();</script>
{% endif %}

{% endblock %}
{% endraw %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf import settings


def expose_settings(request):
# expose any necessary settings
return {
'ACCOUNT_HIDE_INTERMEDIARY_LOGOUT': settings.ACCOUNT_HIDE_INTERMEDIARY_LOGOUT
}