mirror of
git://f0xx.org/ac/ac-be-auth
synced 2026-07-29 04:19:06 +03:00
fix(2fa): avoid double QR mint, i18n poll status, send credentials
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -72,13 +72,28 @@
|
|||||||
var pollActive = true;
|
var pollActive = true;
|
||||||
var INTERVAL = 2500; // ms
|
var INTERVAL = 2500; // ms
|
||||||
|
|
||||||
function showStatus(msg) {
|
function showStatus(text) {
|
||||||
if (statusEl) {
|
if (statusEl) {
|
||||||
statusEl.style.display = '';
|
statusEl.style.display = '';
|
||||||
statusEl.textContent = msg;
|
statusEl.textContent = text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function msg(key, fallback) {
|
||||||
|
var i18n = typeof window !== 'undefined' ? window.CrashI18n : null;
|
||||||
|
if (i18n && typeof i18n.t === 'function') {
|
||||||
|
var s = i18n.t(key);
|
||||||
|
if (s && s !== key) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showStatusMsg(key, fallback) {
|
||||||
|
showStatus(msg(key, fallback));
|
||||||
|
}
|
||||||
|
|
||||||
function stopPolling() {
|
function stopPolling() {
|
||||||
pollActive = false;
|
pollActive = false;
|
||||||
if (pollTimer) {
|
if (pollTimer) {
|
||||||
@@ -94,6 +109,7 @@
|
|||||||
var url = pollUrl + '?token=' + encodeURIComponent(pollToken);
|
var url = pollUrl + '?token=' + encodeURIComponent(pollToken);
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', url, true);
|
xhr.open('GET', url, true);
|
||||||
|
xhr.withCredentials = true;
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
if (!pollActive) {
|
if (!pollActive) {
|
||||||
return;
|
return;
|
||||||
@@ -106,7 +122,7 @@
|
|||||||
}
|
}
|
||||||
if (data.status === 'approved' && data.redirect) {
|
if (data.status === 'approved' && data.redirect) {
|
||||||
stopPolling();
|
stopPolling();
|
||||||
showStatus('✅ Approved — signing you in…');
|
showStatusMsg('twofa.approved', '✅ Approved — signing you in…');
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
window.location.href = data.redirect;
|
window.location.href = data.redirect;
|
||||||
}, 400);
|
}, 400);
|
||||||
@@ -114,14 +130,14 @@
|
|||||||
}
|
}
|
||||||
if (data.status === 'expired' || data.status === 'used' || data.status === 'not_found') {
|
if (data.status === 'expired' || data.status === 'used' || data.status === 'not_found') {
|
||||||
stopPolling();
|
stopPolling();
|
||||||
showStatus('⚠️ QR code expired. Reload to get a new one.');
|
showStatusMsg('twofa.qr_expired', '⚠️ QR code expired. Reload to get a new one.');
|
||||||
if (qrWrap) {
|
if (qrWrap) {
|
||||||
qrWrap.style.opacity = '0.35';
|
qrWrap.style.opacity = '0.35';
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// status === 'pending' — keep polling
|
// status === 'pending' — keep polling
|
||||||
showStatus('⏳ Waiting for mobile approval…');
|
showStatusMsg('twofa.waiting_approval', '⏳ Waiting for mobile approval…');
|
||||||
scheduleNext();
|
scheduleNext();
|
||||||
};
|
};
|
||||||
xhr.onerror = function () {
|
xhr.onerror = function () {
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
$bp = Auth::basePath();
|
$bp = Auth::basePath();
|
||||||
$auth = Auth::authUrl();
|
$auth = Auth::authUrl();
|
||||||
$twofaQr = AuthTwoFactorPage::qrPayload();
|
if (!isset($twofaQr)) {
|
||||||
|
$twofaQr = AuthTwoFactorPage::qrPayload();
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" data-theme="dark">
|
<html lang="en" data-theme="dark">
|
||||||
|
|||||||
Reference in New Issue
Block a user