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

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

View File

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