Hides 'sign up' elements when ACCOUNT_ALLOW_REGISTRATION is disabled (#1914)

Co-authored-by: Bruno Alla <alla.brunoo@gmail.com>
This commit is contained in:
Will Gordon 2021-12-27 06:37:33 -05:00 committed by GitHub
parent c007f46dbe
commit 785df85c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 16 deletions

View File

@ -197,6 +197,7 @@ TEMPLATES = [
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"{{cookiecutter.project_slug}}.users.context_processors.allauth_settings",
],
},
}

View File

@ -13,25 +13,37 @@
{% get_providers as socialaccount_providers %}
{% if socialaccount_providers %}
<p>{% blocktranslate with site.name as site_name %}Please sign in with one
of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
for a {{ site_name }} account and sign in below:{% endblocktranslate %}</p>
<p>
{% translate "Please sign in with one of your existing third party accounts:" %}
{% if ACCOUNT_ALLOW_REGISTRATION %}
{% blocktranslate trimmed %}
Or, <a href="{{ signup_url }}">sign up</a>
for a {{ site_name }} account and sign in below:
{% endblocktranslate %}
{% endif %}
</p>
<div class="socialaccount_ballot">
<div class="socialaccount_ballot">
<ul class="socialaccount_providers">
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
</ul>
<ul class="socialaccount_providers">
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
</ul>
<div class="login-or">{% translate 'or' %}</div>
<div class="login-or">{% translate "or" %}</div>
</div>
</div>
{% include "socialaccount/snippets/login_extra.html" %}
{% include "socialaccount/snippets/login_extra.html" %}
{% else %}
<p>{% blocktranslate %}If you have not created an account yet, then please
<a href="{{ signup_url }}">sign up</a> first.{% endblocktranslate %}</p>
{% if ACCOUNT_ALLOW_REGISTRATION %}
<p>
{% blocktranslate trimmed %}
If you have not created an account yet, then please
<a href="{{ signup_url }}">sign up</a> first.
{% endblocktranslate %}
</p>
{% endif %}
{% endif %}
<form class="login" method="POST" action="{% url 'account_login' %}">

View File

@ -79,10 +79,12 @@
<a class="nav-link" href="{% url 'account_logout' %}">{% translate "Sign Out" %}</a>
</li>
{% else %}
<li class="nav-item">
{# URL provided by django-allauth/account/urls.py #}
<a id="sign-up-link" class="nav-link" href="{% url 'account_signup' %}">{% translate "Sign Up" %}</a>
</li>
{% if ACCOUNT_ALLOW_REGISTRATION %}
<li class="nav-item">
{# URL provided by django-allauth/account/urls.py #}
<a id="sign-up-link" class="nav-link" href="{% url 'account_signup' %}">{% translate "Sign Up" %}</a>
</li>
{% endif %}
<li class="nav-item">
{# URL provided by django-allauth/account/urls.py #}
<a id="log-in-link" class="nav-link" href="{% url 'account_login' %}">{% translate "Sign In" %}</a>

View File

@ -0,0 +1,8 @@
from django.conf import settings
def allauth_settings(request):
"""Expose some settings from django-allauth in templates."""
return {
"ACCOUNT_ALLOW_REGISTRATION": settings.ACCOUNT_ALLOW_REGISTRATION,
}