0001-views-do-not-link-to-registration-when-it-is-closed-.patch
src/authentic2/forms/passwords.py | ||
---|---|---|
18 | 18 |
from collections import OrderedDict |
19 | 19 | |
20 | 20 |
from django import forms |
21 |
from django.conf import settings |
|
21 | 22 |
from django.contrib.auth import forms as auth_forms |
22 | 23 |
from django.core.exceptions import ValidationError |
23 | 24 |
from django.forms import Form |
... | ... | |
83 | 84 |
utils.send_templated_mail(user, ['authentic2/password_reset_refused']) |
84 | 85 |
if not self.users.exists() and email: |
85 | 86 |
logger.info(u'password reset request for "%s", no user found', email) |
86 |
ctx = {'registration_url': utils.make_url('registration_register', absolute=True)} |
|
87 |
if getattr(settings, 'REGISTRATION_OPEN', True): |
|
88 |
ctx = { |
|
89 |
'registration_url': utils.make_url('registration_register', absolute=True), |
|
90 |
} |
|
91 |
else: |
|
92 |
ctx = {} |
|
87 | 93 |
utils.send_templated_mail(email, ['authentic2/password_reset_no_account'], context=ctx) |
88 | 94 |
hooks.call_hooks('event', name='password-reset', email=email or email_or_username, users=active_users) |
89 | 95 |
src/authentic2/templates/authentic2/password_reset_no_account_body.html | ||
---|---|---|
7 | 7 |
<p>{% blocktrans trimmed with hostname=request.get_host %} |
8 | 8 |
You requested reset of your password on {{ hostname }}, but no account was found associated with this address. |
9 | 9 |
{% endblocktrans %}</p> |
10 | ||
10 |
{% if registration_url %} |
|
11 | 11 |
{% with _("Create an account") as button_label %} |
12 | 12 |
{% include "emails/button-link.html" with url=registration_url label=button_label %} |
13 | 13 |
{% endwith %} |
14 |
{% endif %} |
|
14 | 15 |
{% endblock %} |
src/authentic2/templates/authentic2/password_reset_no_account_body.txt | ||
---|---|---|
5 | 5 |
{% blocktrans trimmed with hostname=request.get_host %} |
6 | 6 |
You requested reset of your password on {{ hostname }}, but no account was found associated with this address. |
7 | 7 |
{% endblocktrans %} |
8 |
{% trans "You can create an account here:" %} {{ registration_url }}.
|
|
8 |
{% if registration_url %}{% trans "You can create an account here:" %} {{ registration_url }}.{% endif %}
|
|
9 | 9 |
{% endblock %} |
tests/test_password_reset.py | ||
---|---|---|
13 | 13 |
# |
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | ||
16 |
import pytest |
|
17 | 17 |
from django.test.utils import override_settings |
18 | 18 |
from django.urls import reverse |
19 | 19 | |
... | ... | |
150 | 150 |
assert 'please reset your password again' in response |
151 | 151 | |
152 | 152 | |
153 |
def test_send_password_reset_email_no_account(app, db, mailoutbox): |
|
153 |
@pytest.mark.parametrize( |
|
154 |
'registration_open', |
|
155 |
[True, False], |
|
156 |
) |
|
157 |
def test_send_password_reset_email_no_account(app, db, mailoutbox, settings, registration_open): |
|
158 |
settings.REGISTRATION_OPEN = registration_open |
|
154 | 159 |
url = reverse('password_reset') |
155 | 160 |
resp = app.get(url, status=200) |
156 | 161 |
resp.form.set('email', 'test@entrouvert.com') |
... | ... | |
160 | 165 |
assert mail.subject == 'Password reset on testserver' |
161 | 166 |
for body in (mail.body, mail.alternatives[0][0]): |
162 | 167 |
assert 'no account was found associated with this address' in body |
163 |
assert 'http://testserver/accounts/register/' in body |
|
168 |
if settings.REGISTRATION_OPEN: |
|
169 |
assert 'http://testserver/accounts/register/' in body |
|
170 |
else: |
|
171 |
assert 'http://testserver/accounts/register/' not in body |
|
164 | 172 | |
165 | 173 | |
166 | 174 |
def test_send_password_reset_email_disabled_account(app, simple_user, mailoutbox): |
167 |
- |