feat(security): lock biometric settings behind authentication and restrict access to parental panel
This commit is contained in:
+2
-6
@@ -2191,10 +2191,6 @@
|
|||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 7h.01"/><path d="M17 7h.01"/><path d="M7 17h.01"/><path d="M17 17h.01"/></svg>
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 7h.01"/><path d="M17 7h.01"/><path d="M7 17h.01"/><path d="M17 17h.01"/></svg>
|
||||||
<span id="qrBtnText">Mi QR</span>
|
<span id="qrBtnText">Mi QR</span>
|
||||||
</button>
|
</button>
|
||||||
<button id="btnQrSecurityLock" class="qr-toggle-btn" style="background: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.3); padding: 7px 9px;" onclick="openQrSecuritySettings()" title="Seguridad y bloqueo biométrico de mi carné QR">
|
|
||||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
|
|
||||||
<span id="lblQrSecurityBadge" style="font-size: 0.68rem; font-weight: 800;">Seguridad</span>
|
|
||||||
</button>
|
|
||||||
<button id="btnCardTransfer" class="qr-toggle-btn" style="background: rgba(16, 185, 129, 0.25); border-color: rgba(52, 211, 153, 0.4);" onclick="openTransferModal()">
|
<button id="btnCardTransfer" class="qr-toggle-btn" style="background: rgba(16, 185, 129, 0.25); border-color: rgba(52, 211, 153, 0.4);" onclick="openTransferModal()">
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>
|
||||||
<span id="transferBtnText">Transferir</span>
|
<span id="transferBtnText">Transferir</span>
|
||||||
@@ -2379,8 +2375,8 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3 style="font-size: 1.15rem; font-weight: 900; color: var(--text-main, #0f172a); margin: 0 0 6px 0;">Carné QR Protegido</h3>
|
<h3 id="lblQrPinPromptTitle" style="font-size: 1.15rem; font-weight: 900; color: var(--text-main, #0f172a); margin: 0 0 6px 0;">Carné QR Protegido</h3>
|
||||||
<p style="font-size: 0.8rem; color: var(--text-muted, #64748b); margin: 0 0 18px 0; line-height: 1.4;">
|
<p id="lblQrPinPromptDesc" style="font-size: 0.8rem; color: var(--text-muted, #64748b); margin: 0 0 18px 0; line-height: 1.4;">
|
||||||
Verifica tu identidad para mostrar tu código de pago en la soda.
|
Verifica tu identidad para mostrar tu código de pago en la soda.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|||||||
+37
-18
@@ -1682,11 +1682,21 @@ async function verifyPlatformBiometrics(credIdBase64) {
|
|||||||
return Boolean(assertion);
|
return Boolean(assertion);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function triggerQrSecurityUnlock(onSuccess) {
|
async function triggerQrSecurityUnlock(onSuccess, promptTitle, promptDesc) {
|
||||||
pendingQrUnlockSuccessCallback = onSuccess;
|
pendingQrUnlockSuccessCallback = onSuccess;
|
||||||
const estId = currentStudent ? (currentStudent.id || currentStudent.codigo_estudiante || 'default') : 'default';
|
const estId = currentStudent ? (currentStudent.id || currentStudent.codigo_estudiante || 'default') : 'default';
|
||||||
const credId = localStorage.getItem('sibopay_bio_cred_' + estId);
|
const credId = localStorage.getItem('sibopay_bio_cred_' + estId);
|
||||||
|
|
||||||
|
// Textos dinámicos en el modal de verificación
|
||||||
|
const titleEl = document.getElementById('lblQrPinPromptTitle');
|
||||||
|
const descEl = document.getElementById('lblQrPinPromptDesc');
|
||||||
|
if (titleEl) {
|
||||||
|
titleEl.textContent = promptTitle || 'Carné QR Protegido';
|
||||||
|
}
|
||||||
|
if (descEl) {
|
||||||
|
descEl.textContent = promptDesc || 'Verifica tu identidad para mostrar tu código de pago en la soda.';
|
||||||
|
}
|
||||||
|
|
||||||
const bioAvailable = await checkDeviceBiometricsSupport();
|
const bioAvailable = await checkDeviceBiometricsSupport();
|
||||||
const retryContainer = document.getElementById('qrBioRetryContainer');
|
const retryContainer = document.getElementById('qrBioRetryContainer');
|
||||||
if (retryContainer) {
|
if (retryContainer) {
|
||||||
@@ -1794,6 +1804,18 @@ async function retryQrBiometrics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function openQrSecuritySettings() {
|
async function openQrSecuritySettings() {
|
||||||
|
// Si la seguridad YA está activa, exigir autenticación con Face ID o PIN para entrar
|
||||||
|
if (isQrSecurityActiveForCurrentStudent()) {
|
||||||
|
triggerQrSecurityUnlock(() => {
|
||||||
|
showQrSecuritySettingsModalActual();
|
||||||
|
}, 'Administración de Seguridad', 'Verifica tu identidad con Face ID, Huella o PIN para acceder a los ajustes de seguridad.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
showQrSecuritySettingsModalActual();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function showQrSecuritySettingsModalActual() {
|
||||||
const modal = document.getElementById('modalQrSecuritySettings');
|
const modal = document.getElementById('modalQrSecuritySettings');
|
||||||
if (!modal) return;
|
if (!modal) return;
|
||||||
const isEnabled = isQrSecurityActiveForCurrentStudent();
|
const isEnabled = isQrSecurityActiveForCurrentStudent();
|
||||||
@@ -1832,6 +1854,7 @@ function closeQrSecuritySettings(e) {
|
|||||||
async function toggleQrBiometricSetting(enabled) {
|
async function toggleQrBiometricSetting(enabled) {
|
||||||
const estId = currentStudent ? (currentStudent.id || currentStudent.codigo_estudiante || 'default') : 'default';
|
const estId = currentStudent ? (currentStudent.id || currentStudent.codigo_estudiante || 'default') : 'default';
|
||||||
const key = getQrSecurityKey();
|
const key = getQrSecurityKey();
|
||||||
|
const chk = document.getElementById('chkQrBiometricsEnabled');
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
const bioAvailable = await checkDeviceBiometricsSupport();
|
const bioAvailable = await checkDeviceBiometricsSupport();
|
||||||
@@ -1845,10 +1868,20 @@ async function toggleQrBiometricSetting(enabled) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
localStorage.setItem(key, 'true');
|
localStorage.setItem(key, 'true');
|
||||||
} else {
|
|
||||||
localStorage.setItem(key, 'false');
|
|
||||||
}
|
|
||||||
updateQrSecurityBadgeUI();
|
updateQrSecurityBadgeUI();
|
||||||
|
} else {
|
||||||
|
// Si intenta desactivar, exigir autenticación obligatoria
|
||||||
|
triggerQrSecurityUnlock(() => {
|
||||||
|
localStorage.setItem(key, 'false');
|
||||||
|
if (chk) chk.checked = false;
|
||||||
|
updateQrSecurityBadgeUI();
|
||||||
|
if (window.sounds) window.sounds.playSuccess();
|
||||||
|
alert('La protección biométrica ha sido desactivada.');
|
||||||
|
}, 'Desactivar Seguridad', 'Verifica tu identidad para confirmar la desactivación de la seguridad.');
|
||||||
|
|
||||||
|
// Mantener el switch en ON mientras se confirma
|
||||||
|
if (chk) chk.checked = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveSettingsPinBackup() {
|
function saveSettingsPinBackup() {
|
||||||
@@ -1870,22 +1903,8 @@ function saveSettingsPinBackup() {
|
|||||||
|
|
||||||
function updateQrSecurityBadgeUI() {
|
function updateQrSecurityBadgeUI() {
|
||||||
const isEnabled = isQrSecurityActiveForCurrentStudent();
|
const isEnabled = isQrSecurityActiveForCurrentStudent();
|
||||||
const btn = document.getElementById('btnQrSecurityLock');
|
|
||||||
const badge = document.getElementById('lblQrSecurityBadge');
|
|
||||||
const qrBtnText = document.getElementById('qrBtnText');
|
const qrBtnText = document.getElementById('qrBtnText');
|
||||||
|
|
||||||
if (badge) {
|
|
||||||
badge.textContent = isEnabled ? 'Protegido' : 'Seguridad';
|
|
||||||
}
|
|
||||||
if (btn) {
|
|
||||||
if (isEnabled) {
|
|
||||||
btn.style.background = 'rgba(16, 185, 129, 0.3)';
|
|
||||||
btn.style.borderColor = 'rgba(52, 211, 153, 0.6)';
|
|
||||||
} else {
|
|
||||||
btn.style.background = 'rgba(255, 255, 255, 0.15)';
|
|
||||||
btn.style.borderColor = 'rgba(255, 255, 255, 0.3)';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (qrBtnText) {
|
if (qrBtnText) {
|
||||||
qrBtnText.textContent = isEnabled ? '🔒 Mi QR' : 'Mi QR';
|
qrBtnText.textContent = isEnabled ? '🔒 Mi QR' : 'Mi QR';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user