mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
billing: Redirect user to login page if session expires.
If user makes an AJAX request but their session is expired, we redirect user to the login page.
This commit is contained in:
@@ -2,6 +2,7 @@ from functools import wraps
|
||||
from typing import Callable, Optional
|
||||
from urllib.parse import urlencode, urljoin
|
||||
|
||||
import orjson
|
||||
from django.conf import settings
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
@@ -104,6 +105,18 @@ def authenticated_remote_realm_management_endpoint(
|
||||
query = urlencode({"next_page": page_type})
|
||||
url = append_url_query_string(url, query)
|
||||
|
||||
# Return error for AJAX requests with url.
|
||||
if request.headers.get("x-requested-with") == "XMLHttpRequest": # nocoverage
|
||||
return HttpResponse(
|
||||
orjson.dumps(
|
||||
{
|
||||
"error_message": "Remote billing authentication expired",
|
||||
"login_url": url,
|
||||
}
|
||||
),
|
||||
status=401,
|
||||
)
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
billing_session = RemoteRealmBillingSession(
|
||||
|
||||
@@ -102,6 +102,14 @@ export function create_ajax_request(
|
||||
}
|
||||
$(form_input_section).show();
|
||||
error_callback(xhr);
|
||||
|
||||
if (xhr.status === 401) {
|
||||
// User session timed out, we need to login again.
|
||||
const login_url = JSON.parse(xhr.responseText)?.login_url;
|
||||
if (login_url !== undefined) {
|
||||
window.location.href = login_url;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user