From aa8b3d2beb6f293dd7f540c033ee7aac3dfd2b1e Mon Sep 17 00:00:00 2001
From: Shubham Dhama
+ {% if user_deactivated %} Someone (possibly you) requested a password reset email for {{ email }} - on {{ realm_uri }}, but you do not have an - active account in {{ realm_uri }}. + on {{ realm_uri }}, but your account has been deactivated. You can contact + an organization administrator to reactivate your account. + {% else %} + Someone (possibly you) requested a password reset email for {{ email }} + on {{ realm_uri }}, but you do not have an account in that organization. + {% endif %} +
+{% if active_accounts %} {% if multiple_active_accounts %} However, you do have active accounts in the following diff --git a/templates/zerver/emails/password_reset.txt b/templates/zerver/emails/password_reset.txt index 0d500fad67..59ca32e1e3 100644 --- a/templates/zerver/emails/password_reset.txt +++ b/templates/zerver/emails/password_reset.txt @@ -5,9 +5,14 @@ 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 -{{ email }} on {{ realm_uri }}, but -you do not have an active account in {{ realm_uri }}. +{% if user_deactivated %} +Someone (possibly you) requested a password reset email for {{ email }} +on {{ realm_uri }}, but your account has been deactivated. You can contact +an organization administrator to reactivate your account. +{% else %} +Someone (possibly you) requested a password reset email for {{ email }} +on {{ realm_uri }}, but you do not have an account in that organization. +{% endif %} {% if active_accounts %} {% if multiple_active_accounts %} However, you do have active accounts in the following organizations. diff --git a/zerver/forms.py b/zerver/forms.py index 2e0d4e17d3..a19173d479 100644 --- a/zerver/forms.py +++ b/zerver/forms.py @@ -24,7 +24,7 @@ from zerver.lib.request import JsonableError from zerver.lib.send_email import send_email, FromAddress from zerver.lib.subdomains import get_subdomain, user_matches_subdomain, is_root_domain_available from zerver.lib.users import check_full_name -from zerver.models import Realm, get_active_user, UserProfile, get_realm, email_to_domain, \ +from zerver.models import Realm, get_user, UserProfile, get_realm, email_to_domain, \ email_allowed_for_realm, DisposableEmailError, DomainNotAllowedForRealmError, \ EmailContainsPlusError from zproject.backends import email_auth_enabled, email_belongs_to_ldap @@ -226,7 +226,7 @@ class ZulipPasswordResetForm(PasswordResetForm): user = None # type: Optional[UserProfile] try: - user = get_active_user(email, realm) + user = get_user(email, realm) except UserProfile.DoesNotExist: pass @@ -235,6 +235,10 @@ class ZulipPasswordResetForm(PasswordResetForm): 'realm_uri': realm.uri, } + if user is not None and not user.is_active: + context['user_deactivated'] = True + user = None + if user is not None: token = token_generator.make_token(user) uid = urlsafe_base64_encode(force_bytes(user.id)).decode('ascii') diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 5ac0b1ee42..337c15150f 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -260,6 +260,8 @@ class PasswordResetTest(ZulipTestCase): outbox[0].body) self.assertNotIn('does have an active account in the zulip.testserver', outbox[0].body) + self.assertIn('but your account has been deactivated', + outbox[0].body) def test_password_reset_with_deactivated_realm(self) -> None: user_profile = self.example_user("hamlet") @@ -304,9 +306,11 @@ class PasswordResetTest(ZulipTestCase): message = outbox.pop() tokenized_no_reply_email = parseaddr(message.from_email)[1] self.assertTrue(re.search(self.TOKENIZED_NOREPLY_REGEX, tokenized_no_reply_email)) - self.assertIn('Someone (possibly you) requested a password', + self.assertIn('Someone (possibly you) requested a password reset email for', message.body) - self.assertIn("but\nyou do not have an active account in http://zephyr.testserver", + self.assertIn("but you do not have an account in that organization", + message.body) + self.assertIn("However, you do have an active account in the http://zulip.testserver\norganization;", message.body) def test_invalid_subdomain(self) -> None: