diff --git a/corporate/tests/test_remote_billing.py b/corporate/tests/test_remote_billing.py index 79f235fd87..015226e130 100644 --- a/corporate/tests/test_remote_billing.py +++ b/corporate/tests/test_remote_billing.py @@ -576,7 +576,8 @@ class LegacyServerLoginTest(BouncerTestCase): ) self.assertEqual(result.status_code, 200) self.assert_in_success_response( - ["Did not find a server registration for this server_org_id."], result + ["This zulip_org_id is not registered with Zulip's billing management system."], + result, ) def test_server_login_invalid_server_org_secret(self) -> None: @@ -586,7 +587,7 @@ class LegacyServerLoginTest(BouncerTestCase): subdomain="selfhosting", ) self.assertEqual(result.status_code, 200) - self.assert_in_success_response(["Invalid server_org_secret."], result) + self.assert_in_success_response(["Invalid zulip_org_key for this zulip_org_id."], result) def test_server_login_deactivated_server(self) -> None: self.server.deactivated = True @@ -681,7 +682,7 @@ class LegacyServerLoginTest(BouncerTestCase): subdomain="selfhosting", ) self.assertEqual(result.status_code, 200) - self.assert_in_success_response(["Invalid server_org_secret."], result) + self.assert_in_success_response(["Invalid zulip_org_key for this zulip_org_id."], result) # The next_page param should be preserved in the form. self.assert_in_success_response( [''], result diff --git a/corporate/views/remote_billing_page.py b/corporate/views/remote_billing_page.py index 4a78cd90e2..8d2943c8ca 100644 --- a/corporate/views/remote_billing_page.py +++ b/corporate/views/remote_billing_page.py @@ -442,12 +442,16 @@ def remote_billing_legacy_server_login( remote_server = get_remote_server_by_uuid(server_org_id) except RemoteZulipServer.DoesNotExist: context.update( - {"error_message": _("Did not find a server registration for this server_org_id.")} + { + "error_message": _( + "This zulip_org_id is not registered with Zulip's billing management system." + ) + } ) return render(request, "corporate/legacy_server_login.html", context) if not constant_time_compare(server_org_secret, remote_server.api_key): - context.update({"error_message": _("Invalid server_org_secret.")}) + context.update({"error_message": _("Invalid zulip_org_key for this zulip_org_id.")}) return render(request, "corporate/legacy_server_login.html", context) if remote_server.deactivated: diff --git a/templates/corporate/legacy_server_login.html b/templates/corporate/legacy_server_login.html index d3c53acea3..1931f10f05 100644 --- a/templates/corporate/legacy_server_login.html +++ b/templates/corporate/legacy_server_login.html @@ -27,17 +27,19 @@
-
+
{% endblock %} + diff --git a/web/src/billing/remote_billing_auth.ts b/web/src/billing/remote_billing_auth.ts index 6cf6602521..7fbddc9663 100644 --- a/web/src/billing/remote_billing_auth.ts +++ b/web/src/billing/remote_billing_auth.ts @@ -1,5 +1,32 @@ import $ from "jquery"; +function handle_submit_for_server_login_form(form: HTMLFormElement): void { + // Get value of server_org_id. + const server_org_id = $("#server-org-id").val(); + const $error_field = $(".server_org_id-error"); + if (server_org_id === undefined) { + // Already handled by `validate` plugin. + return; + } + + // Check if server_org_id is in UUID4 format. + // https://melvingeorge.me/blog/check-if-string-valid-uuid-regex-javascript + // Regex was modified by linter after copying from above link according to this rule: + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/better-regex.md + const is_valid_uuid = /^[\da-f]{8}(?:\b-[\da-f]{4}){3}\b-[\da-f]{12}$/gi; + // Check if server_org_id is in UUID4 format. + if (!is_valid_uuid.test(server_org_id)) { + $error_field.text( + "Wrong zulip_org_id format. Check to make sure zulip_org_id and zulip_org_key are not swapped.", + ); + $error_field.show(); + return; + } + $("#server-login-form").find(".loader").css("display", "inline-block"); + $("#server-login-button .server-login-button-text").hide(); + form.submit(); +} + export function initialize(): void { $( "#server-login-form, #remote-billing-confirm-email-form, #remote-billing-confirm-login-form", @@ -7,6 +34,11 @@ export function initialize(): void { errorClass: "text-error", wrapper: "div", submitHandler(form) { + if (form.id === "server-login-form") { + handle_submit_for_server_login_form(form); + return; + } + $("#server-login-form").find(".loader").css("display", "inline-block"); $("#server-login-button .server-login-button-text").hide(); $("#remote-billing-confirm-email-form").find(".loader").css("display", "inline-block"); diff --git a/web/styles/portico/billing.css b/web/styles/portico/billing.css index 3d448a0077..47a2177446 100644 --- a/web/styles/portico/billing.css +++ b/web/styles/portico/billing.css @@ -686,7 +686,10 @@ input[name="licenses"] { } #server-login-error { - text-align: center; + text-align: left; + margin: 0 auto; + max-width: 400px; + padding: 10px 25px; } #upgrade-page-details #due-today-for-future-update-wrapper {