Files
mtusi2026lab2/web/index.html
T

152 lines
6.5 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Relay — lab2 messenger</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="./app.css" />
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<span class="brand-mark" aria-hidden="true"></span>
<div>
<p class="brand-name">Relay</p>
<p class="brand-sub">lab2 · postgres · redis sessions</p>
</div>
</div>
<div class="topbar-status" id="ready-pill" title="GET /health/ready">
<span class="dot"></span>
<span id="ready-label">checking</span>
</div>
</header>
<main id="gate" class="gate hidden">
<section class="gate-panel">
<h1>Сессии и чаты на живом API</h1>
<p class="lede">
Регистрация пишет пользователя в PostgreSQL. Вход через Basic выдаёт opaque Bearer в Redis.
Дальше все запросы идут только с Bearer — как в контракте lab2.
</p>
<div class="tabs" role="tablist">
<button type="button" class="tab is-active" data-tab="login" role="tab" aria-selected="true">Вход</button>
<button type="button" class="tab" data-tab="register" role="tab" aria-selected="false">Регистрация</button>
</div>
<form id="form-login" class="stack" autocomplete="on">
<label>
<span>username</span>
<input name="username" required minlength="3" maxlength="32" pattern="[a-z0-9_]+" placeholder="alice" />
</label>
<label>
<span>password ≥ 12</span>
<input name="password" type="password" required minlength="12" maxlength="128" autocomplete="current-password" />
</label>
<button type="submit" class="btn primary">Войти · Basic → Bearer</button>
</form>
<form id="form-register" class="stack hidden" autocomplete="on">
<label>
<span>username</span>
<input name="username" required minlength="3" maxlength="32" pattern="[a-z0-9_]+" placeholder="bob" />
</label>
<label>
<span>display name</span>
<input name="display_name" required maxlength="100" placeholder="Боб" />
</label>
<label>
<span>password ≥ 12</span>
<input name="password" type="password" required minlength="12" maxlength="128" autocomplete="new-password" />
</label>
<button type="submit" class="btn primary">Создать пользователя</button>
</form>
<p class="hint">username: только <code>a-z</code>, цифры и <code>_</code>. После регистрации сразу можно войти.</p>
<p id="gate-error" class="error" hidden></p>
</section>
</main>
<main id="shell" class="shell hidden">
<aside class="sidebar">
<section class="me-card">
<div class="me-row">
<div>
<p class="me-name" id="me-display">—</p>
<p class="me-user" id="me-username">@—</p>
</div>
<button type="button" class="btn ghost" id="btn-logout" title="DELETE /auth/sessions/current">Выйти</button>
</div>
<dl class="meta">
<div>
<dt>user id</dt>
<dd><code id="me-id">—</code> <button type="button" class="linkish" id="btn-copy-id">copy</button></dd>
</div>
<div>
<dt>session expires</dt>
<dd id="me-expires">—</dd>
</div>
</dl>
</section>
<div class="sidebar-head">
<h2>Чаты</h2>
<button type="button" class="btn small" id="btn-new-chat">+ новый</button>
</div>
<ul id="chat-list" class="chat-list"></ul>
<p id="chats-empty" class="empty">Пока нет чатов. Создайте первый и добавьте user id собеседника.</p>
</aside>
<section class="stage">
<div id="stage-empty" class="stage-empty">
<h2>Выберите чат</h2>
<p>Или создайте новый. Чтобы писать вдвоём, откройте второй браузер / окно инкогнито и залогиньтесь вторым пользователем.</p>
</div>
<div id="stage-chat" class="stage-chat hidden">
<header class="chat-head">
<div>
<h2 id="chat-title">—</h2>
<p class="chat-members" id="chat-members"></p>
</div>
<button type="button" class="btn ghost small" id="btn-refresh">обновить</button>
</header>
<div id="messages" class="messages" aria-live="polite"></div>
<form id="form-message" class="composer">
<textarea name="text" rows="2" maxlength="4000" placeholder="Сообщение…" required></textarea>
<button type="submit" class="btn primary">Отправить</button>
</form>
</div>
</section>
</main>
</div>
<dialog id="dialog-chat" class="dialog">
<form method="dialog" id="form-chat" class="stack">
<h3>Новый чат</h3>
<p class="lede tight">Вы уже включены в участники. Добавьте UUID других пользователей (через запятую или с новой строки).</p>
<label>
<span>title</span>
<input name="title" required maxlength="100" placeholder="Проект по ВНП" />
</label>
<label>
<span>member ids</span>
<textarea name="member_ids" rows="3" placeholder="22222222-2222-4222-8222-222222222222"></textarea>
</label>
<p id="chat-error" class="error" hidden></p>
<div class="row">
<button type="submit" class="btn primary" value="ok">Создать</button>
<button type="button" class="btn ghost" id="btn-cancel-chat">Отмена</button>
</div>
</form>
</dialog>
<div id="toast" class="toast" hidden></div>
<script src="./app.js" type="module"></script>
</body>
</html>