573 lines
24 KiB
PHP
573 lines
24 KiB
PHP
<?php
|
|
include __DIR__ . '/../partials/sidebar_configuracion.php';
|
|
|
|
$dos_factores_estado = obtenerEstadoDosFactores();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>👮 Opciones de Seguridad</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
|
|
<style>
|
|
body { font-family: 'Segoe UI', sans-serif; background-color: #f4f6f9; }
|
|
.sidebar { width: 220px; height: 100vh; background-color: #343a40; position: fixed; top: 0; left: 0; padding-top: 56px; z-index: 1040; }
|
|
.sidebar .nav-link { font-weight: bold; color: white; transition: all 0.3s ease; }
|
|
.sidebar .nav-link:hover,
|
|
.sidebar .nav-link.active { background-color: #495057; color: #fff; }
|
|
.content { margin-top: 56px; padding: 40px 20px; position: relative; z-index: 1; background-color: #f4f6f9; transition: margin-left 0.3s ease; }
|
|
.navbar { position: fixed; top: 0; width: 100%; z-index: 1050; }
|
|
/* A partir de dispositivos medianos (>=768px), deja espacio lateral */
|
|
@media (min-width: 768px) { .content { margin-left: 250px; /* Ancho del sidebar */ } }
|
|
/* En móviles, sin margen lateral */
|
|
@media (max-width: 767.98px) {
|
|
.content { margin-left: 0; }
|
|
.sidebar .nav-link { font-weight: normal; color: #343a40; background-color: transparent; }
|
|
.sidebar .nav-link:hover,
|
|
.sidebar .nav-link.active { background-color: #e9ecef; color: #212529; }
|
|
.login-container { width: 95%; padding: 30PX 20px; }
|
|
}
|
|
.card { border-radius: 12px; }
|
|
.btn i { font-family: "Font Awesome 6 Free", sans-serif; margin-right: 0.5rem; }
|
|
.btn { font-family: 'Segoe UI', sans-serif; }
|
|
/* Contenedor de fondo semitransparente para las vistas */
|
|
.overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 9999; }
|
|
.login-container { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 420px; width: 90%;
|
|
background: white; padding: 40px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08); z-index: 10000; margin: 0; }
|
|
.form-control { border-radius: 6px; transition: all 0.3s ease; }
|
|
.form-control.error { border-color: #dc3545; background-color: #fff5f5; animation: shake 0.5s ease-in-out; }
|
|
.form-control.success { border-color: #28a745; background-color: #f8fff9; }
|
|
#mensaje { transition: all 0.3s ease; min-height: 24px; }
|
|
#btnReenviarRespaldo { background: none; border: none; color: <?= $color1 ?>; text-decoration: underline; cursor: pointer; font-size: 14px; padding: 0; transition: color 0.3s ease; }
|
|
#btnReenviarRespaldo:hover { color: <?= $color2 ?>; }
|
|
#btnReenviarRespaldo:disabled { color: #ccc; cursor: not-allowed; text-decoration: none; }
|
|
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
.loading { position: relative; pointer-events: none; }
|
|
.loading::after { content: ''; position: absolute; top: 50%; left: 50%; width: 20px; height: 20px; border: 2px solid transparent; border-top: 2px solid #fff; border-radius: 50%; animation: spin 1s linear infinite; transform: translate(-50%, -50%); }
|
|
@keyframes shake {
|
|
0%, 100% { transform: translateX(0); }
|
|
25% { transform: translateX(-5px); }
|
|
75% { transform: translateX(5px); }
|
|
}
|
|
@keyframes spin {
|
|
0% { transform: translate(-50%, -50%) rotate(0deg); }
|
|
100% { transform: translate(-50%, -50%) rotate(360deg); }
|
|
}
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; transform: translateY(-10px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
.fade-in { animation: fadeIn 0.3s ease-out; }
|
|
@media (max-height: 600px) { footer { position: static !important; } }
|
|
/* Estilos para input de código */
|
|
#codigo { font-size: 18px; letter-spacing: 3px; text-align: center; font-weight: bold; }
|
|
.input-group { position: relative; }
|
|
.clear-input { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: #ccc; cursor: pointer; z-index: 5; display: none; }
|
|
.clear-input:hover { color: #666; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Overlay (fondo semitransparente) que cubre la pantalla -->
|
|
<div class="overlay"></div>
|
|
|
|
<!-- Formulario de validación de código -->
|
|
<div class="login-container">
|
|
<h4 class="mb-4 text-center text-dark">Verifica tu código</h4>
|
|
<p class="text-muted text-center mb-4">
|
|
<i class="fas fa-envelope me-2"></i>
|
|
Hemos enviado un código de 6 dígitos a tu correo electrónico
|
|
</p>
|
|
|
|
<!-- Formulario para verificar el código -->
|
|
<form id="formCodigo" action="/IMPORTADORES/reset/verificarCodigoInterno" method="POST">
|
|
<div class="mb-3">
|
|
<label class="form-label" for="codigo">
|
|
<i class="fas fa-key me-2"></i>Código de verificación
|
|
</label>
|
|
<div class="input-group">
|
|
<input type="text" id="codigo" name="codigo" class="form-control" required pattern="\d{6}" maxlength="6" placeholder="000000" autocomplete="off" inputmode="numeric">
|
|
<button type="button" class="clear-input" id="clearCode" title="Limpiar código">
|
|
<i class="fas fa-times"></i>
|
|
</button>
|
|
</div>
|
|
<div class="form-text">
|
|
<i class="fas fa-info-circle me-1"></i>
|
|
Ingresa el código de 6 dígitos que recibiste por correo
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" id="btnVerificar" class="btn btn-success w-100">
|
|
<i class="fas fa-check me-2"></i>Verificar código
|
|
</button>
|
|
|
|
<!-- Botón para enviar el código al correo de respaldo-->
|
|
<div class="text-center mt-3">
|
|
<button type="button" id="btnReenviarRespaldo" title="Enviar código al correo de respaldo">
|
|
<i class="fas fa-paper-plane me-1"></i>
|
|
¿No tienes acceso al correo? Reenviar al correo de respaldo
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<!-- Mostrar mensajes -->
|
|
<div id="mensaje" class="mt-3 text-center fw-bold">
|
|
<?php if (isset($_SESSION['codigo_error'])): ?>
|
|
<div class="text-danger fade-in">
|
|
<i class="fas fa-exclamation-triangle me-2"></i>
|
|
<?= $_SESSION['codigo_error'] ?>
|
|
</div>
|
|
<?php unset($_SESSION['codigo_error']); ?>
|
|
<?php elseif (isset($_SESSION['codigo_exito'])): ?>
|
|
<div class="text-success fade-in">
|
|
<i class="fas fa-check-circle me-2"></i>
|
|
<?= $_SESSION['codigo_exito'] ?>
|
|
</div>
|
|
<?php unset($_SESSION['codigo_exito']); ?>
|
|
<?php elseif (isset($_SESSION['conexion_error'])): ?>
|
|
<div class="text-danger fade-in">
|
|
<i class="fas fa-exclamation-triangle me-2"></i>
|
|
<?= $_SESSION['conexion_error'] ?>
|
|
</div>
|
|
<?php unset($_SESSION['conexion_error']); ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Contador de intentos -->
|
|
<div id="intentosInfo" class="mt-2 text-center text-muted" style="font-size: 12px;">
|
|
<!-- Se llenará dinámicamente -->
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<h4 class="mb-4">👮 Opciones de Seguridad</h4>
|
|
<div class="row g-3">
|
|
|
|
<!-- Autenticacin de dos factores -->
|
|
<div class="col-md-6">
|
|
<div class="card shadow-sm p-3">
|
|
<h4 class="mb-4 text-dark">Autenticación de dos factores</h4>
|
|
<p>Al activar esta funcionalidad, blindas el acceso a tu cuenta, recibiras un código de acceso a tu correo electrónico para confirmar identidad.</p>
|
|
<form method="POST" action="/IMPORTADORES/seguridad/autenticacionDosFactores">
|
|
<div class="form-check form-switch mb-3">
|
|
<input type="checkbox" name="dos_factores" id="dos_factores" class="form-check-input"
|
|
<?php echo ($dos_factores_estado == 1) ? "checked" : ""; ?>>
|
|
<label class="form-check-label" for="dos_factores">
|
|
<?php echo ($dos_factores_estado == 1) ? "Activo" : "Inactivo"; ?>
|
|
</label>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary"><i class="fas fa-floppy-disk"></i>Guardar configuración</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Cambiar contraseña -->
|
|
<div class="col-md-6">
|
|
<div class="card shadow-sm p-3">
|
|
<h4 class="mb-4 text-dark">Cambiar contraseña</h4>
|
|
<p>Al actualizar tu contraseña, refuerzas la seguridad de tu cuenta. Te recomendamos usar una combinación de letras, números y símbolos para mayor seguridad.</p><br><br>
|
|
<a href="/IMPORTADORES/reset/changePassword" class="btn btn-primary">Cambiar contraseña</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Correo adicional (extra) -->
|
|
<div class="col-md-6">
|
|
<div class="card shadow-sm p-3">
|
|
<h4 class="mb-4 text-dark">Recibe notificaciones</h4>
|
|
<p>Agrega un correo adicional para recibir notificaciones.</p>
|
|
<?php if (!empty($correos['correo_extra'])): ?>
|
|
<p><code><?= htmlspecialchars($correos['correo_extra']) ?></code></p>
|
|
<!-- Formulario para eliminar -->
|
|
<form method="POST" action="/IMPORTADORES/seguridad/eliminarCorreoExtra" id="form-eliminar-extra" class="mt-2 hide"></form>
|
|
<form method="POST" action="/IMPORTADORES/seguridad/modificarCorreoExtra">
|
|
<div class="mb-3">
|
|
<input type="email" name="email-extra" class="form-control" value="" placeholder="Actualizar correo adicional" required>
|
|
</div>
|
|
<div class="d-flex gap-2">
|
|
<button type="submit" class="btn btn-success">
|
|
<i class="fas fa-edit"></i>Actualizar
|
|
</button>
|
|
<button type="button" class="btn btn-danger" onclick="confirmarEliminacion('extra')">
|
|
<i class="fas fa-trash"></i> Eliminar correo
|
|
</button>
|
|
</div>
|
|
</form>
|
|
<?php else: ?>
|
|
<form method="POST" action="/IMPORTADORES/seguridad/correoExtra">
|
|
<div class="mb-3">
|
|
<input type="email" name="email-extra" class="form-control" placeholder="Correo adicional" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary"><i class="fas fa-envelope"></i>Registrar</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Correo de Respaldo -->
|
|
<div class="col-md-6">
|
|
<div class="card shadow-sm p-3">
|
|
<h4 class="mb-4 text-dark">Correo de respaldo</h4>
|
|
<p>Agrega un correo de respaldo para reuperación de tu cuenta.</p>
|
|
<?php if (!empty($correos['correo_respaldo'])): ?>
|
|
<p><code><?= htmlspecialchars($correos['correo_respaldo']) ?></code></p>
|
|
<!-- Formulario para eliminar -->
|
|
<form method="POST" action="/IMPORTADORES/seguridad/eliminarCorreoRespaldo" id="form-eliminar-respaldo" class="mt-2 hide"></form>
|
|
<form method="POST" action="/IMPORTADORES/seguridad/modificarCorreoRspaldo">
|
|
<div class="mb-3">
|
|
<input type="email" name="email-respaldo" class="form-control" value="" placeholder="Actualizar correo de respaldo" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-success">
|
|
<i class="fas fa-edit"></i>Actualizar
|
|
</button>
|
|
<button type="button" class="btn btn-danger" onclick="confirmarEliminacion('respaldo')">
|
|
<i class="fas fa-trash"></i> Eliminar correo
|
|
</button>
|
|
</form>
|
|
<?php else: ?>
|
|
<form method="POST" action="/IMPORTADORES/seguridad/correoRespaldo">
|
|
<div class="mb-3">
|
|
<input type="email" name="email-respaldo" class="form-control" placeholder="Correo de respaldo" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary"><i class="fas fa-envelope"></i>Registrar</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
const form = document.getElementById('formCodigo');
|
|
const mensaje = document.getElementById('mensaje');
|
|
const inputCodigo = document.getElementById('codigo');
|
|
const btnVerificar = document.getElementById('btnVerificar');
|
|
const btnReenviar = document.getElementById('btnReenviarRespaldo');
|
|
const clearBtn = document.getElementById('clearCode');
|
|
const intentosInfo = document.getElementById('intentosInfo');
|
|
|
|
let intentosRealizados = 0;
|
|
const maxIntentos = 3;
|
|
|
|
// Auto-focus en el input al cargar
|
|
inputCodigo.focus();
|
|
|
|
// Mostrar/ocultar botón de limpiar
|
|
inputCodigo.addEventListener('input', function() {
|
|
clearBtn.style.display = this.value.length > 0 ? 'block' : 'none';
|
|
|
|
// Limpiar mensajes previos
|
|
limpiarMensajes();
|
|
|
|
// Remover clases de error/éxito
|
|
inputCodigo.classList.remove('error', 'success');
|
|
|
|
// Solo permitir números
|
|
this.value = this.value.replace(/[^0-9]/g, '');
|
|
|
|
// Actualizar contador visual
|
|
actualizarContadorVisual();
|
|
});
|
|
|
|
// Limpiar input
|
|
clearBtn.addEventListener('click', function() {
|
|
inputCodigo.value = '';
|
|
inputCodigo.focus();
|
|
clearBtn.style.display = 'none';
|
|
limpiarMensajes();
|
|
inputCodigo.classList.remove('error', 'success');
|
|
});
|
|
|
|
// Permitir solo números en tiempo real
|
|
inputCodigo.addEventListener('keypress', function(e) {
|
|
if (!/[0-9]/.test(e.key) && !['Backspace', 'Delete', 'Tab', 'Enter'].includes(e.key)) {
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
|
|
// Auto-envío cuando se completen 6 dígitos (opcional)
|
|
inputCodigo.addEventListener('input', function() {
|
|
if (this.value.length === 6) {
|
|
// Opcional: enviar automáticamente después de un breve delay
|
|
setTimeout(() => form.dispatchEvent(new Event('submit')), 500);
|
|
}
|
|
});
|
|
|
|
// Manejo del formulario
|
|
form.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const codigo = inputCodigo.value.trim();
|
|
if (!validarCodigo(codigo)) return;
|
|
|
|
enviarCodigo(codigo);
|
|
});
|
|
|
|
// Validación del código
|
|
function validarCodigo(codigo) {
|
|
if (!codigo) {
|
|
mostrarError("❌ Por favor, ingresa el código.");
|
|
return false;
|
|
}
|
|
if (codigo.length !== 6) {
|
|
mostrarError("❌ El código debe tener exactamente 6 dígitos.");
|
|
inputCodigo.classList.add('error');
|
|
return false;
|
|
}
|
|
if (!/^\d{6}$/.test(codigo)) {
|
|
mostrarError("❌ El código solo debe contener números.");
|
|
inputCodigo.classList.add('error');
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// 1. SOLUCIÓN PARA EL CONTADOR DE INTENTOS
|
|
// REEMPLAZA tu función enviarCodigo con esta versión de debug:
|
|
function enviarCodigo(codigo) {
|
|
btnVerificar.disabled = true;
|
|
btnVerificar.classList.add('loading');
|
|
btnVerificar.innerHTML = '<span style="opacity: 0;">Verificando...</span>';
|
|
|
|
const formData = new FormData();
|
|
formData.append('codigo', codigo);
|
|
|
|
fetch('/IMPORTADORES/reset/verificarCodigoInterno', {
|
|
method: 'POST',
|
|
body: formData,
|
|
credentials: 'same-origin'
|
|
})
|
|
.then(response => {
|
|
console.log('Status:', response.status);
|
|
console.log('Content-Type:', response.headers.get('content-type'));
|
|
|
|
// SIEMPRE obtener el texto primero para debug
|
|
return response.text();
|
|
})
|
|
.then(text => {
|
|
console.log('Respuesta completa del servidor:');
|
|
console.log(text);
|
|
|
|
// Mostrar los primeros 500 caracteres en la consola
|
|
console.log('Primeros 500 caracteres:', text.substring(0, 500));
|
|
|
|
// Intentar parsear como JSON
|
|
try {
|
|
const data = JSON.parse(text);
|
|
console.log('JSON parseado exitosamente:', data);
|
|
|
|
// Procesar respuesta normal
|
|
if (data.blocked) {
|
|
mostrarError(data.message);
|
|
setTimeout(() => {
|
|
window.location.href = data.redirect;
|
|
}, 4000);
|
|
return;
|
|
}
|
|
|
|
if (data.success === true) {
|
|
mostrarExito(data.message);
|
|
inputCodigo.classList.add('success');
|
|
inputCodigo.disabled = true;
|
|
|
|
setTimeout(() => {
|
|
window.location.href = '/IMPORTADORES/reset/cambiarPasswordInternoView';
|
|
}, 1500);
|
|
|
|
} else {
|
|
manejarCodigoIncorrecto(data);
|
|
}
|
|
|
|
} catch (parseError) {
|
|
console.error('Error al parsear JSON:', parseError);
|
|
console.error('Texto que causó el error:', text);
|
|
|
|
// Mostrar error al usuario
|
|
mostrarError("❌ Error del servidor. Revisa la consola para más detalles.");
|
|
inputCodigo.classList.add('error');
|
|
limpiarYEnfocarInput();
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error de red:', error);
|
|
mostrarError("❌ Error de conexión. Intenta nuevamente.");
|
|
inputCodigo.classList.add('error');
|
|
limpiarYEnfocarInput();
|
|
})
|
|
.finally(() => {
|
|
btnVerificar.disabled = false;
|
|
btnVerificar.classList.remove('loading');
|
|
btnVerificar.innerHTML = '<i class="fas fa-check me-2"></i>Verificar código';
|
|
});
|
|
}
|
|
|
|
// 2. FUNCIÓN CORREGIDA PARA MANEJAR CÓDIGO INCORRECTO
|
|
function manejarCodigoIncorrecto(data) {
|
|
// USAR intentos del servidor, no incrementar localmente
|
|
if (data.intentos_restantes !== undefined) {
|
|
const restantes = data.intentos_restantes;
|
|
intentosRealizados = maxIntentos - restantes;
|
|
} else {
|
|
// Fallback: incrementar localmente solo si no hay datos del servidor
|
|
intentosRealizados++;
|
|
}
|
|
|
|
mostrarError(data.message);
|
|
inputCodigo.classList.add('error');
|
|
|
|
limpiarYEnfocarInput();
|
|
actualizarContadorIntentos();
|
|
|
|
if (data.blocked || (data.intentos_restantes !== undefined && data.intentos_restantes <= 0)) {
|
|
bloquearFormulario();
|
|
}
|
|
}
|
|
|
|
// 3. FUNCIÓN ACTUALIZADA PARA MOSTRAR INTENTOS
|
|
function actualizarContadorIntentos() {
|
|
if (intentosRealizados > 0) {
|
|
const restantes = Math.max(0, maxIntentos - intentosRealizados); // Evitar negativos
|
|
if (restantes > 0) {
|
|
intentosInfo.innerHTML = `
|
|
<i class="fas fa-exclamation-triangle text-warning me-1"></i>
|
|
Intentos restantes: <strong>${restantes}</strong> de ${maxIntentos}
|
|
`;
|
|
} else {
|
|
intentosInfo.innerHTML = `
|
|
<i class="fas fa-ban text-danger me-1"></i>
|
|
<span class="text-danger">Sin intentos restantes</span>
|
|
`;
|
|
}
|
|
intentosInfo.classList.add('fade-in');
|
|
}
|
|
}
|
|
|
|
// Limpiar input y enfocar
|
|
function limpiarYEnfocarInput() {
|
|
setTimeout(() => {
|
|
inputCodigo.value = '';
|
|
inputCodigo.classList.remove('error');
|
|
inputCodigo.focus();
|
|
clearBtn.style.display = 'none';
|
|
}, 1500); // Esperar 1.5 segundos antes de limpiar
|
|
}
|
|
|
|
// Actualizar contador visual
|
|
function actualizarContadorVisual() {
|
|
const longitud = inputCodigo.value.length;
|
|
if (longitud > 0) {
|
|
inputCodigo.setAttribute('placeholder', '0'.repeat(6 - longitud) + inputCodigo.value);
|
|
} else {
|
|
inputCodigo.setAttribute('placeholder', '000000');
|
|
}
|
|
}
|
|
|
|
// Actualizar contador de intentos
|
|
function actualizarContadorIntentos() {
|
|
if (intentosRealizados > 0) {
|
|
const restantes = maxIntentos - intentosRealizados;
|
|
intentosInfo.innerHTML = `
|
|
<i class="fas fa-exclamation-triangle text-warning me-1"></i>
|
|
Intentos restantes: <strong>${restantes}</strong> de ${maxIntentos}
|
|
`;
|
|
intentosInfo.classList.add('fade-in');
|
|
}
|
|
}
|
|
|
|
// Bloquear formulario cuando se exceden intentos
|
|
function bloquearFormulario() {
|
|
inputCodigo.disabled = true;
|
|
btnVerificar.disabled = true;
|
|
btnReenviar.disabled = true;
|
|
|
|
intentosInfo.innerHTML = `
|
|
<i class="fas fa-ban text-danger me-1"></i>
|
|
<span class="text-danger">Código bloqueado por seguridad</span>
|
|
`;
|
|
|
|
// Redirigir a solicitar nuevo código después de 5 segundos
|
|
setTimeout(() => {
|
|
window.location.href = '/IMPORTADORES/reset/enviarCodigoInterno';
|
|
}, 5000);
|
|
}
|
|
|
|
// Funciones de utilidad para mensajes
|
|
function mostrarMensaje(texto, tipo) {
|
|
mensaje.innerHTML = `<div class="${tipo} fade-in">${texto}</div>`;
|
|
mensaje.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
|
}
|
|
|
|
function mostrarError(texto) {
|
|
mostrarMensaje(`<i class="fas fa-exclamation-triangle me-2"></i>${texto}`, 'text-danger');
|
|
}
|
|
|
|
function mostrarExito(texto) {
|
|
mostrarMensaje(`<i class="fas fa-check-circle me-2"></i>${texto}`, 'text-success');
|
|
}
|
|
|
|
function mostrarInfo(texto) {
|
|
mostrarMensaje(`<i class="fas fa-info-circle me-2"></i>${texto}`, 'text-info');
|
|
}
|
|
|
|
function limpiarMensajes() {
|
|
mensaje.innerHTML = '';
|
|
}
|
|
|
|
// Manejo del botón de reenvío
|
|
btnReenviar.addEventListener("click", function() {
|
|
const btnOriginalText = this.innerHTML;
|
|
|
|
// Deshabilitar botón temporalmente
|
|
this.disabled = true;
|
|
this.innerHTML = '<i class="fas fa-spinner fa-spin me-1"></i>Enviando...';
|
|
|
|
fetch("/IMPORTADORES/reset/reenviarCodigo", {
|
|
method: "POST",
|
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
|
body: "accion=reenviarCodigo"
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
mostrarInfo(data.message);
|
|
|
|
// Habilitar botón después de 30 segundos
|
|
setTimeout(() => {
|
|
this.disabled = false;
|
|
this.innerHTML = btnOriginalText;
|
|
}, 30000);
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
mostrarError("❌ Error al reenviar código.");
|
|
|
|
// Restaurar botón en caso de error
|
|
this.disabled = false;
|
|
this.innerHTML = btnOriginalText;
|
|
});
|
|
});
|
|
|
|
// Manejar tecla Enter en cualquier parte del formulario
|
|
document.addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter' && !btnVerificar.disabled) {
|
|
form.dispatchEvent(new Event('submit'));
|
|
}
|
|
});
|
|
|
|
// Prevenir paste de contenido no numérico
|
|
inputCodigo.addEventListener('paste', function(e) {
|
|
e.preventDefault();
|
|
const paste = (e.clipboardData || window.clipboardData).getData('text');
|
|
const numericPaste = paste.replace(/[^0-9]/g, '').substring(0, 6);
|
|
this.value = numericPaste;
|
|
this.dispatchEvent(new Event('input'));
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|