emails/password_reset: Refactor and replace no_account_in_realm.

In place of no_account_in_realm we will use its negation
active_account_in_realm as a part of refactoring this template.
This commit is contained in:
Shubham Dhama 2018-08-15 01:36:47 +05:30 committed by Tim Abbott
parent 3fecc71777
commit 491bd6d2c9
3 changed files with 22 additions and 20 deletions

View File

@ -1,8 +1,14 @@
{% extends "zerver/emails/compiled/email_base_default.html" %} {% extends "zerver/emails/compiled/email_base_default.html" %}
{% block content %} {% block content %}
{% if active_account_in_realm %}
<p>
Psst. Word on the street is that you need a new password, {{ email }}.<br />
It's all good. Click here and we'll take care of the rest:<br />
<a class="button" href="{{ reset_url }}">Reset password</a>
</p>
{% else %}
<p> <p>
{% if no_account_in_realm %}
Someone (possibly you) requested a password reset email for {{ email }} Someone (possibly you) requested a password reset email for {{ email }}
on {{ realm_uri }}, but you do not have an on {{ realm_uri }}, but you do not have an
active account in {{ realm_uri }}. active account in {{ realm_uri }}.
@ -23,12 +29,8 @@
organization; you can try logging in or resetting your password there. organization; you can try logging in or resetting your password there.
{% endif %} {% endif %}
{% endif %} {% endif %}
{% else %}
Psst. Word on the street is that you need a new password, {{ email }}.<br />
It's all good. Click here and we'll take care of the rest:<br />
<a class="button" href="{{ reset_url }}">Reset password</a>
{% endif %}
</p> </p>
{% endif %}
<p> <p>
Thanks,<br /> Thanks,<br />
Your friends at Zulip HQ Your friends at Zulip HQ

View File

@ -1,4 +1,10 @@
{% if no_account_in_realm %} {% if active_account_in_realm %}
Psst. Word on the street is that you need a new password, {{ email }}.
It's all good. Follow the link below and we'll take care of the rest:
{{ reset_url }}
{% else %}
Someone (possibly you) requested a password reset email for Someone (possibly you) requested a password reset email for
{{ email }} on {{ realm_uri }}, but {{ email }} on {{ realm_uri }}, but
you do not have an active account in {{ realm_uri }}. you do not have an active account in {{ realm_uri }}.
@ -15,12 +21,6 @@ However, you do have an active account in the {{ active_accounts[0].realm.uri }}
organization; you can try logging in or resetting your password there. organization; you can try logging in or resetting your password there.
{% endif %} {% endif %}
{% endif %} {% endif %}
{% else %}
Psst. Word on the street is that you need a new password, {{ email }}.
It's all good. Follow the link below and we'll take care of the rest:
{{ reset_url }}
{% endif %} {% endif %}
Thanks, Thanks,

View File

@ -241,14 +241,14 @@ class ZulipPasswordResetForm(PasswordResetForm):
endpoint = reverse('django.contrib.auth.views.password_reset_confirm', endpoint = reverse('django.contrib.auth.views.password_reset_confirm',
kwargs=dict(uidb64=uid, token=token)) kwargs=dict(uidb64=uid, token=token))
context['no_account_in_realm'] = False context['active_account_in_realm'] = True
context['reset_url'] = "{}{}".format(user.realm.uri, endpoint) context['reset_url'] = "{}{}".format(user.realm.uri, endpoint)
send_email('zerver/emails/password_reset', to_user_id=user.id, send_email('zerver/emails/password_reset', to_user_id=user.id,
from_name="Zulip Account Security", from_name="Zulip Account Security",
from_address=FromAddress.tokenized_no_reply_address(), from_address=FromAddress.tokenized_no_reply_address(),
context=context) context=context)
else: else:
context['no_account_in_realm'] = True context['active_account_in_realm'] = False
active_accounts = UserProfile.objects.filter(email__iexact=email, is_active=True) active_accounts = UserProfile.objects.filter(email__iexact=email, is_active=True)
if active_accounts: if active_accounts:
context['active_accounts'] = active_accounts context['active_accounts'] = active_accounts