feat: мульти-пользовательская авторизация через invite + email
- SQLite: таблицы users (email, password_hash, role, verified) + invites - auth.py: register_user, verify_email, hash_password + legacy env user - email_service.py: SMTP Timeweb (smtp.timeweb.ru:465) — код подтверждения - API: POST /api/register, /api/verify-email, /api/admin/invite - UI: /register?invite=TOKEN — 3-шаговая регистрация - Admin: кнопка создать приглашение, список invites + users - Обратная совместимость: env user (smeta) = admin Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Регистрация — Сметный ИИ-ассистент</title>
|
||||
<style>
|
||||
:root { --bg: #f5f0eb; --card: #fff; --text: #3a3a3a; --muted: #6b6b6b; --accent: #c4463a; --border: #d4c5b2; --radius: 10px; --green: #2d8a56; }
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
|
||||
.card { background: var(--card); border-radius: var(--radius); padding: 2rem; width: 380px; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
|
||||
h1 { font-size: 1.2rem; margin-bottom: .3rem; }
|
||||
.subtitle { color: var(--muted); font-size: .85rem; margin-bottom: 1.5rem; }
|
||||
label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .85rem; }
|
||||
input { width: 100%; padding: .6rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: .9rem; margin-bottom: 1rem; font-family: inherit; }
|
||||
input:focus { outline: none; border-color: var(--accent); }
|
||||
button { width: 100%; padding: .7rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: .95rem; font-weight: 600; cursor: pointer; }
|
||||
button:hover { background: #a83830; }
|
||||
button:disabled { background: var(--border); cursor: not-allowed; }
|
||||
.error { color: var(--accent); font-size: .85rem; margin-bottom: .5rem; display: none; }
|
||||
.success { color: var(--green); font-size: .85rem; margin-bottom: .5rem; display: none; }
|
||||
.link { color: var(--accent); text-decoration: none; font-size: .85rem; }
|
||||
.link:hover { text-decoration: underline; }
|
||||
.step { display: none; }
|
||||
.step.active { display: block; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="card">
|
||||
<h1>Регистрация</h1>
|
||||
<p class="subtitle">Сметный ИИ-ассистент</p>
|
||||
|
||||
<!-- Step 1: Email + Password -->
|
||||
<div class="step active" id="step1">
|
||||
<div class="error" id="err1"></div>
|
||||
<label>Email</label>
|
||||
<input type="email" id="reg-email" placeholder="your@email.com">
|
||||
<label>Пароль</label>
|
||||
<input type="password" id="reg-pass" placeholder="Минимум 6 символов">
|
||||
<label>Повторите пароль</label>
|
||||
<input type="password" id="reg-pass2" placeholder="Повторите пароль">
|
||||
<button onclick="doRegister()">Зарегистрироваться</button>
|
||||
<p style="margin-top:1rem;text-align:center"><a class="link" href="/">Уже есть аккаунт? Войти</a></p>
|
||||
</div>
|
||||
|
||||
<!-- Step 2: Verification code -->
|
||||
<div class="step" id="step2">
|
||||
<div class="success" id="msg2"></div>
|
||||
<div class="error" id="err2"></div>
|
||||
<label>Код подтверждения</label>
|
||||
<p style="color:var(--muted);font-size:.8rem;margin-bottom:.5rem">Код отправлен на <b id="sent-email"></b></p>
|
||||
<input type="text" id="verify-code" placeholder="000000" maxlength="6" style="text-align:center;font-size:1.5rem;letter-spacing:8px">
|
||||
<button onclick="doVerify()">Подтвердить</button>
|
||||
</div>
|
||||
|
||||
<!-- Step 3: Success -->
|
||||
<div class="step" id="step3">
|
||||
<div class="success" style="display:block">Email подтверждён! Можете войти.</div>
|
||||
<br>
|
||||
<button onclick="window.location.href='/'">Войти</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Get invite token from URL
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const inviteToken = params.get('invite') || '';
|
||||
let regEmail = '';
|
||||
|
||||
function showStep(n) {
|
||||
document.querySelectorAll('.step').forEach(s => s.classList.remove('active'));
|
||||
document.getElementById('step' + n).classList.add('active');
|
||||
}
|
||||
|
||||
async function doRegister() {
|
||||
const email = document.getElementById('reg-email').value.trim();
|
||||
const pass = document.getElementById('reg-pass').value;
|
||||
const pass2 = document.getElementById('reg-pass2').value;
|
||||
const err = document.getElementById('err1');
|
||||
err.style.display = 'none';
|
||||
|
||||
if (!email || !pass) { err.textContent = 'Заполните все поля'; err.style.display = 'block'; return; }
|
||||
if (pass !== pass2) { err.textContent = 'Пароли не совпадают'; err.style.display = 'block'; return; }
|
||||
if (pass.length < 6) { err.textContent = 'Пароль минимум 6 символов'; err.style.display = 'block'; return; }
|
||||
if (!inviteToken) { err.textContent = 'Нужна ссылка-приглашение от администратора'; err.style.display = 'block'; return; }
|
||||
|
||||
try {
|
||||
const r = await fetch('/api/register', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({email, password: pass, invite: inviteToken}),
|
||||
});
|
||||
const data = await r.json();
|
||||
if (!r.ok) { err.textContent = data.detail || 'Ошибка регистрации'; err.style.display = 'block'; return; }
|
||||
|
||||
regEmail = email;
|
||||
document.getElementById('sent-email').textContent = email;
|
||||
document.getElementById('msg2').textContent = data.message;
|
||||
document.getElementById('msg2').style.display = 'block';
|
||||
showStep(2);
|
||||
} catch(e) { err.textContent = 'Ошибка сети'; err.style.display = 'block'; }
|
||||
}
|
||||
|
||||
async function doVerify() {
|
||||
const code = document.getElementById('verify-code').value.trim();
|
||||
const err = document.getElementById('err2');
|
||||
err.style.display = 'none';
|
||||
|
||||
if (!code) { err.textContent = 'Введите код'; err.style.display = 'block'; return; }
|
||||
|
||||
try {
|
||||
const r = await fetch('/api/verify-email', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({email: regEmail, code}),
|
||||
});
|
||||
const data = await r.json();
|
||||
if (!r.ok) { err.textContent = data.detail || 'Неверный код'; err.style.display = 'block'; return; }
|
||||
showStep(3);
|
||||
} catch(e) { err.textContent = 'Ошибка сети'; err.style.display = 'block'; }
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user