fix(web): remove password from public applications
This commit is contained in:
1 parent
0c59d8cb15
commit
e5bd31b428
9 files changed
+9
-91
No files matched your search
@@ -21,8 +21,7 @@
|
||||
</head>
|
||||
<body><main>
|
||||
<nav class="topnav"><a class="brand" href="/belki">Беличья нора</a><a href="/belki">Калькулятор отчётов</a></nav>
|
||||
<section id="auth" class="auth"><h2>Вход</h2><p class="hint">Введите пароль, чтобы подать заявку и приложить скриншоты.</p><form id="authForm"><label>Пароль<input id="password" type="password" autocomplete="current-password" required></label><p id="authError" class="error"></p><button class="primary" type="submit">Войти</button></form></section>
|
||||
<section id="app" class="hidden"><h1>Новая заявка</h1><p class="intro">Заполните форму — администратор получит структурированную заявку для рассмотрения. Не нужно готовить форумную отпись.</p>
|
||||
<section id="app"><h1>Новая заявка</h1><p class="intro">Заполните форму — администратор получит структурированную заявку для рассмотрения. Не нужно готовить форумную отпись.</p>
|
||||
<div class="types" role="radiogroup" aria-label="Тип заявки">
|
||||
<button class="type active" type="button" data-type="feather_donation">Пожертвовать перо отряду</button><button class="type" type="button" data-type="kitten">Хочу стать бельчонком</button><button class="type" type="button" data-type="flying_squirrel">Хочу стать белкой-летягой</button><button class="type" type="button" data-type="curator">Хочу стать куратором</button>
|
||||
</div>
|
||||
@@ -36,9 +35,7 @@
|
||||
</div><p id="error" class="error" role="alert"></p><div class="actions"><button class="primary" type="submit">Отправить заявку</button></div></form><div id="success" class="success hidden"></div>
|
||||
</section>
|
||||
</main><script>
|
||||
const auth=document.querySelector('#auth'), app=document.querySelector('#app'), form=document.querySelector('#form'), error=document.querySelector('#error'); let active='feather_donation';
|
||||
function activate(){auth.classList.add('hidden');app.classList.remove('hidden')} async function session(){const r=await fetch('/api/web/session');const d=await r.json();if(d.authenticated)activate()}
|
||||
document.querySelector('#authForm').addEventListener('submit',async e=>{e.preventDefault();const r=await fetch('/api/web/auth',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({password:document.querySelector('#password').value})});const d=await r.json();if(!r.ok){document.querySelector('#authError').textContent=d.error||'Не удалось войти';return}activate()});session().catch(()=>{});
|
||||
const form=document.querySelector('#form'), error=document.querySelector('#error'); let active='feather_donation';
|
||||
function addFeather(data={}){const row=document.createElement('div');row.className='feather';row.innerHTML='<label>Количество<input data-field="amount" type="number" min="1" required></label><label>Цвет<input data-field="color" placeholder="например, синие" required></label><label>Источник добычи<input data-field="source" placeholder="личные запасы, осмотр дупла…" required></label><button class="remove" type="button">Убрать</button>';Object.entries(data).forEach(([k,v])=>{const el=row.querySelector(`[data-field="${k}"]`);if(el)el.value=v});row.querySelector('.remove').onclick=()=>row.remove();document.querySelector('#feathers').append(row)} addFeather();document.querySelector('#addFeather').onclick=()=>addFeather();
|
||||
function sync(){document.querySelector('#featherFields').classList.toggle('hidden',active!=='feather_donation');document.querySelector('#kittenFields').classList.toggle('hidden',active!=='kitten');document.querySelector('#curatorFields').classList.toggle('hidden',active!=='curator');document.querySelector('#flyingFields').classList.toggle('hidden',active!=='flying_squirrel');document.querySelector('#vkField').classList.toggle('hidden',active!=='flying_squirrel');document.querySelectorAll('.type').forEach(x=>x.classList.toggle('active',x.dataset.type===active))} document.querySelectorAll('.type').forEach(b=>b.onclick=()=>{active=b.dataset.type;sync()});sync();
|
||||
document.querySelector('[name="practiced_before"]').onchange=e=>document.querySelector('#practiceLink').classList.toggle('hidden',e.target.value!=='yes');
|
||||
|
||||
+1
-37
@@ -150,16 +150,7 @@
|
||||
</section>
|
||||
|
||||
<section id="applicationsSection" class="hidden" role="tabpanel" aria-labelledby="applicationsTab">
|
||||
<div id="applicationAuth" class="panel auth-panel">
|
||||
<h2>Подача заявки</h2>
|
||||
<p class="muted">Введите пароль, чтобы отправить заявку на рассмотрение и приложить скриншоты.</p>
|
||||
<form id="applicationAuthForm">
|
||||
<label>Пароль<input id="applicationPassword" type="password" autocomplete="current-password" required></label>
|
||||
<p id="applicationAuthError" class="error" role="alert"></p>
|
||||
<button class="primary" type="submit">Войти</button>
|
||||
</form>
|
||||
</div>
|
||||
<div id="applicationWorkspace" class="hidden">
|
||||
<div id="applicationWorkspace">
|
||||
<h2>Новая заявка</h2>
|
||||
<p class="muted application-intro">Заполните форму — администратор получит структурированную заявку для рассмотрения. Форумную отпись готовить не нужно.</p>
|
||||
<div class="application-types" role="group" aria-label="Тип заявки">
|
||||
@@ -366,9 +357,6 @@
|
||||
const reportsSection = document.querySelector('#reportsSection');
|
||||
const applicationsSection = document.querySelector('#applicationsSection');
|
||||
const sectionTabs = [...document.querySelectorAll('[data-section]')];
|
||||
const applicationAuth = document.querySelector('#applicationAuth');
|
||||
const applicationWorkspace = document.querySelector('#applicationWorkspace');
|
||||
const applicationAuthError = document.querySelector('#applicationAuthError');
|
||||
const applicationForm = document.querySelector('#applicationForm');
|
||||
const applicationError = document.querySelector('#applicationError');
|
||||
const applicationSuccess = document.querySelector('#applicationSuccess');
|
||||
@@ -385,7 +373,6 @@
|
||||
tab.classList.toggle('active', selected);
|
||||
tab.setAttribute('aria-selected', String(selected));
|
||||
});
|
||||
if (isApplications) checkApplicationSession();
|
||||
if (updateUrl) {
|
||||
const url = new URL(window.location.href);
|
||||
if (isApplications) url.searchParams.set('section', 'applications');
|
||||
@@ -396,29 +383,6 @@
|
||||
sectionTabs.forEach(tab => tab.addEventListener('click', () => setSection(tab.dataset.section)));
|
||||
window.addEventListener('popstate', () => setSection(new URLSearchParams(window.location.search).get('section') === 'applications' ? 'applications' : 'reports', false));
|
||||
|
||||
function showApplicationWorkspace() {
|
||||
applicationAuth.classList.add('hidden');
|
||||
applicationWorkspace.classList.remove('hidden');
|
||||
}
|
||||
async function checkApplicationSession() {
|
||||
try {
|
||||
const response = await fetch('/api/web/session');
|
||||
const data = await response.json();
|
||||
if (data.authenticated) showApplicationWorkspace();
|
||||
} catch (_) { /* The login form remains available and explains any error. */ }
|
||||
}
|
||||
document.querySelector('#applicationAuthForm').addEventListener('submit', async event => {
|
||||
event.preventDefault();
|
||||
applicationAuthError.textContent = '';
|
||||
const response = await fetch('/api/web/auth', {
|
||||
method: 'POST', headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({password: document.querySelector('#applicationPassword').value}),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) { applicationAuthError.textContent = data.error || 'Не удалось войти'; return; }
|
||||
showApplicationWorkspace();
|
||||
});
|
||||
|
||||
function addApplicationFeather(values = {}) {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'feather';
|
||||
|
||||
Reference in new issue
Block a user