Add email login fallback (for testing outside Telegram)

WebApp detects if Telegram SDK is missing, shows email login form
so we can test without the bot running.
This commit is contained in:
root 2026-08-20 17:52:38 +00:00
parent 21d281a1c6
commit 897fc4cd31

View File

@ -31,7 +31,8 @@ const App = {
this.showError('Сессия истекла: ' + e.message);
}
} else {
this.showError('Откройте BuhApp через бота @buhoiapp_bot');
// WebApp открыт вне Telegram — предложим email login
this.showEmailLogin();
}
// bind input events for chat
@ -117,6 +118,68 @@ const App = {
`;
},
showEmailLogin() {
document.getElementById('app').innerHTML = `
<div class="view">
<h1>🍻 BuhApp</h1>
<div class="sub">Приложение для поиска компании (Telegram Mini App)</div>
<div class="card">
<div style="background:var(--warning);color:#000;padding:8px 12px;border-radius:8px;margin-bottom:12px;font-size:13px;">
WebApp лучше открывать через Telegram там авторизация автоматическая.
Здесь можно зайти по email для тестирования.
</div>
<label>Email</label>
<input class="input" id="el-email" type="email" placeholder="you@example.com">
<label>Пароль</label>
<input class="input" id="el-pass" type="password" placeholder="минимум 8 символов">
<button class="btn" id="el-login">Войти</button>
<button class="btn ghost" id="el-register">Регистрация</button>
</div>
<div class="card" style="font-size:12px;color:var(--text-dim);">
🍻 BuhApp приложение для лиц 18+. Встречи и употребление алкоголя на свой риск.
Принимая соглашение, вы подтверждаете совершеннолетие.
</div>
</div>
`;
document.getElementById('el-login').onclick = () => this.emailLogin();
document.getElementById('el-register').onclick = () => this.emailRegister();
},
async emailLogin() {
const email = document.getElementById('el-email').value.trim();
const pass = document.getElementById('el-pass').value;
try {
await API.Auth.loginEmail(email, pass);
await API.Auth.me();
await this.checkConsent();
this.showView('map');
} catch (e) {
TG_APP.showAlert('Ошибка: ' + e.message);
}
},
async emailRegister() {
const email = document.getElementById('el-email').value.trim();
const pass = document.getElementById('el-pass').value;
if (!email || pass.length < 8) {
TG_APP.showAlert('Email и пароль (≥8 символов) обязательны');
return;
}
try {
await API.Auth.registerEmail({
email,
password: pass,
name: email.split('@')[0],
consents: { adult: true, terms: true, privacy: true, disclaimer: true },
});
await API.Auth.me();
this.consentGiven = true;
this.showView('map');
} catch (e) {
TG_APP.showAlert('Ошибка: ' + e.message);
}
},
showView(name, params = {}) {
document.querySelectorAll('.tab').forEach(t => t.classList.toggle('active', t.dataset.view === name));