remote_billing: Redirect via next_page param in legacy server flow.

Analogical to 1df8e00d7c which implemented
this for the RemoteRealm auth flow.
Except here we don't need to add next_page to the IdentityDict
(LegacyServerIdentityDict in this flow), because the redirect happens
immediately at remote_billing_legacy_server_login upon login - so no
need to have a structure to carry the info through intermediate steps.
This commit is contained in:
Mateusz Mandera 2023-12-03 02:16:14 +01:00 committed by Tim Abbott
parent 3d6863b5b9
commit 44ac99b8fc
2 changed files with 25 additions and 27 deletions

View File

@ -1,5 +1,5 @@
import logging import logging
from typing import Literal, Optional from typing import Any, Dict, Literal, Optional
from django.conf import settings from django.conf import settings
from django.core import signing from django.core import signing
@ -233,44 +233,31 @@ def remote_billing_legacy_server_login(
*, *,
server_org_id: Optional[str] = None, server_org_id: Optional[str] = None,
server_org_secret: Optional[str] = None, server_org_secret: Optional[str] = None,
next_page: VALID_NEXT_PAGES_TYPE = None,
) -> HttpResponse: ) -> HttpResponse:
context: Dict[str, Any] = {"next_page": next_page}
if server_org_id is None or server_org_secret is None: if server_org_id is None or server_org_secret is None:
# Should not be possible to submit the form like this, so this is the default context.update({"error_message": False})
# case, where the user just opened this page and therefore we render a fresh form. return render(request, "corporate/legacy_server_login.html", context)
return render(
request,
"corporate/legacy_server_login.html",
context={"error_message": False},
)
# The form must be submitted via POST.
if request.method != "POST": if request.method != "POST":
return HttpResponseNotAllowed(["POST"]) return HttpResponseNotAllowed(["POST"])
try: try:
remote_server = get_remote_server_by_uuid(server_org_id) remote_server = get_remote_server_by_uuid(server_org_id)
except RemoteZulipServer.DoesNotExist: except RemoteZulipServer.DoesNotExist:
return render( context.update(
request, {"error_message": _("Did not find a server registration for this server_org_id.")}
"corporate/legacy_server_login.html",
context={
"error_message": _("Did not find a server registration for this server_org_id.")
},
) )
return render(request, "corporate/legacy_server_login.html", context)
if not constant_time_compare(server_org_secret, remote_server.api_key): if not constant_time_compare(server_org_secret, remote_server.api_key):
return render( context.update({"error_message": _("Invalid server_org_secret.")})
request, return render(request, "corporate/legacy_server_login.html", context)
"corporate/legacy_server_login.html",
context={"error_message": _("Invalid server_org_secret.")},
)
if remote_server.deactivated:
return render(
request,
"corporate/legacy_server_login.html",
context={"error_message": _("Your server registration has been deactivated.")},
)
if remote_server.deactivated:
context.update({"error_message": _("Your server registration has been deactivated.")})
return render(request, "corporate/legacy_server_login.html", context)
remote_server_uuid = str(remote_server.uuid) remote_server_uuid = str(remote_server.uuid)
request.session["remote_billing_identities"] = {} request.session["remote_billing_identities"] = {}
@ -281,4 +268,12 @@ def remote_billing_legacy_server_login(
authenticated_at=datetime_to_timestamp(timezone_now()), authenticated_at=datetime_to_timestamp(timezone_now()),
) )
return HttpResponseRedirect(reverse("remote_server_billing_page", args=(remote_server_uuid,))) assert next_page in VALID_NEXT_PAGES
if next_page is None:
return HttpResponseRedirect(
reverse("remote_server_billing_page", args=(remote_server_uuid,))
)
else:
return HttpResponseRedirect(
reverse(f"remote_server_{next_page}_page", args=(remote_server_uuid,))
)

View File

@ -17,6 +17,9 @@
<div id="server-login-input-section"> <div id="server-login-input-section">
<form id="server-login-form" method="post" action="/serverlogin/"> <form id="server-login-form" method="post" action="/serverlogin/">
{{ csrf_input }} {{ csrf_input }}
{% if next_page %}
<input type="hidden" name="next_page" value="{{ next_page }}" />
{% endif %}
<div class="input-box server-login-form-field"> <div class="input-box server-login-form-field">
<label for="username" class="inline-block label-title"> <label for="username" class="inline-block label-title">
server_org_id server_org_id