Compare commits
12 Commits
22cb9bed51
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 757839eba6 | |||
| f54eb04a2e | |||
| d282175209 | |||
|
|
24adc04b8f | ||
| 0ae5567cc6 | |||
| f2e92d246e | |||
| da9f9bf588 | |||
| d502146b43 | |||
| e21d2cafaa | |||
| ab62cfbd45 | |||
| be3b0e91f4 | |||
| ade16e6417 |
145
index.html
145
index.html
@@ -1,74 +1,149 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Lendry SSO - Заглушка</title>
|
||||
<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; }
|
||||
.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; }
|
||||
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;
|
||||
}
|
||||
.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>
|
||||
</head>
|
||||
<body>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-card">
|
||||
<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">
|
||||
<input type="text" id="username" value="" placeholder="Логин" required>
|
||||
<input type="password" id="password" value="" placeholder="Пароль" required>
|
||||
<input
|
||||
type="text"
|
||||
id="username"
|
||||
value=""
|
||||
placeholder="Логин"
|
||||
required
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
value=""
|
||||
placeholder="Пароль"
|
||||
required
|
||||
/>
|
||||
<button type="submit">Войти и вернуться в сервис</button>
|
||||
</form>
|
||||
<div id="error" class="error"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
||||
document
|
||||
.getElementById("loginForm")
|
||||
.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const errorEl = document.getElementById('error');
|
||||
errorEl.style.display = 'none';
|
||||
const errorEl = document.getElementById("error");
|
||||
errorEl.style.display = "none";
|
||||
|
||||
const username = document.getElementById('username').value;
|
||||
const password = document.getElementById('password').value;
|
||||
let username = document.getElementById("username").value;
|
||||
let password = document.getElementById("password").value;
|
||||
|
||||
console.log(username + password);
|
||||
let json = JSON.stringify({
|
||||
username,
|
||||
password,
|
||||
deviceId: "stub-device",
|
||||
publicKey: "N6fByS7oTIOX6m7on8h6T093SOn3df67o6v6n6n6n6o=",
|
||||
});
|
||||
try {
|
||||
// 1. Делаем реальный запрос к вашему API Gateway
|
||||
const response = await fetch('https://api.dev.lendry.ru/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
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.stringify({ username, password, deviceId: 'stub-device', publicKey: 'N6fByS7oTIOX6m7on8h6T093SOn3df67o6v6n6n6n6o=' }),
|
||||
body: json,
|
||||
// КРИТИЧЕСКИ ВАЖНО: заставляет браузер сохранить куку refreshToken
|
||||
credentials: 'include'
|
||||
});
|
||||
credentials: "include",
|
||||
},
|
||||
);
|
||||
|
||||
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. Ищем, куда нас просили вернуться
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const returnUrl = urlParams.get('returnUrl');
|
||||
|
||||
const returnUrl = urlParams.get("returnUrl");
|
||||
if (returnUrl) {
|
||||
// 3. Перенаправляем пользователя обратно на Gateway (который перекинет в Grafana)
|
||||
window.location.href = returnUrl;
|
||||
} else {
|
||||
alert('Успешный вход! Но параметр returnUrl не найден. Вы авторизованы.');
|
||||
alert(
|
||||
"Успешный вход! Но параметр returnUrl не найден. Вы авторизованы.",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
errorEl.textContent = result.message || 'Неверный логин или пароль';
|
||||
errorEl.style.display = 'block';
|
||||
errorEl.textContent =
|
||||
result.message || "Неверный логин или пароль";
|
||||
errorEl.style.display = "block";
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
errorEl.textContent = 'Ошибка сети. Проверьте консоль.';
|
||||
errorEl.style.display = 'block';
|
||||
errorEl.textContent = "Ошибка сети. Проверьте консоль.";
|
||||
errorEl.style.display = "block";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user