Skip to content

Commit

Permalink
Allow disabling of registration
Browse files Browse the repository at this point in the history
  • Loading branch information
jscott1989 committed Dec 1, 2016
1 parent d57e418 commit 9e37956
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/members/allauth_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Special configuration for AllAuth."""

from allauth.account.adapter import DefaultAccountAdapter
from .utils import allow_new_users


class AccountAdapter(DefaultAccountAdapter):
Expand All @@ -16,3 +17,14 @@ def get_login_redirect_url(self, request):
return '/member/%s/edit' % request.user.pk
else:
return '/'

def is_open_for_signup(self, request):
"""
Check whether or not the site is open for signups.
Next to simply returning True/False you can also intervene the
regular flow by raising an ImmediateHttpResponse
(Comment reproduced from the overridden method.)
"""
return allow_new_users(request)
9 changes: 9 additions & 0 deletions src/members/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ class ProfileProperties(configuration.PropertiesField):
default = [
# TODO: After name + bio are moved to use properties, put them here
]


class AllowRegistration(configuration.BooleanField):

"""Should new users be allowed to register."""

category = "Members"

default = True
Empty file.
12 changes: 12 additions & 0 deletions src/members/templatetags/members.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Template tags relating to members."""

from django import template
from members.utils import allow_new_users

register = template.Library()


@register.assignment_tag(takes_context=True)
def get_allow_new_users(context):
"""Are new users allowed."""
return allow_new_users(context['request'])
7 changes: 7 additions & 0 deletions src/members/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Member utils."""
from members.configuration import AllowRegistration


def allow_new_users(request):
"""Are new users allowed to register."""
return AllowRegistration().get()
1 change: 0 additions & 1 deletion src/templates/account/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{% block secondary_navigation %}
<ul class="inline-list inline-list--space">
<li><a class="secondary-navigation__link" href="{% url 'account_login' %}">{% trans "Sign In" %}</a></li>
<li><a class="secondary-navigation__link" href="{% url 'account_signup' %}">{% trans "Sign Up" %}</a></li>
<li><a class="secondary-navigation__link" href="{% url 'account_reset_password' %}">{% trans "Forgot Password" %}</a></li>
</ul>
{% endblock %}
7 changes: 5 additions & 2 deletions src/templates/account/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% load account %}
{% load forms %}
{% load auth %}
{% load members %}

{% block head_title %}{% trans "Sign In" %}{% endblock %}

Expand All @@ -14,8 +15,10 @@
<header class="block__header">
<h2 class="block__header-text">{% trans "Sign In" %}</h2>
</header>

<p>{% blocktrans %}If you have not created an account yet, then please <a href="{{ signup_url }}">sign up</a> first.{% endblocktrans %}</p>
{% get_allow_new_users as allow_new_users %}
{% if allow_new_users %}
<p>{% blocktrans %}If you have not created an account yet, then please <a href="{{ signup_url }}">sign up</a> first.{% endblocktrans %}</p>
{% endif %}

<form class="login form" method="POST" action="{% url 'account_login' %}">
{% csrf_token %}
Expand Down
17 changes: 12 additions & 5 deletions src/templates/page_blocks/welcome.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% load members %}

<!-- <header class="block__header valign-together">
{% if request.user.is_authenticated %}
<h2 class="block__header-text block__header-text--small">Welcome back, <strong>{{request.user}}</strong></h2>
Expand Down Expand Up @@ -35,9 +37,14 @@ <h2 class="block__header-text block__header-text--small">Welcome, <strong>Guest<
</div>
</div>
{% else %}
<ul class="inline-list">
<li><a class="btn" href="{% url "account_login" %}">Log In</a></li>
<li>or</li>
<li><a class="btn" href="{% url "account_signup" %}">Sign Up</a></li>
</ul>
{% get_allow_new_users as allow_new_users %}
{% if allow_new_users %}
<ul class="inline-list">
<li><a class="btn" href="{% url "account_login" %}">Log In</a></li>
<li>or</li>
<li><a class="btn" href="{% url "account_signup" %}">Sign Up</a></li>
</ul>
{% else %}
<a class="btn" href="{% url "account_login" %}">Log In</a>
{% endif %}
{% endif %}

0 comments on commit 9e37956

Please sign in to comment.