Опубликовано через кнопку

This commit is contained in:
Balgyn 2026-08-21 11:02:43 +00:00
parent 8e3798be21
commit 3a5b0d0b4b
2 changed files with 67 additions and 13 deletions

View File

@ -73,6 +73,15 @@
font-size: 14px;
display: none;
}
.login-box .loading {
background: #dbeafe;
color: #1e40af;
padding: 12px;
border-radius: 6px;
margin-bottom: 20px;
font-size: 14px;
display: none;
}
.demo-users {
margin-top: 24px;
padding-top: 24px;
@ -107,6 +116,7 @@
<h1>Контроль исполнения поручений СД</h1>
<p class="subtitle">Войдите для продолжения работы</p>
<div class="loading" id="loadingMsg">Проверка...</div>
<div class="error" id="errorMsg"></div>
<form id="loginForm">
@ -118,7 +128,7 @@
<label for="password">Пароль</label>
<input type="password" id="password" name="password" required placeholder="Введите пароль">
</div>
<button type="submit">Войти</button>
<button type="submit" id="submitBtn">Войти</button>
</form>
<div class="demo-users">
@ -140,24 +150,67 @@
window.location = "index.html";
}
// Встроенные пользователи (резервный вариант если API не работает)
const USERS = [
{ login: "admin", password: "admin", role: "admin", name: "Администратор" },
{ login: "pmo", password: "pmo", role: "pmo", name: "Сотрудник ПО" },
{ login: "ivanov", password: "123", role: "rm", name: "Иванов А.С." },
{ login: "petrova", password: "123", role: "rm", name: "Петрова В.И." },
{ login: "executor", password: "123", role: "executor", name: "Исполнитель" }
];
document.getElementById("loginForm").addEventListener("submit", async (e) => {
e.preventDefault();
const login = document.getElementById("login").value;
const password = document.getElementById("password").value;
const btn = document.getElementById("submitBtn");
const errorEl = document.getElementById("errorMsg");
const loadingEl = document.getElementById("loadingMsg");
btn.disabled = true;
btn.textContent = "Проверка...";
errorEl.style.display = "none";
loadingEl.style.display = "block";
try {
// Пробуем через API
const res = await fetch("/api/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ login, password })
});
if (res.ok) {
const result = await res.json();
if (result.ok) {
localStorage.setItem("sdCurrentUser", JSON.stringify(result.user));
window.location = "index.html";
return;
}
}
// Если API не сработало — проверяем локально
const user = USERS.find(u => u.login === login && u.password === password);
if (user) {
localStorage.setItem("sdCurrentUser", JSON.stringify(user));
window.location = "index.html";
} else {
document.getElementById("errorMsg").textContent = result.error || "Ошибка входа";
document.getElementById("errorMsg").style.display = "block";
throw new Error("Неверный логин или пароль");
}
} catch (err) {
// Фоллбэк на локальную проверку
const user = USERS.find(u => u.login === login && u.password === password);
if (user) {
localStorage.setItem("sdCurrentUser", JSON.stringify(user));
window.location = "index.html";
} else {
errorEl.textContent = "Неверный логин или пароль";
errorEl.style.display = "block";
}
} finally {
loadingEl.style.display = "none";
btn.disabled = false;
btn.textContent = "Войти";
}
});
</script>

View File

@ -32,6 +32,7 @@ function updateStatuses(instructions) {
}
http.createServer(async (req, res) => {
console.log(req.method, req.url);
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");