中控
This commit is contained in:
@@ -41,11 +41,34 @@
|
||||
const userInput = document.getElementById("login-username");
|
||||
const params = new URLSearchParams(location.search);
|
||||
const next = params.get("next") || "/monitor";
|
||||
const inFrame = window.self !== window.top;
|
||||
|
||||
function gotoAfterLogin(token, dest) {
|
||||
const target = dest.startsWith("/") ? dest : "/monitor";
|
||||
if (token && inFrame) {
|
||||
const q = new URLSearchParams({ token, next: target });
|
||||
const embedUrl = "/embed-auth?" + q.toString();
|
||||
try {
|
||||
window.parent.postMessage(
|
||||
{
|
||||
type: "hub:login-ok",
|
||||
session_token: token,
|
||||
next: target,
|
||||
embed_auth_url: location.origin + embedUrl,
|
||||
},
|
||||
"*"
|
||||
);
|
||||
} catch (_) {}
|
||||
location.replace(embedUrl);
|
||||
return;
|
||||
}
|
||||
location.href = target;
|
||||
}
|
||||
|
||||
fetch("/api/auth/status")
|
||||
.then((r) => r.json())
|
||||
.then((s) => {
|
||||
if (!s.required || s.logged_in) location.href = next;
|
||||
if (!s.required || s.logged_in) gotoAfterLogin(null, next);
|
||||
if (s.username_hint && !userInput.value) userInput.value = s.username_hint;
|
||||
})
|
||||
.catch(() => {});
|
||||
@@ -63,7 +86,7 @@
|
||||
});
|
||||
const j = await r.json().catch(() => ({}));
|
||||
if (r.ok && j.ok) {
|
||||
location.href = next.startsWith("/") ? next : "/monitor";
|
||||
gotoAfterLogin(j.session_token || null, next);
|
||||
return;
|
||||
}
|
||||
err.textContent = j.detail || j.msg || "用户名或密码错误";
|
||||
|
||||
Reference in New Issue
Block a user