diff --git a/src/authentic2/forms/passwords.py b/src/authentic2/forms/passwords.py index e4ada5bc9..6e7ff4434 100644 --- a/src/authentic2/forms/passwords.py +++ b/src/authentic2/forms/passwords.py @@ -18,6 +18,7 @@ import logging from collections import OrderedDict from django import forms +from django.conf import settings from django.contrib.auth import forms as auth_forms from django.core.exceptions import ValidationError from django.forms import Form @@ -87,7 +88,12 @@ class PasswordResetForm(HoneypotForm): utils.send_templated_mail(user, ['authentic2/password_reset_refused']) if not self.users.exists() and email: logger.info(u'password reset request for "%s", no user found', email) - ctx = {'registration_url': utils.make_url('registration_register', absolute=True)} + if getattr(settings, 'REGISTRATION_OPEN', True): + ctx = { + 'registration_url': utils.make_url('registration_register', absolute=True), + } + else: + ctx = {} utils.send_templated_mail(email, ['authentic2/password_reset_no_account'], context=ctx) hooks.call_hooks('event', name='password-reset', email=email or email_or_username, users=active_users) diff --git a/src/authentic2/templates/authentic2/password_reset_no_account_body.html b/src/authentic2/templates/authentic2/password_reset_no_account_body.html index b676535c1..b9eeee8cd 100644 --- a/src/authentic2/templates/authentic2/password_reset_no_account_body.html +++ b/src/authentic2/templates/authentic2/password_reset_no_account_body.html @@ -7,8 +7,9 @@
{% blocktrans trimmed with hostname=request.get_host %} You requested reset of your password on {{ hostname }}, but no account was found associated with this address. {% endblocktrans %}
- +{% if registration_url %} {% with _("Create an account") as button_label %} {% include "emails/button-link.html" with url=registration_url label=button_label %} {% endwith %} +{% endif %} {% endblock %} diff --git a/src/authentic2/templates/authentic2/password_reset_no_account_body.txt b/src/authentic2/templates/authentic2/password_reset_no_account_body.txt index 65de333ee..783c18d17 100644 --- a/src/authentic2/templates/authentic2/password_reset_no_account_body.txt +++ b/src/authentic2/templates/authentic2/password_reset_no_account_body.txt @@ -5,5 +5,5 @@ {% blocktrans trimmed with hostname=request.get_host %} You requested reset of your password on {{ hostname }}, but no account was found associated with this address. {% endblocktrans %} -{% trans "You can create an account here:" %} {{ registration_url }}. +{% if registration_url %}{% trans "You can create an account here:" %} {{ registration_url }}.{% endif %} {% endblock %} diff --git a/tests/test_password_reset.py b/tests/test_password_reset.py index 5e6d0b46c..6a8149c69 100644 --- a/tests/test_password_reset.py +++ b/tests/test_password_reset.py @@ -13,7 +13,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see