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
+140
View File
@@ -49,6 +49,78 @@
</div>
{% endif %}
<!-- Credencial Digital Universitaria y QR Dinámico -->
<div class="card border-0 shadow-sm mb-4 overflow-hidden" style="border-radius: 14px;">
<div class="p-3 px-4 d-flex align-items-center justify-content-between text-white"
style="background: linear-gradient(135deg, #1E1B4B 0%, #4338CA 50%, #B43E8E 100%);">
<div class="d-flex align-items-center gap-2">
<img src="/img/logo_unicaba_mini.png" alt="UniCABA" height="24" class="bg-white rounded-circle p-1 shadow-xs">
<h5 class="card-title mb-0 h6 fw-bold text-white text-uppercase tracking-wider">
Credencial Universitaria · Acceso QR Dinámico
</h5>
</div>
<span class="badge bg-success-subtle text-success border border-success-subtle rounded-pill px-2 py-1 small fw-semibold">
● ACTIVO
</span>
</div>
<div class="card-body p-4">
<div class="row align-items-center g-4">
<div class="col-md-5 col-lg-4 text-center">
<div class="p-3 bg-body-tertiary border rounded-4 d-inline-block shadow-xs position-relative" style="background-color: var(--bs-body-bg) !important;">
<div id="profileQrCodeDisplay" class="d-flex align-items-center justify-content-center" style="min-width: 180px; min-height: 180px;">
<div class="spinner-border text-primary spinner-border-sm" role="status">
<span class="visually-hidden">Generando QR...</span>
</div>
</div>
</div>
<div class="mt-2 text-muted small" style="font-size: 0.72rem;" id="profileQrValidity">
<i class="bi bi-clock-history me-1"></i>QR Dinámico renovable ({{ expiresInHours or 72 }}hs)
</div>
</div>
<div class="col-md-7 col-lg-8">
<div class="d-flex align-items-center gap-2 flex-wrap mb-2">
<h5 class="fw-bold mb-0 text-body">{{ user.name or (user.first_name ~ ' ' ~ user.last_name) }}</h5>
<span class="badge bg-primary-subtle text-primary border border-primary-subtle font-monospace text-uppercase" style="font-size: 0.72rem;">
{{ user.role }}
</span>
</div>
<div class="text-muted small mb-3">
<i class="bi bi-envelope me-1"></i>{{ user.email }}
</div>
<div class="p-3 bg-body-tertiary rounded-3 mb-3 small">
<div class="row g-2">
<div class="col-sm-6">
<span class="text-muted d-block" style="font-size: 0.7rem;">Documento Nacional / DNI</span>
<span class="fw-bold font-monospace">{{ user.document_number or 'Sin registrar' }}</span>
</div>
<div class="col-sm-6">
<span class="text-muted d-block" style="font-size: 0.7rem;">ID de Matrícula Institucional</span>
<span class="fw-bold font-monospace">#{{ user.id }}</span>
</div>
</div>
</div>
<p class="text-muted small mb-3">
Este código QR posee firma criptográfica HMAC y se actualiza periódicamente para garantizar la autenticidad e intransferibilidad de tu acceso a sedes y descuentos comerciales.
</p>
<div class="d-flex gap-2 flex-wrap">
<a href="/credential/my-card" class="btn btn-primary btn-sm px-3 shadow-xs">
<i class="bi bi-person-badge me-1"></i>Ver Carnet Completo
</a>
<button type="button" class="btn btn-outline-secondary btn-sm px-3 shadow-xs" onclick="refreshProfileQrCode()">
<i class="bi bi-arrow-clockwise me-1" id="profileRefreshQrIcon"></i>Actualizar Código QR
</button>
<a href="/benefits" class="btn btn-outline-primary btn-sm px-3 shadow-xs">
<i class="bi bi-tags me-1"></i>Ver Beneficios Activos
</a>
</div>
</div>
</div>
</div>
</div>
<!-- Profile Card -->
<div class="card border-0 shadow-sm mb-4" style="border-radius: 12px;">
<div class="card-body p-4">
@@ -229,4 +301,72 @@
</div>
</div>
</div>
<!-- Librería QRCode.js via CDN y Lógica de Renderizado Dinámico -->
<script src="https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js"></script>
<script>
(function() {
var profileQrInstance = null;
var initialToken = "{{ qrToken }}";
var fallbackToken = "UNICABA:USR:{{ user.id }}:DNI:{{ user.document_number or user.email }}";
function drawQR(text) {
var container = document.getElementById('profileQrCodeDisplay');
if (!container) return;
container.innerHTML = '';
try {
profileQrInstance = new QRCode(container, {
text: text,
width: 180,
height: 180,
colorDark: "#0F172A",
colorLight: "#FFFFFF",
correctLevel: QRCode.CorrectLevel.M
});
} catch(e) {
console.error('Error dibujando QR en perfil:', e);
container.innerHTML = '<div class="alert alert-warning p-2 small">Error generando código QR</div>';
}
}
window.refreshProfileQrCode = function() {
var icon = document.getElementById('profileRefreshQrIcon');
var container = document.getElementById('profileQrCodeDisplay');
if (icon) icon.classList.add('spin-animation');
if (container) {
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) {
drawQR(data.qr_token);
if (data.expires_in_hours) {
var valEl = document.getElementById('profileQrValidity');
if (valEl) {
valEl.innerHTML = '<i class="bi bi-clock-history me-1"></i>QR Dinámico renovable (' + data.expires_in_hours + 'hs)';
}
}
} else {
drawQR(fallbackToken);
}
})
.catch(function(err) {
console.warn('Error refrescando token:', err);
drawQR(fallbackToken);
})
.finally(function() {
if (icon) {
setTimeout(function() { icon.classList.remove('spin-animation'); }, 700);
}
});
};
document.addEventListener('DOMContentLoaded', function() {
var tokenToUse = (initialToken && initialToken.length > 10) ? initialToken : fallbackToken;
drawQR(tokenToUse);
});
})();
</script>
{% endblock %}