csv_import: use absolute URL for password reset (#49479)

This commit is contained in:
Valentin Deniaud 2020-12-15 10:54:42 +01:00
parent d915700420
commit ebfbd66552
4 changed files with 6 additions and 5 deletions

View File

@ -2,5 +2,5 @@
{% blocktrans with hostname=request.get_host %}You requested reset of your password on {{ hostname }}, to proceed please
click on the following link{% endblocktrans %}:
{% block reset_link %}
{{ base_url }}{{ reset_url }}
{{ reset_url }}
{% endblock %}

View File

@ -339,6 +339,8 @@ def make_url(to, args=(), kwargs={}, keep_params=False, params=None, append=None
if absolute:
if request:
url = request.build_absolute_uri(url)
elif hasattr(settings, 'SITE_BASE_URL'):
url = urlparse.urljoin(settings.SITE_BASE_URL, url)
else:
raise TypeError('make_url() absolute cannot be used without request')
# keep using unicode
@ -812,7 +814,7 @@ def build_reset_password_url(user, request=None, next_url=None, set_random_passw
next_url=next_url,
sign_next_url=sign_next_url,
request=request,
absolute=bool(request))
absolute=True)
return reset_url, token

View File

@ -505,6 +505,7 @@ tnoel@entrouvert.com,Thomas,Noël,'''
assert importer.run()
thomas = User.objects.get(email='tnoel@entrouvert.com')
assert len(mail.outbox) == 1
assert 'http://testserver/accounts/password/reset/confirm/' in mail.outbox[0].body
password = thomas.password
del mail.outbox[0]

View File

@ -28,9 +28,7 @@ def test_send_password_reset_email(app, simple_user, mailoutbox):
simple_user,
legacy_subject_templates=['registration/password_reset_subject.txt'],
legacy_body_templates=['registration/password_reset_email.html'],
context={
'base_url': 'http://testserver',
})
)
assert len(mailoutbox) == 1
utils.assert_event('user.password.reset.request', user=simple_user, email=simple_user.email)
url = utils.get_link_from_mail(mailoutbox[0])