From 3a5b0d0b4b99923eeac3380ea672bc7a530386d4 Mon Sep 17 00:00:00 2001 From: Balgyn Date: Fri, 21 Aug 2026 11:02:43 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BF=D1=83=D0=B1=D0=BB=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7?= =?UTF-8?q?=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- login.html | 79 +++++++++++++++++++++++++++++++++++++++++++++--------- server.js | 1 + 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/login.html b/login.html index 920d037..50493c1 100644 --- a/login.html +++ b/login.html @@ -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 @@

Контроль исполнения поручений СД

Войдите для продолжения работы

+
Проверка...
@@ -118,7 +128,7 @@ - +
@@ -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"); - const res = await fetch("/api/login", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ login, password }) - }); + btn.disabled = true; + btn.textContent = "Проверка..."; + errorEl.style.display = "none"; + loadingEl.style.display = "block"; - const result = await res.json(); - if (result.ok) { - localStorage.setItem("sdCurrentUser", JSON.stringify(result.user)); - window.location = "index.html"; - } else { - document.getElementById("errorMsg").textContent = result.error || "Ошибка входа"; - document.getElementById("errorMsg").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 { + 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 = "Войти"; } }); diff --git a/server.js b/server.js index d6f0be3..07723cf 100644 --- a/server.js +++ b/server.js @@ -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");