This commit is contained in:
2026-05-18 08:38:30 +02:00
parent eddba45f4e
commit 28e3053a6a
39 changed files with 55 additions and 29 deletions

View File

@@ -4,6 +4,10 @@ const errmsg = `
</div>
`;
function navigateTop(page) {
window.open(new URL(page, window.location.href).href, "_top");
}
document.getElementById("login-form").addEventListener("submit", async function(event) {
event.preventDefault();
@@ -14,6 +18,7 @@ document.getElementById("login-form").addEventListener("submit", async function(
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;
const form = document.getElementById("login-form");
const cookiePath = window.location.pathname.replace(/[^/]+$/, "/");
try {
const response = await fetch("https://ssnj.dcrubro.com/api/prijava", {
@@ -28,10 +33,10 @@ document.getElementById("login-form").addEventListener("submit", async function(
if (response.status === 200) {
// Nastavi cookie, 3 ure veljaven
document.cookie = `token=${data.token}; max-age=${3 * 60 * 60}; path=/; secure; samesite=strict`;
document.cookie = `username=${username}; max-age=${3 * 60 * 60}; path=/; secure; samesite=strict`;
document.cookie = `token=${data.token}; max-age=${3 * 60 * 60}; path=${cookiePath}; samesite=strict`;
document.cookie = `username=${username}; max-age=${3 * 60 * 60}; path=${cookiePath}; samesite=strict`;
window.location.href = "index.html";
navigateTop("index.html");
return;
}