fix(credential): desacople modal qr vs carnet completo, dni y usuario en perfil, y resolucion robusta en dni parser v3.8.54
This commit is contained in:
@@ -171,6 +171,20 @@
|
||||
|
||||
<!-- User Details Grid -->
|
||||
<div class="row g-3">
|
||||
<div class="col-sm-6">
|
||||
<label class="form-label text-muted small mb-1 fw-semibold">Número de Documento (DNI)</label>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="badge bg-secondary-subtle text-secondary-emphasis font-monospace">{{ user.document_type or 'DNI' }}</span>
|
||||
<span class="fw-bold font-monospace fs-6 text-body">{{ user.document_number or user.dni or 'Sin registrar' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<label class="form-label text-muted small mb-1 fw-semibold">Nombre de Usuario / Login</label>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="badge bg-primary-subtle text-primary font-monospace"><i class="bi bi-person-fill me-1"></i>Usuario</span>
|
||||
<span class="fw-bold font-monospace fs-6 text-body">{{ user.username or user.document_number or user.dni or (user.email.split('@')[0] if user.email else '') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<label class="form-label text-muted small mb-1 fw-semibold">Correo Electrónico Institucional</label>
|
||||
<div class="fw-bold font-monospace text-body">{{ user.email }}</div>
|
||||
@@ -179,6 +193,14 @@
|
||||
<label class="form-label text-muted small mb-1 fw-semibold">Nombre Completo</label>
|
||||
<div class="fw-semibold text-body">{{ user.name or user.first_name ~ ' ' ~ user.last_name }}</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<label class="form-label text-muted small mb-1 fw-semibold">Origen de Cuenta / Acceso</label>
|
||||
<div class="fw-semibold text-body">
|
||||
<span class="badge bg-info-subtle text-info border border-info-subtle">
|
||||
<i class="bi bi-shield-lock me-1"></i>{{ user.auth_provider_label or 'Institucional' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<label class="form-label text-muted small mb-1 fw-semibold">Rol de Acceso Asignado</label>
|
||||
<div class="fw-semibold text-body">{{ user.role }}</div>
|
||||
@@ -205,6 +227,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-light border rounded-3 p-3 mt-3 mb-0 small text-muted">
|
||||
<i class="bi bi-info-circle-fill text-primary me-2"></i>
|
||||
<strong>Identificación de inicio de sesión:</strong> Puedes ingresar al sistema utilizando tanto tu
|
||||
<strong class="text-body">correo electrónico</strong> como tu <strong class="text-body">número de DNI</strong> o mediante autenticación institucional de Google Workspace y Moodle.
|
||||
</div>
|
||||
|
||||
<hr class="my-4 opacity-25">
|
||||
|
||||
<!-- Preferences Section -->
|
||||
@@ -317,8 +345,8 @@
|
||||
</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>
|
||||
<!-- Librería QRCode.js local y Lógica de Renderizado Dinámico -->
|
||||
<script src="/js/qrcode.min.js"></script>
|
||||
<script>
|
||||
(function() {
|
||||
var profileQrInstance = null;
|
||||
@@ -328,24 +356,28 @@
|
||||
var tickIntervalMs = 100;
|
||||
var isFetching = false;
|
||||
var initialToken = "{{ qrToken }}";
|
||||
var fallbackToken = "UNICABA:USR:{{ user.id }}:DNI:{{ user.document_number or user.email }}";
|
||||
var fallbackToken = "UNICABA:USR:{{ user.id }}:DNI:{{ user.document_number or user.dni or user.id }}";
|
||||
|
||||
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
|
||||
});
|
||||
if (profileQrInstance && typeof profileQrInstance.makeCode === 'function') {
|
||||
profileQrInstance.makeCode(text);
|
||||
} else {
|
||||
container.innerHTML = '';
|
||||
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>';
|
||||
container.innerHTML = '<div class="alert alert-secondary p-2 small font-monospace">Credencial activa</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2285,6 +2285,7 @@
|
||||
</script>
|
||||
|
||||
<script src="/js/walkthrough-engine.js"></script>
|
||||
<script src="/js/qrcode.min.js"></script>
|
||||
{% if auth_user and auth_user.is_authenticated %}
|
||||
{% include "partials/ai_chat_widget.html" %}
|
||||
{% include "partials/user_qr_modal.html" %}
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
<div class="d-flex justify-content-center align-items-center gap-3 text-start small opacity-90 mb-2">
|
||||
<div>
|
||||
<span class="d-block text-uppercase" style="font-size: 0.65rem;">Documento</span>
|
||||
<span class="fw-bold fs-6">{{ user.document_number or user.email }}</span>
|
||||
<span class="fw-bold fs-6">{{ user.document_number or user.dni or 'Sin DNI Registrado' }}</span>
|
||||
</div>
|
||||
<div class="vr bg-white opacity-25"></div>
|
||||
<div>
|
||||
@@ -115,8 +115,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Librería QRCode.js via CDN -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js"></script>
|
||||
<!-- Librería QRCode.js local -->
|
||||
<script src="/js/qrcode.min.js"></script>
|
||||
<script>
|
||||
(function() {
|
||||
var qrInstance = null;
|
||||
@@ -126,21 +126,25 @@
|
||||
var tickIntervalMs = 100;
|
||||
var isFetching = false;
|
||||
var initialToken = "{{ qrToken }}";
|
||||
var fallbackText = "UNICABA:USR:{{ user.id }}:DNI:{{ user.document_number or user.email }}";
|
||||
var fallbackText = "UNICABA:USR:{{ user.id }}:DNI:{{ user.document_number or user.dni or user.id }}";
|
||||
|
||||
function drawQR(text) {
|
||||
var qrContainer = document.getElementById('qrcode');
|
||||
if (!qrContainer) return;
|
||||
qrContainer.innerHTML = '';
|
||||
try {
|
||||
qrInstance = new QRCode(qrContainer, {
|
||||
text: text,
|
||||
width: 180,
|
||||
height: 180,
|
||||
colorDark: "#0F172A",
|
||||
colorLight: "#FFFFFF",
|
||||
correctLevel: QRCode.CorrectLevel.M
|
||||
});
|
||||
if (qrInstance && typeof qrInstance.makeCode === 'function') {
|
||||
qrInstance.makeCode(text);
|
||||
} else {
|
||||
qrContainer.innerHTML = '';
|
||||
qrInstance = new QRCode(qrContainer, {
|
||||
text: text,
|
||||
width: 180,
|
||||
height: 180,
|
||||
colorDark: "#0F172A",
|
||||
colorLight: "#FFFFFF",
|
||||
correctLevel: QRCode.CorrectLevel.M
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error generando QR:', e);
|
||||
qrContainer.innerHTML = '<div class="alert alert-warning p-2 small">Código disponible en modo texto</div>';
|
||||
|
||||
@@ -52,9 +52,9 @@
|
||||
<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 %}
|
||||
{% if auth_user and (auth_user.document_number or auth_user.dni) %}
|
||||
<span class="badge bg-body-tertiary text-body-secondary border font-monospace" style="font-size: 0.74rem;">
|
||||
DNI: {{ auth_user.document_number }}
|
||||
DNI: {{ auth_user.document_number or auth_user.dni }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -99,7 +99,7 @@
|
||||
|
||||
<!-- Botón de Acción -->
|
||||
<div class="d-grid">
|
||||
<a href="/credential/my-card" class="btn btn-primary py-2 rounded-3 shadow-xs d-flex align-items-center justify-content-center">
|
||||
<a href="/credential/my-card" id="modalBtnVerCarnet" class="btn btn-primary py-2 rounded-3 shadow-xs d-flex align-items-center justify-content-center">
|
||||
<i class="bi bi-person-badge me-2"></i>Ver Carnet Completo
|
||||
</a>
|
||||
</div>
|
||||
@@ -122,54 +122,50 @@
|
||||
(function() {
|
||||
let qrModalInstance = null;
|
||||
let timerId = null;
|
||||
let renewalInterval = 3; // Segundos (default 3s configurable)
|
||||
let renewalInterval = 3;
|
||||
let elapsedMs = 0;
|
||||
const tickIntervalMs = 100;
|
||||
let isFetching = false;
|
||||
|
||||
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);
|
||||
}
|
||||
// Detectar si la página activa es /credential/my-card
|
||||
const isCarnetPage = window.location.pathname.includes('/credential/my-card') ||
|
||||
window.location.pathname.endsWith('/credential') ||
|
||||
window.location.pathname.includes('/mi-credencial');
|
||||
|
||||
function renderModalQR(token) {
|
||||
var container = document.getElementById('globalQrModalContainer');
|
||||
const 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
|
||||
});
|
||||
if (qrModalInstance && typeof qrModalInstance.makeCode === 'function') {
|
||||
qrModalInstance.makeCode(token);
|
||||
} else {
|
||||
container.innerHTML = '';
|
||||
if (typeof QRCode !== 'undefined') {
|
||||
qrModalInstance = new QRCode(container, {
|
||||
text: token,
|
||||
width: 180,
|
||||
height: 180,
|
||||
colorDark: "#0F172A",
|
||||
colorLight: "#FFFFFF",
|
||||
correctLevel: QRCode.CorrectLevel.M
|
||||
});
|
||||
} else {
|
||||
container.innerHTML = '<div class="alert alert-warning p-2 small">Código disponible: ' + token.substring(0, 16) + '...</div>';
|
||||
}
|
||||
}
|
||||
} 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>';
|
||||
container.innerHTML = '<div class="alert alert-secondary p-2 small font-monospace">Credencial institucional activa</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function updateProgressUi() {
|
||||
var progressBar = document.getElementById('modalQrProgressBar');
|
||||
var countdownEl = document.getElementById('modalQrCountdown');
|
||||
var totalMs = renewalInterval * 1000;
|
||||
var remainingMs = Math.max(0, totalMs - elapsedMs);
|
||||
var pct = Math.max(0, Math.min(100, (remainingMs / totalMs) * 100));
|
||||
const progressBar = document.getElementById('modalQrProgressBar');
|
||||
const countdownEl = document.getElementById('modalQrCountdown');
|
||||
const totalMs = renewalInterval * 1000;
|
||||
const remainingMs = Math.max(0, totalMs - elapsedMs);
|
||||
const pct = Math.max(0, Math.min(100, (remainingMs / totalMs) * 100));
|
||||
|
||||
if (progressBar) {
|
||||
progressBar.style.width = pct + '%';
|
||||
@@ -179,26 +175,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
function fetchAndRenderToken(showSpinner) {
|
||||
function fetchAndRenderToken() {
|
||||
if (isFetching) return;
|
||||
isFetching = true;
|
||||
|
||||
var container = document.getElementById('globalQrModalContainer');
|
||||
if (showSpinner && container && !qrModalInstance) {
|
||||
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(res) {
|
||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||
return res.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
if (data && data.qr_token) {
|
||||
if (data.renewal_interval_seconds && data.renewal_interval_seconds > 0) {
|
||||
renewalInterval = data.renewal_interval_seconds;
|
||||
}
|
||||
ensureQrLibrary(function() {
|
||||
renderModalQR(data.qr_token);
|
||||
});
|
||||
var valText = document.getElementById('modalQrValidityText');
|
||||
renderModalQR(data.qr_token);
|
||||
const valText = document.getElementById('modalQrValidityText');
|
||||
if (valText) {
|
||||
valText.innerHTML = '<i class="bi bi-arrow-repeat me-1"></i>Código dinámico con rotación cada ' + renewalInterval + ' seg';
|
||||
}
|
||||
@@ -208,10 +200,8 @@
|
||||
})
|
||||
.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 or auth_user.dni or auth_user.id or 'N/A' }}";
|
||||
ensureQrLibrary(function() {
|
||||
renderModalQR(fallback);
|
||||
});
|
||||
const fallback = "UNICABA:USR:{{ auth_user.id if auth_user else 0 }}:DNI:{{ auth_user.document_number or auth_user.dni or auth_user.id or 'N/A' }}";
|
||||
renderModalQR(fallback);
|
||||
})
|
||||
.finally(function() {
|
||||
isFetching = false;
|
||||
@@ -224,7 +214,7 @@
|
||||
stopAutoRefreshLoop();
|
||||
elapsedMs = 0;
|
||||
updateProgressUi();
|
||||
fetchAndRenderToken(false);
|
||||
fetchAndRenderToken();
|
||||
|
||||
timerId = setInterval(function() {
|
||||
elapsedMs += tickIntervalMs;
|
||||
@@ -232,7 +222,7 @@
|
||||
|
||||
if (elapsedMs >= renewalInterval * 1000) {
|
||||
elapsedMs = 0;
|
||||
fetchAndRenderToken(false);
|
||||
fetchAndRenderToken();
|
||||
}
|
||||
}, tickIntervalMs);
|
||||
}
|
||||
@@ -242,63 +232,72 @@
|
||||
clearInterval(timerId);
|
||||
timerId = null;
|
||||
}
|
||||
qrModalInstance = null;
|
||||
}
|
||||
|
||||
window.refreshGlobalQrModal = function() {
|
||||
var icon = document.getElementById('globalRefreshQrIcon');
|
||||
if (icon) icon.classList.add('spin-animation');
|
||||
elapsedMs = 0;
|
||||
fetchAndRenderToken(false);
|
||||
setTimeout(function() {
|
||||
if (icon) icon.classList.remove('spin-animation');
|
||||
}, 600);
|
||||
};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var modalEl = document.getElementById('userQrCredentialModal');
|
||||
if (modalEl) {
|
||||
// Impedir que eventos de scroll de rueda o táctiles se propaguen a la página de fondo
|
||||
modalEl.addEventListener('wheel', function(e) {
|
||||
if (e.target === modalEl) {
|
||||
const modalEl = document.getElementById('userQrCredentialModal');
|
||||
if (!modalEl) return;
|
||||
|
||||
// Desacople total si estamos en la vista de carnet completo:
|
||||
if (isCarnetPage) {
|
||||
// El usuario ya está viendo su credencial en pantalla completa:
|
||||
// Interceptamos los botones de barra y menú para evitar solapamientos y bloqueos
|
||||
document.querySelectorAll('[data-bs-target="#userQrCredentialModal"]').forEach(function(btn) {
|
||||
btn.removeAttribute('data-bs-toggle');
|
||||
btn.removeAttribute('data-bs-target');
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}, { passive: false });
|
||||
|
||||
modalEl.addEventListener('touchmove', function(e) {
|
||||
if (e.target === modalEl) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}, { passive: false });
|
||||
|
||||
modalEl.addEventListener('show.bs.modal', function() {
|
||||
// Bloqueo total de scroll en el elemento raíz (html) y cuerpo (body)
|
||||
document.documentElement.classList.add('modal-open');
|
||||
document.body.classList.add('modal-open');
|
||||
document.documentElement.style.overflow = 'hidden';
|
||||
document.body.style.overflow = 'hidden';
|
||||
|
||||
// Si el sidebar móvil estuviera desplegado, cerrarlo para evitar solapamientos
|
||||
if (typeof window.closeMobileSidebar === 'function') {
|
||||
window.closeMobileSidebar();
|
||||
} else {
|
||||
var sb = document.querySelector('.sidebar.mobile-open');
|
||||
if (sb) sb.classList.remove('mobile-open');
|
||||
var bd = document.getElementById('sidebarBackdrop');
|
||||
if (bd) bd.classList.remove('show');
|
||||
}
|
||||
|
||||
startAutoRefreshLoop();
|
||||
// Scroll suave y destello elegante en la credencial ya visible
|
||||
const card = document.querySelector('.card[style*="linear-gradient"]');
|
||||
if (card) {
|
||||
card.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
card.style.transform = 'scale(1.02)';
|
||||
card.style.transition = 'transform 0.25s ease, box-shadow 0.25s ease';
|
||||
card.style.boxShadow = '0 0 25px rgba(180, 62, 142, 0.6)';
|
||||
setTimeout(function() {
|
||||
card.style.transform = '';
|
||||
card.style.boxShadow = '';
|
||||
}, 600);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
modalEl.addEventListener('hidden.bs.modal', function() {
|
||||
// Restaurar scroll de página
|
||||
document.documentElement.classList.remove('modal-open');
|
||||
document.body.classList.remove('modal-open');
|
||||
document.documentElement.style.overflow = '';
|
||||
document.body.style.overflow = '';
|
||||
stopAutoRefreshLoop();
|
||||
// Si por algún enlace previo o history el modal estuviese abierto, cerrarlo inmediatamente
|
||||
const existingModal = bootstrap.Modal.getInstance(modalEl);
|
||||
if (existingModal) {
|
||||
existingModal.hide();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Si estamos en cualquier otra página del sistema:
|
||||
const btnVerCarnet = document.getElementById('modalBtnVerCarnet');
|
||||
if (btnVerCarnet) {
|
||||
btnVerCarnet.addEventListener('click', function() {
|
||||
const inst = bootstrap.Modal.getInstance(modalEl);
|
||||
if (inst) inst.hide();
|
||||
});
|
||||
}
|
||||
|
||||
// Utilizar shown.bs.modal (cuando la animación fade terminó y el modal es 100% visible)
|
||||
modalEl.addEventListener('shown.bs.modal', function() {
|
||||
document.documentElement.classList.add('modal-open');
|
||||
document.body.classList.add('modal-open');
|
||||
startAutoRefreshLoop();
|
||||
});
|
||||
|
||||
// Limpieza innegociable al ocultar el modal:
|
||||
modalEl.addEventListener('hidden.bs.modal', function() {
|
||||
stopAutoRefreshLoop();
|
||||
document.documentElement.classList.remove('modal-open');
|
||||
document.body.classList.remove('modal-open');
|
||||
document.documentElement.style.overflow = '';
|
||||
document.body.style.overflow = '';
|
||||
document.querySelectorAll('.modal-backdrop').forEach(function(b) {
|
||||
b.remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user