Compare commits
12 Commits
22cb9bed51
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 757839eba6 | |||
| f54eb04a2e | |||
| d282175209 | |||
|
|
24adc04b8f | ||
| 0ae5567cc6 | |||
| f2e92d246e | |||
| da9f9bf588 | |||
| d502146b43 | |||
| e21d2cafaa | |||
| ab62cfbd45 | |||
| be3b0e91f4 | |||
| ade16e6417 |
189
index.html
189
index.html
@@ -1,74 +1,149 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="ru">
|
<html lang="ru">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8" />
|
||||||
<title>Lendry SSO - Заглушка</title>
|
<title>Lendry SSO - Заглушка</title>
|
||||||
<style>
|
<style>
|
||||||
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f3f4f6; }
|
body {
|
||||||
.login-card { background: white; padding: 2rem; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); width: 100%; max-width: 320px; text-align: center; }
|
font-family:
|
||||||
h2 { margin-top: 0; color: #111827; }
|
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||||
input { width: 100%; padding: 10px; margin-bottom: 15px; border: 1px solid #d1d5db; border-radius: 6px; box-sizing: border-box; font-size: 16px; }
|
display: flex;
|
||||||
button { width: 100%; padding: 10px; background-color: #2563eb; color: white; border: none; border-radius: 6px; font-size: 16px; font-weight: 600; cursor: pointer; transition: background 0.2s; }
|
justify-content: center;
|
||||||
button:hover { background-color: #1d4ed8; }
|
align-items: center;
|
||||||
.error { color: #dc2626; font-size: 14px; margin-top: 10px; display: none; }
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
background-color: #f3f4f6;
|
||||||
|
}
|
||||||
|
.login-card {
|
||||||
|
background: white;
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||||
|
width: 100%;
|
||||||
|
max-width: 320px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
margin-top: 0;
|
||||||
|
color: #111827;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
border: 1px solid #d1d5db;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: #2563eb;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background-color: #1d4ed8;
|
||||||
|
}
|
||||||
|
.error {
|
||||||
|
color: #dc2626;
|
||||||
|
font-size: 14px;
|
||||||
|
margin-top: 10px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="login-card">
|
<div class="login-card">
|
||||||
<h2>Вход в Lendry</h2>
|
<h2>Вход в Lendry</h2>
|
||||||
<p style="font-size: 12px; color: #6b7280; margin-bottom: 20px;">Frontend-заглушка для теста SSO</p>
|
<p style="font-size: 12px; color: #6b7280; margin-bottom: 20px">
|
||||||
|
Frontend-заглушка для теста SSO
|
||||||
|
</p>
|
||||||
|
|
||||||
<form id="loginForm">
|
<form id="loginForm">
|
||||||
<input type="text" id="username" value="" placeholder="Логин" required>
|
<input
|
||||||
<input type="password" id="password" value="" placeholder="Пароль" required>
|
type="text"
|
||||||
<button type="submit">Войти и вернуться в сервис</button>
|
id="username"
|
||||||
</form>
|
value=""
|
||||||
<div id="error" class="error"></div>
|
placeholder="Логин"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="password"
|
||||||
|
value=""
|
||||||
|
placeholder="Пароль"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<button type="submit">Войти и вернуться в сервис</button>
|
||||||
|
</form>
|
||||||
|
<div id="error" class="error"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
document
|
||||||
e.preventDefault();
|
.getElementById("loginForm")
|
||||||
const errorEl = document.getElementById('error');
|
.addEventListener("submit", async (e) => {
|
||||||
errorEl.style.display = 'none';
|
e.preventDefault();
|
||||||
|
const errorEl = document.getElementById("error");
|
||||||
|
errorEl.style.display = "none";
|
||||||
|
|
||||||
const username = document.getElementById('username').value;
|
let username = document.getElementById("username").value;
|
||||||
const password = document.getElementById('password').value;
|
let password = document.getElementById("password").value;
|
||||||
|
|
||||||
try {
|
console.log(username + password);
|
||||||
// 1. Делаем реальный запрос к вашему API Gateway
|
let json = JSON.stringify({
|
||||||
const response = await fetch('https://api.dev.lendry.ru/auth/login', {
|
username,
|
||||||
method: 'POST',
|
password,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
deviceId: "stub-device",
|
||||||
// Добавил device_id и public_key (как требует ваш auth.proto)
|
publicKey: "N6fByS7oTIOX6m7on8h6T093SOn3df67o6v6n6n6n6o=",
|
||||||
body: JSON.stringify({ username, password, deviceId: 'stub-device', publicKey: 'N6fByS7oTIOX6m7on8h6T093SOn3df67o6v6n6n6n6o=' }),
|
});
|
||||||
// КРИТИЧЕСКИ ВАЖНО: заставляет браузер сохранить куку refreshToken
|
try {
|
||||||
credentials: 'include'
|
// 1. Делаем реальный запрос к вашему API Gateway
|
||||||
});
|
const response = await fetch(
|
||||||
|
"http://docker.mvk.lpr:4000/auth/login",
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
// Добавил device_id и public_key (как требует ваш auth.proto)
|
||||||
|
body: json,
|
||||||
|
// КРИТИЧЕСКИ ВАЖНО: заставляет браузер сохранить куку refreshToken
|
||||||
|
credentials: "include",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
console.log(result);
|
||||||
|
|
||||||
if (response.ok && result.data && result.data.status === 'OK') {
|
if (response.ok && result.data && result.data.status === "OK") {
|
||||||
// 2. Ищем, куда нас просили вернуться
|
// 2. Ищем, куда нас просили вернуться
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const returnUrl = urlParams.get('returnUrl');
|
const returnUrl = urlParams.get("returnUrl");
|
||||||
|
if (returnUrl) {
|
||||||
if (returnUrl) {
|
// 3. Перенаправляем пользователя обратно на Gateway (который перекинет в Grafana)
|
||||||
// 3. Перенаправляем пользователя обратно на Gateway (который перекинет в Grafana)
|
window.location.href = returnUrl;
|
||||||
window.location.href = returnUrl;
|
} else {
|
||||||
} else {
|
alert(
|
||||||
alert('Успешный вход! Но параметр returnUrl не найден. Вы авторизованы.');
|
"Успешный вход! Но параметр returnUrl не найден. Вы авторизованы.",
|
||||||
}
|
);
|
||||||
} else {
|
}
|
||||||
errorEl.textContent = result.message || 'Неверный логин или пароль';
|
} else {
|
||||||
errorEl.style.display = 'block';
|
errorEl.textContent =
|
||||||
}
|
result.message || "Неверный логин или пароль";
|
||||||
} catch (err) {
|
errorEl.style.display = "block";
|
||||||
console.error(err);
|
|
||||||
errorEl.textContent = 'Ошибка сети. Проверьте консоль.';
|
|
||||||
errorEl.style.display = 'block';
|
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
errorEl.textContent = "Ошибка сети. Проверьте консоль.";
|
||||||
|
errorEl.style.display = "block";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user