Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

urls: Provide `email` as a GET parameter.

Aman Agrawal37431cf0b550
diff --git a/frontend_tests/puppeteer_tests/realm-creation.ts b/frontend_tests/puppeteer_tests/realm-creation.ts
index b1d86e58708..2529ac03f32 100644
--- a/frontend_tests/puppeteer_tests/realm-creation.ts
+++ b/frontend_tests/puppeteer_tests/realm-creation.ts
@@ -21,7 +21,7 @@ async function realm_creation_tests(page: Page): Promise<void> {
]);
// Make sure confirmation email is sent.
- assert.ok(page.url().includes("/accounts/new/send_confirm/" + email));
+ assert.ok(page.url().includes("/accounts/new/send_confirm/?email=alice%40test.example.com"));
// Special endpoint enabled only during tests for extracting confirmation key
await page.goto("http://" + host + "/confirmation_key/");
diff --git a/static/js/portico/signup.js b/static/js/portico/signup.js
index c420d26d973..31293738d8f 100644
--- a/static/js/portico/signup.js
+++ b/static/js/portico/signup.js
@@ -99,7 +99,7 @@ $(() => {
}
});
- // Code in this block will be executed when the /accounts/send_confirm
+ // Code in this block will be executed when the /accounts/send_confirm/
// endpoint is visited i.e. accounts_send_confirm.html is rendered.
if ($("[data-page-id='accounts-send-confirm']").length > 0) {
$("#resend_email_link").on("click", () => {
diff --git a/static/styles/portico/portico_signin.css b/static/styles/portico/portico_signin.css
index 5eb0ff3d630..d751a3a4afc 100644
--- a/static/styles/portico/portico_signin.css
+++ b/static/styles/portico/portico_signin.css
@@ -15,6 +15,10 @@ html {
margin: 10px;
}
+.semi-bold {
+ font-weight: 600;
+}
+
.white-box {
position: relative;
padding: 30px;
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 5839e629376..4cfbdca4649 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -733,7 +733,9 @@ Output:
def register(self, email: str, password: str, subdomain: str = DEFAULT_SUBDOMAIN) -> None:
response = self.client_post("/accounts/home/", {"email": email}, subdomain=subdomain)
self.assertEqual(response.status_code, 302)
- self.assertEqual(response["Location"], f"/accounts/send_confirm/{email}")
+ self.assertEqual(
+ response["Location"], f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
response = self.submit_reg_form_for_user(email, password, subdomain=subdomain)
self.assertEqual(response.status_code, 302)
self.assertEqual(response["Location"], f"http://{Realm.host_for_subdomain(subdomain)}/")
diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.py
index c6de1b10561..0d59668c1c8 100644
--- a/zerver/tests/test_management_commands.py
+++ b/zerver/tests/test_management_commands.py
@@ -1,5 +1,6 @@
import os
import re
+import urllib
from datetime import timedelta
from typing import Any, Dict, List, Optional
from unittest import mock, skipUnless
@@ -318,9 +319,11 @@ class TestGenerateRealmCreationLink(ZulipTestCase):
result = self.client_post(generated_link, {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(re.search(f"/accounts/new/send_confirm/{email}$", result["Location"]))
+ self.assertEqual(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}", result["Location"]
+ )
result = self.client_get(result["Location"])
- self.assert_in_response("Check your email so we can get started", result)
+ self.assert_in_response("Check your email", result)
# Original link is now dead
result = self.client_get(generated_link)
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py
index aabaaff1596..c512bd29155 100644
--- a/zerver/tests/test_signup.py
+++ b/zerver/tests/test_signup.py
@@ -774,10 +774,10 @@ class PasswordResetTest(ZulipTestCase):
result = self.client_get("/accounts/password/done/")
self.assert_in_success_response(["We've reset your password!"], result)
- result = self.client_get("/accounts/send_confirm/[email protected]")
+ result = self.client_get("/accounts/send_confirm/[email protected]")
self.assert_in_success_response(["/accounts/home/"], result)
- result = self.client_get("/accounts/new/send_confirm/[email protected]")
+ result = self.client_get("/accounts/new/send_confirm/[email protected]")
self.assert_in_success_response(["/new/"], result)
def test_password_reset_for_soft_deactivated_user(self) -> None:
@@ -3022,7 +3022,11 @@ class MultiuseInviteTest(ZulipTestCase):
result = self.client_post(invite_link, {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -3396,7 +3400,11 @@ class RealmCreationTest(ZulipTestCase):
# Create new realm with the email
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -3507,7 +3515,11 @@ class RealmCreationTest(ZulipTestCase):
# Create new realm with the email
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -3547,7 +3559,11 @@ class RealmCreationTest(ZulipTestCase):
# Create new realm with the email
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -3590,7 +3606,11 @@ class RealmCreationTest(ZulipTestCase):
# Create new realm with the email
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -3644,7 +3664,11 @@ class RealmCreationTest(ZulipTestCase):
# Create new realm with the email
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -3683,7 +3707,11 @@ class RealmCreationTest(ZulipTestCase):
# Create new realm with the email
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -3718,7 +3746,11 @@ class RealmCreationTest(ZulipTestCase):
# Create new realm with the email
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -3756,7 +3788,11 @@ class RealmCreationTest(ZulipTestCase):
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -3804,7 +3840,11 @@ class RealmCreationTest(ZulipTestCase):
# Now we pre-generate two realm creation links
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
first_confirmation_url = self.get_confirmation_url_from_outbox(email)
@@ -3813,7 +3853,11 @@ class RealmCreationTest(ZulipTestCase):
# Get a second realm creation link.
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
second_confirmation_url = self.get_confirmation_url_from_outbox(email)
@@ -4072,7 +4116,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/accounts/home/", {"email": email}, **client_kwargs)
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"], **client_kwargs)
self.assert_in_response("Check your email", result)
@@ -4149,7 +4197,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/accounts/home/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -4180,7 +4232,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/accounts/home/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -4214,7 +4270,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/accounts/home/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -4307,7 +4367,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/accounts/home/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -4325,7 +4389,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/accounts/home/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -4355,7 +4423,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/accounts/home/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -4626,7 +4698,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/accounts/home/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -4817,7 +4893,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
# Visit the confirmation link.
@@ -4900,7 +4980,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
# Visit the confirmation link.
@@ -4975,7 +5059,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -5042,7 +5130,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -5188,7 +5280,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -5239,7 +5335,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -5361,7 +5461,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -5402,7 +5506,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
with self.settings(
@@ -5553,7 +5661,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
@@ -5582,7 +5694,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email})
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"])
self.assert_in_response("Check your email", result)
# Visit the confirmation link.
@@ -5643,7 +5759,11 @@ class UserSignUpTest(InviteUserBase):
result = self.client_post("/register/", {"email": email}, subdomain="zephyr")
self.assertEqual(result.status_code, 302)
- self.assertTrue(result["Location"].endswith(f"/accounts/send_confirm/{email}"))
+ self.assertTrue(
+ result["Location"].endswith(
+ f"/accounts/send_confirm/?email={urllib.parse.quote(email)}"
+ )
+ )
result = self.client_get(result["Location"], subdomain="zephyr")
self.assert_in_response("Check your email", result)
# Visit the confirmation link.
diff --git a/zerver/views/registration.py b/zerver/views/registration.py
index 512b453ad60..2a82ec6245f 100644
--- a/zerver/views/registration.py
+++ b/zerver/views/registration.py
@@ -655,7 +655,10 @@ def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> Ht
if key_record is not None:
key_record.delete()
- return HttpResponseRedirect(reverse("new_realm_send_confirm", kwargs={"email": email}))
+ new_realm_send_confirm_url = reverse("new_realm_send_confirm")
+ query = urlencode({"email": email})
+ url = append_url_query_string(new_realm_send_confirm_url, query)
+ return HttpResponseRedirect(url)
else:
form = RealmCreationForm()
return TemplateResponse(
@@ -665,8 +668,18 @@ def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> Ht
)
+@has_request_variables
+def signup_send_confirm(request: HttpRequest, email: str = REQ("email")) -> HttpResponse:
+ return TemplateResponse(
+ request,
+ "zerver/accounts_send_confirm.html",
+ context={"email": email},
+ )
+
+
@add_google_analytics
-def new_realm_send_confirm(request: HttpRequest, email: str) -> HttpResponse:
+@has_request_variables
+def new_realm_send_confirm(request: HttpRequest, email: str = REQ("email")) -> HttpResponse:
return TemplateResponse(
request,
"zerver/accounts_send_confirm.html",
@@ -739,8 +752,10 @@ def accounts_home(
except EmailNotDeliveredError:
logging.error("Error in accounts_home")
return HttpResponseRedirect("/config-error/smtp")
-
- return HttpResponseRedirect(reverse("signup_send_confirm", kwargs={"email": email}))
+ signup_send_confirm_url = reverse("signup_send_confirm")
+ query = urlencode({"email": email})
+ url = append_url_query_string(signup_send_confirm_url, query)
+ return HttpResponseRedirect(url)
else:
form = HomepageForm(realm=realm)
diff --git a/zproject/urls.py b/zproject/urls.py
index 78d02de2503..6f69e3b3380 100644
--- a/zproject/urls.py
+++ b/zproject/urls.py
@@ -13,7 +13,7 @@ from django.contrib.auth.views import (
from django.urls import path, re_path
from django.urls.resolvers import URLPattern, URLResolver
from django.utils.module_loading import import_string
-from django.views.generic import RedirectView, TemplateView
+from django.views.generic import RedirectView
from zerver.forms import LoggingSetPasswordForm
from zerver.lib.integrations import WEBHOOK_INTEGRATIONS
@@ -126,6 +126,7 @@ from zerver.views.registration import (
get_prereg_key_and_redirect,
new_realm_send_confirm,
realm_redirect,
+ signup_send_confirm,
)
from zerver.views.report import (
report_csp_violations,
@@ -565,12 +566,12 @@ i18n_urls = [
# Registration views, require a confirmation ID.
path("accounts/home/", accounts_home),
path(
- "accounts/send_confirm/<email>",
- TemplateView.as_view(template_name="zerver/accounts_send_confirm.html"),
+ "accounts/send_confirm/",
+ signup_send_confirm,
name="signup_send_confirm",
),
path(
- "accounts/new/send_confirm/<email>",
+ "accounts/new/send_confirm/",
new_realm_send_confirm,
name="new_realm_send_confirm",
),