diff --git a/src/members/allauth_config.py b/src/members/allauth_config.py index 60d4c1e..fb76503 100644 --- a/src/members/allauth_config.py +++ b/src/members/allauth_config.py @@ -1,6 +1,7 @@ """Special configuration for AllAuth.""" from allauth.account.adapter import DefaultAccountAdapter +from .utils import allow_new_users class AccountAdapter(DefaultAccountAdapter): @@ -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) diff --git a/src/members/configuration.py b/src/members/configuration.py index 79624ea..e489eec 100644 --- a/src/members/configuration.py +++ b/src/members/configuration.py @@ -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 diff --git a/src/members/templatetags/__init__.py b/src/members/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/members/templatetags/members.py b/src/members/templatetags/members.py new file mode 100644 index 0000000..6ac5ac7 --- /dev/null +++ b/src/members/templatetags/members.py @@ -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']) diff --git a/src/members/utils.py b/src/members/utils.py new file mode 100644 index 0000000..6566e55 --- /dev/null +++ b/src/members/utils.py @@ -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() diff --git a/src/templates/account/base.html b/src/templates/account/base.html index 5ec692b..6ad3a23 100644 --- a/src/templates/account/base.html +++ b/src/templates/account/base.html @@ -5,7 +5,6 @@ {% block secondary_navigation %} {% endblock %} \ No newline at end of file diff --git a/src/templates/account/login.html b/src/templates/account/login.html index 621ab2c..6485820 100644 --- a/src/templates/account/login.html +++ b/src/templates/account/login.html @@ -4,6 +4,7 @@ {% load account %} {% load forms %} {% load auth %} +{% load members %} {% block head_title %}{% trans "Sign In" %}{% endblock %} @@ -14,8 +15,10 @@

{% trans "Sign In" %}

- -

{% blocktrans %}If you have not created an account yet, then please sign up first.{% endblocktrans %}

+ {% get_allow_new_users as allow_new_users %} + {% if allow_new_users %} +

{% blocktrans %}If you have not created an account yet, then please sign up first.{% endblocktrans %}

+ {% endif %}
{% csrf_token %} diff --git a/src/templates/page_blocks/welcome.html b/src/templates/page_blocks/welcome.html index d050d68..8134ee8 100644 --- a/src/templates/page_blocks/welcome.html +++ b/src/templates/page_blocks/welcome.html @@ -1,3 +1,5 @@ +{% load members %} +