feat(qr): add dynamic QR credential to user profile and global access icon next to theme button (v3.8.45)

This commit is contained in:
2026-10-28 07:34:46 -03:00
parent aaf8281e86
commit 54c221e20e
11 changed files with 481 additions and 24 deletions
+193
View File
@@ -0,0 +1,193 @@
<!-- Modal Global de Credencial Digital QR del Usuario (UniCABA) -->
<div class="modal fade" id="userQrCredentialModal" tabindex="-1" aria-labelledby="userQrCredentialModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" style="max-width: 440px;">
<div class="modal-content border-0 shadow-lg overflow-hidden" style="border-radius: 18px;">
<!-- Encabezado con estética de Carnet Universitario -->
<div class="p-4 text-white position-relative" style="background: linear-gradient(135deg, #1E1B4B 0%, #4338CA 50%, #B43E8E 100%);">
<button type="button" class="btn-close btn-close-white position-absolute top-0 end-0 m-3" data-bs-dismiss="modal" aria-label="Cerrar"></button>
<div class="d-flex align-items-center gap-2 mb-2">
<img src="/img/logo_unicaba_mini.png" alt="UniCABA" height="26" class="bg-white rounded-circle p-1 shadow-sm">
<span class="fw-bold tracking-wider fs-6 text-uppercase">UniCABA · Identidad Digital</span>
</div>
<div class="d-flex align-items-center justify-content-between mt-2">
<div>
<h5 class="modal-title fw-bold text-white mb-0" id="userQrCredentialModalLabel">
Credencial Universitaria
</h5>
<p class="text-white-50 small mb-0 mt-1">Acceso a sedes y convenios de beneficios</p>
</div>
<span class="badge bg-success-subtle text-success border border-success-subtle rounded-pill px-2 py-1 small fw-bold">
● ACTIVO
</span>
</div>
</div>
<!-- Cuerpo del Modal -->
<div class="modal-body p-4 text-center">
<!-- Datos del Usuario -->
<div class="mb-3">
<h5 class="fw-bold mb-1 text-body" id="modalQrUserName">
{{ auth_user.name if (auth_user and auth_user.name) else (user.name if user else 'Usuario') }}
</h5>
<div class="d-flex align-items-center justify-content-center gap-2 flex-wrap mb-2">
<span class="badge bg-primary-subtle text-primary border border-primary-subtle font-monospace text-uppercase" style="font-size: 0.74rem;">
{{ auth_user.role_badge_display.label if (auth_user and auth_user.role_badge_display) else (auth_user.role|upper if auth_user else 'ALUMNO') }}
</span>
{% if auth_user and auth_user.document_number %}
<span class="badge bg-body-tertiary text-body-secondary border font-monospace" style="font-size: 0.74rem;">
DNI: {{ auth_user.document_number }}
</span>
{% endif %}
</div>
<div class="text-muted small font-monospace" style="font-size: 0.78rem;">
{{ auth_user.email if auth_user else '' }}
</div>
</div>
<!-- Contenedor del Código QR Dinámico -->
<div class="p-3 bg-body-tertiary border rounded-4 d-inline-block shadow-sm my-2 position-relative" style="background-color: var(--bs-body-bg) !important;">
<div id="globalQrModalContainer" class="d-flex align-items-center justify-content-center" style="min-width: 190px; min-height: 190px;">
<div class="spinner-border text-primary" role="status" id="globalQrSpinner">
<span class="visually-hidden">Generando credencial QR...</span>
</div>
</div>
</div>
<!-- Información de Validez y Seguridad -->
<div class="mt-2 mb-3">
<div class="d-inline-flex align-items-center gap-1 text-success small fw-semibold">
<i class="bi bi-shield-check"></i>
<span>Firma Criptográfica Verificada</span>
</div>
<div class="text-muted small mt-1" style="font-size: 0.73rem;" id="modalQrValidityText">
<i class="bi bi-clock-history me-1"></i>QR Dinámico renovable cada 72hs
</div>
</div>
<!-- Botones de Acción -->
<div class="d-grid gap-2">
<div class="btn-group">
<button type="button" class="btn btn-outline-secondary btn-sm py-2" onclick="refreshGlobalQrModal()" id="btnRefreshGlobalQr">
<i class="bi bi-arrow-clockwise me-1" id="globalRefreshQrIcon"></i>Actualizar Código QR
</button>
<a href="/credential/my-card" class="btn btn-primary btn-sm py-2">
<i class="bi bi-person-badge me-1"></i>Ver Carnet Completo
</a>
</div>
</div>
</div>
<!-- Footer Informativo -->
<div class="modal-footer bg-body-tertiary py-2 px-3 border-top d-flex justify-content-between align-items-center">
<small class="text-muted" style="font-size: 0.72rem;">
<i class="bi bi-info-circle me-1"></i>Escanea en recepción para ingresar
</small>
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">
Cerrar
</button>
</div>
</div>
</div>
</div>
<script>
(function() {
let qrModalInstance = null;
let cachedQrToken = null;
function ensureQrLibrary(callback) {
if (typeof QRCode !== 'undefined') {
callback();
return;
}
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js';
script.onload = callback;
script.onerror = function() {
var container = document.getElementById('globalQrModalContainer');
if (container) {
container.innerHTML = '<div class="alert alert-warning p-2 small">Error al cargar librería QR</div>';
}
};
document.head.appendChild(script);
}
function renderModalQR(token) {
var container = document.getElementById('globalQrModalContainer');
if (!container) return;
container.innerHTML = '';
try {
qrModalInstance = new QRCode(container, {
text: token,
width: 180,
height: 180,
colorDark: "#0F172A",
colorLight: "#FFFFFF",
correctLevel: QRCode.CorrectLevel.M
});
} catch (err) {
console.error('Error generando QR en modal:', err);
container.innerHTML = '<div class="alert alert-danger p-2 small">Error generando código QR</div>';
}
}
function loadAndRenderQR(forceRefresh) {
var spinner = document.getElementById('globalQrSpinner');
var container = document.getElementById('globalQrModalContainer');
if (!forceRefresh && cachedQrToken) {
renderModalQR(cachedQrToken);
return;
}
if (container && (!qrModalInstance || forceRefresh)) {
container.innerHTML = '<div class="spinner-border text-primary spinner-border-sm" role="status"></div>';
}
fetch('/credential/token')
.then(function(res) { return res.json(); })
.then(function(data) {
if (data && data.qr_token) {
cachedQrToken = data.qr_token;
ensureQrLibrary(function() {
renderModalQR(data.qr_token);
});
if (data.expires_in_hours) {
var valText = document.getElementById('modalQrValidityText');
if (valText) {
valText.innerHTML = '<i class="bi bi-clock-history me-1"></i>QR Dinámico renovable cada ' + data.expires_in_hours + 'hs';
}
}
} else {
throw new Error('Token no disponible');
}
})
.catch(function(err) {
console.warn('Fallback a token local para QR modal:', err);
var fallback = "UNICABA:USR:{{ auth_user.id if auth_user else 0 }}:DNI:{{ auth_user.document_number if auth_user else 'N/A' }}";
ensureQrLibrary(function() {
renderModalQR(fallback);
});
});
}
window.refreshGlobalQrModal = function() {
var icon = document.getElementById('globalRefreshQrIcon');
if (icon) icon.classList.add('spin-animation');
loadAndRenderQR(true);
setTimeout(function() {
if (icon) icon.classList.remove('spin-animation');
}, 800);
};
document.addEventListener('DOMContentLoaded', function() {
var modalEl = document.getElementById('userQrCredentialModal');
if (modalEl) {
modalEl.addEventListener('show.bs.modal', function() {
loadAndRenderQR(false);
});
}
});
})();
</script>