diff --git a/templates/confirmation/link_expired.html b/templates/confirmation/link_expired.html index 0f84c0f272..81a9c3038b 100644 --- a/templates/confirmation/link_expired.html +++ b/templates/confirmation/link_expired.html @@ -4,12 +4,10 @@

-

Whoops. The confirmation link has expired.

+

Whoops. The confirmation link has expired or been deactivated.

- If you're not sure how to generate a new one, shoot us a line at - {{ support_email }} - and we'll get this resolved shortly. + Please contact your organization administrator for a new one.

diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index 21861dc944..e41ec23480 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -540,7 +540,7 @@ class GitHubAuthBackendTest(ZulipTestCase): def test_github_backend_new_user(self) -> None: rf = RequestFactory() - request = rf.get('/complete') + request = rf.get('/complete', HTTP_HOST=self.user_profile.realm.host) request.session = {} request.user = self.user_profile self.backend.strategy.request = request diff --git a/zerver/tests/test_email_change.py b/zerver/tests/test_email_change.py index 127855ea67..f8fe532a2f 100644 --- a/zerver/tests/test_email_change.py +++ b/zerver/tests/test_email_change.py @@ -52,7 +52,7 @@ class EmailChangeTestCase(ZulipTestCase): type=Confirmation.EMAIL_CHANGE) url = confirmation_url(key, user_profile.realm.host, Confirmation.EMAIL_CHANGE) response = self.client_get(url) - self.assert_in_success_response(["Whoops. The confirmation link has expired."], response) + self.assert_in_success_response(["The confirmation link has expired or been deactivated."], response) def test_confirm_email_change(self) -> None: user_profile = self.example_user('hamlet') diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index ff84c97bc0..8b02e618ed 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -1040,7 +1040,7 @@ class MultiuseInviteTest(ZulipTestCase): result = self.client_post(invite_link, {'email': email}) self.assertEqual(result.status_code, 200) - self.assert_in_response("Whoops. The confirmation link has expired.", result) + self.assert_in_response("The confirmation link has expired or been deactivated.", result) def test_invalid_multiuse_link(self) -> None: email = self.nonreg_email('newuser') @@ -1707,6 +1707,26 @@ class UserSignUpTest(ZulipTestCase): 'from_confirmation': '1'}, subdomain="zephyr") self.assert_in_success_response(["We couldn't find your confirmation link"], result) + def test_failed_signup_due_to_empty_realm_in_prereg_user(self) -> None: + """ + Largely to test a transitional state, where we started requiring the + realm in PreregistrationUser (if realm_creation is False), and wanted + to make sure we had properly disabled any existing confirmation links that + didn't have the realm set. + """ + email = "newuser@zulip.com" + password = "password" + self.client_post('/accounts/home/', {'email': email}) + PreregistrationUser.objects.update(realm=None) + result = self.client_post( + '/accounts/register/', + {'password': password, + 'key': find_key_by_email(email), + 'terms': True, + 'full_name': "New User", + 'from_confirmation': '1'}) + self.assert_in_success_response(["The confirmation link has expired or been deactivated."], result) + def test_failed_signup_due_to_restricted_domain(self) -> None: realm = get_realm('zulip') realm.invite_required = False diff --git a/zerver/views/registration.py b/zerver/views/registration.py index 8e9935f136..787e4e4952 100644 --- a/zerver/views/registration.py +++ b/zerver/views/registration.py @@ -64,7 +64,9 @@ def accounts_register(request): realm = None else: realm = get_realm(get_subdomain(request)) - if prereg_user.realm is not None and prereg_user.realm != realm: + if prereg_user.realm is None: + return render(request, 'confirmation/link_expired.html') + if prereg_user.realm != realm: return render(request, 'confirmation/link_does_not_exist.html') if realm and not email_allowed_for_realm(email, realm):