Commit a8dc5a6d authored by Michal Čihař's avatar Michal Čihař

Different mail template for registration and password reset

Fixes #571
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 1cd13067
......@@ -58,6 +58,10 @@ def send_validation(strategy, backend, code):
if not strategy.request.session.session_key:
strategy.request.session.create()
template = 'activation'
if strategy.request.session.pop('password_reset', False):
template = 'reset'
url = '{}?verification_code={}&id={}'.format(
reverse('social:complete', args=(backend.name,)),
code.code,
......@@ -67,7 +71,7 @@ def send_validation(strategy, backend, code):
send_notification_email(
None,
code.email,
'activation',
template,
info=code.code,
context={
'url': url
......
......@@ -67,8 +67,8 @@ REGISTRATION_DATA = {
class RegistrationTest(TestCase, RegistrationTestMixin):
clear_cookie = False
def assert_registration(self):
url = self.assert_registration_mailbox()
def assert_registration(self, match=None):
url = self.assert_registration_mailbox(match)
if self.clear_cookie:
del self.client.cookies['sessionid']
......@@ -144,7 +144,7 @@ class RegistrationTest(TestCase, RegistrationTestMixin):
)
self.assertRedirects(response, reverse('email-sent'))
self.assert_registration()
self.assert_registration('[Weblate] Password reset on Weblate')
def test_wrong_username(self):
data = REGISTRATION_DATA.copy()
......
......@@ -521,6 +521,9 @@ def reset_password(request):
user = form.cleaned_data['email']
user.set_unusable_password()
user.save()
if not request.session.session_key:
request.session.create()
request.session['password_reset'] = True
return complete(request, 'email')
else:
form = ResetForm()
......
{% extends "mail/base.html" %}
{% load url from future %}
{% load i18n %}{% load translations %}
{% block content %}
<p>
{% trans "Hi,"%}
</p>
<p>
{% blocktrans %}There was a request to reset your Weblate password at {{ site_title }}.{% endblocktrans %}
</p>
<p>
{% blocktrans %}Please open the following link in your web browser. If the link is split over several lines, you may need to copy it in the address bar.{% endblocktrans %}
</p>
<p>
<a href="{{ current_site_url }}{{ url }}">{{ current_site_url }}{{ url }}</a>
</p>
<p>
{% blocktrans %}If there is a problem with your registration, please contact us:{% endblocktrans %}
</p>
<p>
<a href="{{ current_site_url }}{% url 'contact' %}?subject=Registration">{{ current_site_url }}{% url 'contact' %}?subject=Registration</a>
</p>
{% endblock %}
{% load url from future %}{% load i18n %}{% load translations %}{% autoescape off %}{% filter wordwrap:72 %}{% trans "Hi," %}
{% blocktrans %}There was a request to reset your Weblate password at {{ site_title }}.{% endblocktrans %}
{% blocktrans %}Please open the following link in your web browser. If the link is split over several lines, you may need to copy it in the address bar.{% endblocktrans %}
{{ current_site_url }}{{ url }}
{% blocktrans %}If there is a problem with your registration, please contact us:{% endblocktrans %}
{{ current_site_url }}{% url 'contact' %}?subject=Registration
{% endfilter%}{% endautoescape %}{% include "mail/signature.txt" %}
{% load i18n %}{% load translations %}{% blocktrans %}Password reset on {{ site_title }}{% endblocktrans %}
......@@ -44,12 +44,14 @@ class RegistrationTestMixin(object):
"""
Helper to share code for registration testing.
"""
def assert_registration_mailbox(self):
def assert_registration_mailbox(self, match=None):
if match is None:
match = '[Weblate] Your registration on Weblate'
# Check mailbox
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(
mail.outbox[0].subject,
'[Weblate] Your registration on Weblate'
match
)
# Parse URL
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment