Files
coremarket/app/static/login.html
T
2026-12-02 09:46:25 -07:00

47 lines
1.9 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sign in: Coremarket</title>
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
<link rel="stylesheet" href="/static/style.css">
</head>
<body class="login-page">
<form id="loginForm" class="card login-card">
<h1>Coremarket</h1>
<p class="muted small">Sign in to size and price Federated Core VMs.</p>
<label>Username <input id="username" name="username" autocomplete="username" required autofocus></label>
<label>Password <input id="password" name="password" type="password" autocomplete="current-password" required></label>
<p id="loginErr" class="err small" role="alert"></p>
<button type="submit" id="loginBtn">Sign in</button>
<p class="muted small">No account? Ask your Coremarket administrator.</p>
</form>
<script>
"use strict";
const form = document.getElementById("loginForm");
form.onsubmit = async (e) => {
e.preventDefault();
const btn = document.getElementById("loginBtn"), err = document.getElementById("loginErr");
btn.disabled = true; err.textContent = "";
try {
const r = await fetch("/api/v1/auth/login", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username: form.username.value.trim(), password: form.password.value }),
});
if (!r.ok) {
let msg = "Sign-in failed.";
try { msg = (await r.json()).detail || msg; } catch (_) {}
throw new Error(typeof msg === "string" ? msg : "Sign-in failed.");
}
const next = new URLSearchParams(location.search).get("next") || "/";
location.href = next.startsWith("/") && !next.startsWith("//") ? next : "/";
} catch (ex) {
err.textContent = ex.message.charAt(0).toUpperCase() + ex.message.slice(1);
form.password.value = ""; form.password.focus();
} finally { btn.disabled = false; }
};
</script>
</body>
</html>