fix: confirm temporary hotspot login and show payment access countdown
build-image / build-push (push) Successful in 2m48s
build-image / build-push (push) Successful in 2m48s
This commit is contained in:
1 parent
bba6dcd37e
commit
0c01e5d88b
5 files changed
+105
-23
No files matched your search
@@ -477,6 +477,10 @@
|
||||
</header>
|
||||
|
||||
<!-- ===== PLANOS ===== -->
|
||||
<div class="card" style="margin-bottom:14px" role="status" aria-live="polite">
|
||||
<p id="freeAccessMessage">Verificando acesso temporário para pagamento…</p>
|
||||
<button class="btn btn-ghost" id="retryFreeAccess" type="button" hidden>Tentar liberar acesso</button>
|
||||
</div>
|
||||
<main id="view-plans">
|
||||
<div class="card">
|
||||
<div class="section-label">Planos disponíveis</div>
|
||||
@@ -804,9 +808,14 @@
|
||||
|
||||
// ===== Internet temporaria para pagar (login automatico no hotspot) =====
|
||||
async function startFreeAccess() {
|
||||
if (!mac) return;
|
||||
if (sessionStorage.getItem('freeOk') || sessionStorage.getItem('freeTried')) return;
|
||||
sessionStorage.setItem('freeTried', '1');
|
||||
const message = $('freeAccessMessage');
|
||||
const retry = $('retryFreeAccess');
|
||||
if (!/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i.test(mac)) {
|
||||
message.textContent = 'Para liberar internet temporária, conecte ao Wi-Fi de convidados e abra o portal pela tela de entrada da rede.';
|
||||
return;
|
||||
}
|
||||
retry.hidden = true;
|
||||
message.textContent = 'Preparando acesso temporário para abrir o aplicativo do banco…';
|
||||
try {
|
||||
const res = await fetch('/api/access/start', {
|
||||
method: 'POST',
|
||||
@@ -814,14 +823,41 @@
|
||||
body: JSON.stringify({ mac }),
|
||||
});
|
||||
const d = await res.json();
|
||||
if (!res.ok) { sessionStorage.removeItem('freeTried'); return; }
|
||||
if (d.loginUrl) {
|
||||
if (!res.ok) {
|
||||
message.textContent = res.status === 429 ? d.error + (d.retryAfterSeconds ? ' Tente em ' + d.retryAfterSeconds + ' segundos.' : '') : 'Não foi possível liberar a internet temporária. Tente novamente ou consulte o responsável pela rede.';
|
||||
retry.hidden = false;
|
||||
return;
|
||||
}
|
||||
if (d.authenticated) {
|
||||
sessionStorage.removeItem('freeLoginAttemptUntil');
|
||||
clearInterval(window.freeAccessTimer);
|
||||
const deadline = Date.now() + d.seconds * 1000;
|
||||
const update = () => {
|
||||
const seconds = Math.max(0, Math.ceil((deadline - Date.now()) / 1000));
|
||||
message.textContent = seconds ? 'Sessão temporária confirmada: ' + seconds + ' segundos para efetuar o pagamento.' : 'O acesso temporário terminou. Se já pagou, toque em “Já paguei”.';
|
||||
if (!seconds) { clearInterval(window.freeAccessTimer); retry.hidden = false; }
|
||||
};
|
||||
update(); window.freeAccessTimer = setInterval(update, 1000);
|
||||
return;
|
||||
}
|
||||
message.textContent = 'O MikroTik ainda não confirmou o acesso. Tentando autenticar pela tela do hotspot…';
|
||||
retry.hidden = false;
|
||||
if (d.loginUrl && Number(sessionStorage.getItem('freeLoginAttemptUntil') || 0) < Date.now()) {
|
||||
sessionStorage.setItem('freeLoginAttemptUntil', String(Date.now() + d.seconds * 1000));
|
||||
const target = new URL(d.loginUrl);
|
||||
hotspotLogin(target.searchParams.get('username'), target.searchParams.get('password'), target.searchParams.get('dst'));
|
||||
}
|
||||
} catch { /* segue */ }
|
||||
} catch {
|
||||
message.textContent = 'Falha ao verificar o acesso temporário. Toque em tentar liberar acesso.';
|
||||
retry.hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
$('retryFreeAccess').addEventListener('click', () => {
|
||||
sessionStorage.removeItem('freeLoginAttemptUntil');
|
||||
startFreeAccess();
|
||||
});
|
||||
|
||||
async function loadSiteConfig() {
|
||||
try {
|
||||
const res = await fetch('/api/config');
|
||||
@@ -831,8 +867,6 @@
|
||||
} catch { /* usa padrao */ }
|
||||
}
|
||||
|
||||
if (new URLSearchParams(location.search).get('free') === '1') sessionStorage.setItem('freeOk', '1');
|
||||
|
||||
loadSiteConfig().then(startFreeAccess);
|
||||
loadPlans();
|
||||
if (sessionStorage.getItem('paymentId')) {
|
||||
|
||||
Reference in new issue
Block a user