fix: start payment internet window on demand and verify connectivity from guest browser
build-image / build-push (push) Successful in 2m41s
build-image / build-push (push) Successful in 2m41s
This commit is contained in:
1 parent
0c01e5d88b
commit
783e241e42
7 files changed
+187
-8
No files matched your search
@@ -479,6 +479,7 @@
|
||||
<!-- ===== PLANOS ===== -->
|
||||
<div class="card" style="margin-bottom:14px" role="status" aria-live="polite">
|
||||
<p id="freeAccessMessage">Verificando acesso temporário para pagamento…</p>
|
||||
<p id="freeAccessProbe" hidden></p>
|
||||
<button class="btn btn-ghost" id="retryFreeAccess" type="button" hidden>Tentar liberar acesso</button>
|
||||
</div>
|
||||
<main id="view-plans">
|
||||
@@ -714,6 +715,7 @@
|
||||
|
||||
currentPaymentId = data.paymentId;
|
||||
sessionStorage.setItem('paymentId', currentPaymentId);
|
||||
sessionStorage.setItem('pendingPix', JSON.stringify(data));
|
||||
$('payTitle').textContent = data.planName + ' · ' + money(data.price);
|
||||
$('qrImg').src = data.qrCodeBase64 ? 'data:image/png;base64,' + data.qrCodeBase64 : '';
|
||||
$('copiaCola').textContent = data.copiaCola || '';
|
||||
@@ -722,6 +724,7 @@
|
||||
|
||||
clearInterval(pollTimer);
|
||||
pollTimer = setInterval(verify, 6000);
|
||||
startFreeAccess();
|
||||
} catch (e) {
|
||||
toast('Erro: ' + e.message);
|
||||
} finally {
|
||||
@@ -745,6 +748,10 @@
|
||||
if (!res.ok) throw new Error('Falha na consulta');
|
||||
const data = await res.json();
|
||||
if (data.status === 'paid' && data.voucher) {
|
||||
sessionStorage.removeItem('pendingPix');
|
||||
clearInterval(window.freeAccessTimer);
|
||||
$('freeAccessMessage').textContent = 'Pagamento confirmado. Use seu voucher para conectar ao Wi-Fi.';
|
||||
$('retryFreeAccess').hidden = true;
|
||||
clearInterval(pollTimer); pollTimer = null;
|
||||
$('vUser').textContent = data.voucher.user;
|
||||
$('vPass').textContent = data.voucher.pass;
|
||||
@@ -812,6 +819,8 @@
|
||||
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.';
|
||||
retry.textContent = 'Abrir entrada do Wi-Fi';
|
||||
retry.hidden = false;
|
||||
return;
|
||||
}
|
||||
retry.hidden = true;
|
||||
@@ -829,6 +838,7 @@
|
||||
return;
|
||||
}
|
||||
if (d.authenticated) {
|
||||
if (d.probeToken) verifyClientInternet(d.probeToken);
|
||||
sessionStorage.removeItem('freeLoginAttemptUntil');
|
||||
clearInterval(window.freeAccessTimer);
|
||||
const deadline = Date.now() + d.seconds * 1000;
|
||||
@@ -853,7 +863,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyClientInternet(token) {
|
||||
const label = $('freeAccessProbe');
|
||||
label.hidden = false;
|
||||
label.textContent = 'Verificando o acesso a serviços externos neste aparelho…';
|
||||
const results = await Promise.all([
|
||||
['google', 'https://www.gstatic.com/generate_204'],
|
||||
['apple', 'https://www.apple.com/library/test/success.html'],
|
||||
].map(async ([provider, url]) => {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), 6000);
|
||||
try {
|
||||
const response = await fetch(url + '?_=' + Date.now(), { mode: 'no-cors', cache: 'no-store', redirect: 'error', signal: controller.signal });
|
||||
return { provider, ok: response.type === 'opaque' || response.ok };
|
||||
} catch { return { provider, ok: false }; }
|
||||
finally { clearTimeout(timer); }
|
||||
}));
|
||||
label.textContent = results.some(r => r.ok) ? 'Este aparelho alcançou um serviço externo. Você pode abrir o aplicativo do banco.' : 'A sessão está ativa, mas não foi possível confirmar o acesso externo. Verifique se o aplicativo do banco abre.';
|
||||
try { await fetch('/api/access/report', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ mac, token, results }) }); } catch { /* report is optional */ }
|
||||
}
|
||||
|
||||
$('retryFreeAccess').addEventListener('click', () => {
|
||||
if (!/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i.test(mac)) {
|
||||
window.location.href = HS_LOGIN;
|
||||
return;
|
||||
}
|
||||
sessionStorage.removeItem('freeLoginAttemptUntil');
|
||||
startFreeAccess();
|
||||
});
|
||||
@@ -867,10 +901,27 @@
|
||||
} catch { /* usa padrao */ }
|
||||
}
|
||||
|
||||
loadSiteConfig().then(startFreeAccess);
|
||||
loadSiteConfig().then(() => {
|
||||
if (!/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i.test(mac) || new URLSearchParams(location.search).get('free') === '1' || sessionStorage.getItem('pendingPix')) startFreeAccess();
|
||||
else {
|
||||
$('freeAccessMessage').textContent = 'O acesso temporário para abrir o aplicativo do banco começa após gerar o PIX. Se precisar antes, toque em liberar acesso.';
|
||||
$('retryFreeAccess').textContent = 'Liberar acesso para pagamento';
|
||||
$('retryFreeAccess').hidden = false;
|
||||
}
|
||||
});
|
||||
loadPlans();
|
||||
if (sessionStorage.getItem('paymentId')) {
|
||||
currentPaymentId = sessionStorage.getItem('paymentId');
|
||||
try {
|
||||
const pending = JSON.parse(sessionStorage.getItem('pendingPix') || 'null');
|
||||
if (pending?.paymentId === currentPaymentId) {
|
||||
$('payTitle').textContent = pending.planName + ' · ' + money(pending.price);
|
||||
$('qrImg').src = pending.qrCodeBase64 ? 'data:image/png;base64,' + pending.qrCodeBase64 : '';
|
||||
$('copiaCola').textContent = pending.copiaCola || '';
|
||||
show('pay');
|
||||
pollTimer = setInterval(verify, 6000);
|
||||
}
|
||||
} catch { sessionStorage.removeItem('pendingPix'); }
|
||||
verify();
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user