grales
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
<?php
|
||||
$nombre = $config['nombre_plataforma'] ?? 'Sistema Integral para Importadores de Hidrocarburos';
|
||||
$siglas = $config['siglas'] ?? 'SIIH';
|
||||
$logo = $config['logo_url'] ?? 'assets/img/logo_siih.png';
|
||||
$color1 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')[0];
|
||||
$color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')[1];
|
||||
$mantenimiento = $config['modo_mantenimiento'] ?? 0;
|
||||
$mensajeMantenimiento = $config['mensaje_mantenimiento'] ?? 'El sistema se encuentra en mantenimiento temporal. Por favor, vuelve más tarde.';
|
||||
require_once __DIR__ . '/../../config/database.php';
|
||||
$conn = getConnection();
|
||||
|
||||
$sql = "SELECT TOP 1 * FROM configuracion_sistema";
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
$config = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
|
||||
|
||||
// Variables con valores por defecto - Branding moderno
|
||||
$nombre = $config['nombre_plataforma'] ?? 'Sistema de Gestión de Importaciones';
|
||||
$siglas = $config['siglas'] ?? 'AduanaSoft';
|
||||
$logo = $config['logo_url'] ?? 'assets/img/logo_aduanasoft.png';
|
||||
$color1 = explode(',', $config['colores_primarios'] ?? '#0f172a,#334155')[0];
|
||||
$color2 = explode(',', $config['colores_primarios'] ?? '#0f172a,#334155')[1];
|
||||
|
||||
if (!isset($_SESSION['email_recuperacion'])) {
|
||||
// Si no hay correo en sesión, redirige a solicitar código
|
||||
@@ -18,60 +24,271 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title><?= htmlspecialchars($siglas) ?> | Recuperación de Contraseña</title>
|
||||
<title><?= htmlspecialchars($siglas) ?> | Verificar Código</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Verifica el código de recuperación enviado a tu correo">
|
||||
<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 href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body { background-color: #f4f6f9; font-family: 'Segoe UI', sans-serif; position: relative; min-height: 100vh; }
|
||||
.navbar { background-color: #fff; }
|
||||
.navbar .nav-link, .navbar-brand { color: <?= $color1 ?> !important; font-weight: 500; }
|
||||
.logo-siih { height: 90px; margin-right: 10px; }
|
||||
.login-container { max-width: 420px; margin: 80px auto; background: white; padding: 40px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08); z-index: 10; position: relative; }
|
||||
.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; }
|
||||
footer { background-color: #e9ecef; padding: 20px; text-align: center; font-size: 14px; color: #666; margin-top: 60px; }
|
||||
/* 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: 5; }
|
||||
#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); }
|
||||
:root {
|
||||
--primary: <?= $color1 ?>;
|
||||
--secondary: <?= $color2 ?>;
|
||||
--accent: #10b981;
|
||||
--surface: #ffffff;
|
||||
--background: #f8fafc;
|
||||
--text: #1e293b;
|
||||
--text-muted: #64748b;
|
||||
--border: #e2e8f0;
|
||||
--error: #ef4444;
|
||||
}
|
||||
@keyframes spin {
|
||||
0% { transform: translate(-50%, -50%) rotate(0deg); }
|
||||
100% { transform: translate(-50%, -50%) rotate(360deg); }
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(-10px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
|
||||
body {
|
||||
background: linear-gradient(135deg, var(--background) 0%, #e2e8f0 100%);
|
||||
font-family: 'Poppins', sans-serif;
|
||||
color: var(--text);
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
backdrop-filter: blur(20px);
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding: 1rem 0;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: 600;
|
||||
font-size: 1.25rem;
|
||||
color: var(--primary) !important;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
color: var(--text-muted) !important;
|
||||
font-weight: 500;
|
||||
padding: 0.5rem 1rem !important;
|
||||
border-radius: 8px;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.nav-link:hover {
|
||||
color: var(--primary) !important;
|
||||
background-color: #f1f5f9;
|
||||
}
|
||||
|
||||
.verification-container {
|
||||
max-width: 500px;
|
||||
margin: 3rem auto;
|
||||
background: var(--surface);
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
|
||||
padding: 3rem;
|
||||
border: 1px solid var(--border);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.verification-container::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 4px;
|
||||
background: linear-gradient(90deg, var(--accent), var(--primary));
|
||||
}
|
||||
|
||||
.verification-header {
|
||||
text-align: center;
|
||||
margin-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
.verification-icon {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: linear-gradient(135deg, #3b82f6, #1d4ed8);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 auto 1.5rem;
|
||||
color: white;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.verification-title {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 700;
|
||||
color: var(--text);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.verification-subtitle {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 500;
|
||||
color: var(--text);
|
||||
margin-bottom: 0.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
border: 2px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 0.75rem 1rem;
|
||||
font-size: 0.95rem;
|
||||
transition: all 0.2s ease;
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.code-input {
|
||||
text-align: center;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.5rem;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
.btn-modern {
|
||||
padding: 12px 28px;
|
||||
border-radius: 12px;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
transition: all 0.3s ease;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.btn-primary-modern {
|
||||
background: linear-gradient(135deg, var(--accent), #059669);
|
||||
color: white;
|
||||
box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
|
||||
}
|
||||
|
||||
.btn-primary-modern:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-outline-modern {
|
||||
background: transparent;
|
||||
color: var(--text-muted);
|
||||
border: 2px solid var(--border);
|
||||
}
|
||||
|
||||
.btn-outline-modern:hover {
|
||||
background: var(--background);
|
||||
color: var(--text);
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.alert-modern {
|
||||
border-radius: 12px;
|
||||
border: none;
|
||||
padding: 1rem 1.25rem;
|
||||
margin-bottom: 1.5rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.alert-danger {
|
||||
background: linear-gradient(135deg, #fef2f2, #fee2e2);
|
||||
color: #dc2626;
|
||||
border: 1px solid #fecaca;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background: linear-gradient(135deg, #f0fdf4, #dcfce7);
|
||||
color: #16a34a;
|
||||
border: 1px solid #bbf7d0;
|
||||
}
|
||||
|
||||
.resend-section {
|
||||
text-align: center;
|
||||
margin-top: 1.5rem;
|
||||
padding-top: 1.5rem;
|
||||
border-top: 2px solid var(--border);
|
||||
}
|
||||
|
||||
.resend-text {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.9rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.resend-link {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.resend-link:hover {
|
||||
color: #059669;
|
||||
}
|
||||
|
||||
footer {
|
||||
background: var(--text);
|
||||
color: #94a3b8;
|
||||
padding: 2rem 0;
|
||||
text-align: center;
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.footer-text {
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.verification-container {
|
||||
margin: 2rem 1rem;
|
||||
padding: 2rem 1.5rem;
|
||||
}
|
||||
|
||||
.verification-title {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.code-input {
|
||||
font-size: 1.25rem;
|
||||
letter-spacing: 0.25rem;
|
||||
}
|
||||
}
|
||||
.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>
|
||||
|
||||
<!-- Navbar institucional -->
|
||||
<!-- NAVBAR -->
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<div class="container">
|
||||
<a class="navbar-brand d-flex align-items-center text-dark" href="#">
|
||||
<img src="/IMPORTADORES/public/<?= htmlspecialchars($logo) ?>" alt="Logo" class="logo-siih">
|
||||
| Inicio de Importador
|
||||
<a class="navbar-brand" href="/IMPORTADORES/">
|
||||
<i class="fas fa-shipping-fast me-2"></i><?= htmlspecialchars($siglas) ?>
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
@@ -82,387 +299,229 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
<a class="nav-link" href="/IMPORTADORES/">Inicio</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link " aria-current="page" href="/IMPORTADORES/registro">Registro</a>
|
||||
<a class="nav-link" href="/IMPORTADORES/registro">Registro</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/IMPORTADORES/login">Inicio sesión</a>
|
||||
<a class="nav-link" href="/IMPORTADORES/login">Iniciar Sesión</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<?php if ($mantenimiento): ?>
|
||||
<div class="container mt-4">
|
||||
<div class="alert alert-danger text-center" role="alert">
|
||||
<i class="fas fa-triangle-exclamation me-2"></i>
|
||||
<?= htmlspecialchars($mensajeMantenimiento) ?>
|
||||
<!-- CONTENEDOR DE VERIFICACIÓN -->
|
||||
<div class="verification-container">
|
||||
<div class="verification-header">
|
||||
<div class="verification-icon">
|
||||
<i class="fas fa-shield-alt"></i>
|
||||
</div>
|
||||
<h1 class="verification-title">Verificar Código</h1>
|
||||
<p class="verification-subtitle">
|
||||
Hemos enviado un código de 6 dígitos a tu correo electrónico.<br>
|
||||
Ingresa el código para continuar con la recuperación.
|
||||
</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Overlay (fondo semitransparente) que cubre la pantalla -->
|
||||
<div class="overlay"></div>
|
||||
<!-- MENSAJES -->
|
||||
<?php if (isset($_SESSION['error_message'])): ?>
|
||||
<div class="alert-modern alert-danger">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||
<?= $_SESSION['error_message'] ?>
|
||||
</div>
|
||||
<?php unset($_SESSION['error_message']); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- 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/login/verificarCodigo" 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
|
||||
<?php if (isset($_SESSION['success_message'])): ?>
|
||||
<div class="alert-modern alert-success">
|
||||
<i class="fas fa-check-circle me-2"></i>
|
||||
<?= $_SESSION['success_message'] ?>
|
||||
</div>
|
||||
<?php unset($_SESSION['success_message']); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="/IMPORTADORES/login/verificar_codigo_recuperacion" method="POST" id="verificationForm">
|
||||
<div class="mb-4">
|
||||
<label for="codigo" class="form-label">
|
||||
<i class="fas fa-key text-muted"></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">
|
||||
<input type="text" name="codigo" id="codigo" class="form-control code-input"
|
||||
required maxlength="6" minlength="6"
|
||||
placeholder="000000"
|
||||
pattern="[0-9]{6}"
|
||||
autocomplete="one-time-code">
|
||||
<small class="form-text text-muted mt-2">
|
||||
<i class="fas fa-info-circle me-1"></i>
|
||||
Ingresa el código de 6 dígitos que recibiste por correo
|
||||
</div>
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<button type="submit" id="btnVerificar" class="btn btn-success w-100">
|
||||
<i class="fas fa-check me-2"></i>Verificar código
|
||||
|
||||
<button type="submit" class="btn-modern btn-primary-modern" id="submitBtn">
|
||||
<i class="fas fa-check"></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>
|
||||
<a href="/IMPORTADORES/login/recuperar" class="btn-modern btn-outline-modern">
|
||||
<i class="fas fa-arrow-left"></i>
|
||||
Volver
|
||||
</a>
|
||||
</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 endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- Contador de intentos -->
|
||||
<div id="intentosInfo" class="mt-2 text-center text-muted" style="font-size: 12px;">
|
||||
<!-- Se llenará dinámicamente -->
|
||||
<div class="resend-section">
|
||||
<div class="resend-text">
|
||||
¿No recibiste el código?
|
||||
</div>
|
||||
<a href="#" class="resend-link" id="resendLink">
|
||||
<i class="fas fa-redo me-1"></i>
|
||||
Reenviar código
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- FOOTER -->
|
||||
<footer class="fixed-bottom">
|
||||
© <?= date('Y') ?> <?= htmlspecialchars($siglas) ?> · <?= htmlspecialchars($nombre) ?>
|
||||
<footer>
|
||||
<div class="container text-center">
|
||||
<div class="footer-text">
|
||||
© <?= date('Y') ?> <?= htmlspecialchars($siglas) ?> - <?= htmlspecialchars($nombre) ?><br>
|
||||
Verificación segura de identidad
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<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');
|
||||
// Auto-format del código
|
||||
document.getElementById('codigo').addEventListener('input', function(e) {
|
||||
let value = e.target.value.replace(/\D/g, ''); // Solo números
|
||||
if (value.length > 6) value = value.substring(0, 6);
|
||||
e.target.value = value;
|
||||
});
|
||||
|
||||
let intentosRealizados = 0;
|
||||
const maxIntentos = 5;
|
||||
// Focus automático al cargar
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.getElementById('codigo').focus();
|
||||
});
|
||||
|
||||
// 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;
|
||||
// Manejar envío del formulario
|
||||
document.getElementById('verificationForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
const codigo = document.getElementById('codigo').value.trim();
|
||||
|
||||
// Validar código
|
||||
if (!codigo || codigo.length !== 6 || !/^\d{6}$/.test(codigo)) {
|
||||
showAlert('error', 'El código debe tener exactamente 6 dígitos');
|
||||
return;
|
||||
}
|
||||
|
||||
// Enviar código para verificación
|
||||
function enviarCodigo(codigo) {
|
||||
// Mostrar estado de carga
|
||||
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/login/verificarCodigo', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
credentials: 'same-origin'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.blocked) {
|
||||
mostrarError(data.message); // <-- función personalizada con un div bonito
|
||||
setTimeout(() => {
|
||||
window.location.href = data.redirect;
|
||||
}, 4000);
|
||||
}
|
||||
|
||||
if (data.success) {
|
||||
// Código correcto
|
||||
mostrarExito(data.message);
|
||||
inputCodigo.classList.add('success');
|
||||
inputCodigo.disabled = true;
|
||||
|
||||
// Redirigir al formulario de cambio de contraseña
|
||||
setTimeout(() => {
|
||||
window.location.href = '/IMPORTADORES/login/cambiarPasswordVista';
|
||||
}, 1500);
|
||||
|
||||
} else {
|
||||
// Código incorrecto
|
||||
manejarCodigoIncorrecto(data);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
mostrarError("❌ Error de conexión. Intenta nuevamente.");
|
||||
inputCodigo.classList.add('error');
|
||||
limpiarYEnfocarInput();
|
||||
})
|
||||
.finally(() => {
|
||||
// Restaurar botón
|
||||
btnVerificar.disabled = false;
|
||||
btnVerificar.classList.remove('loading');
|
||||
btnVerificar.innerHTML = '<i class="fas fa-check me-2"></i>Verificar código';
|
||||
});
|
||||
}
|
||||
|
||||
// Mostrar error de cuenta bloqueada
|
||||
function mostrarError(mensaje) {
|
||||
const mensajeDiv = document.getElementById('mensaje');
|
||||
mensajeDiv.innerHTML = `
|
||||
<div class="text-danger fade-in">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i> ${mensaje}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// Manejar código incorrecto
|
||||
function manejarCodigoIncorrecto(data) {
|
||||
intentosRealizados++;
|
||||
|
||||
mostrarError(data.message);
|
||||
inputCodigo.classList.add('error');
|
||||
|
||||
// Limpiar input y enfocar para nuevo intento
|
||||
limpiarYEnfocarInput();
|
||||
|
||||
// Actualizar contador de intentos
|
||||
actualizarContadorIntentos();
|
||||
|
||||
// Si se bloqueó el código
|
||||
if (data.blocked) {
|
||||
bloquearFormulario();
|
||||
}
|
||||
}
|
||||
|
||||
// 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/login/recuperar';
|
||||
}, 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/login/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
|
||||
|
||||
// Deshabilitar botón y mostrar loading
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Verificando...';
|
||||
|
||||
// Enviar solicitud AJAX
|
||||
fetch('/IMPORTADORES/login/verificar_codigo_recuperacion', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: 'codigo=' + encodeURIComponent(codigo)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// Éxito - redirigir a cambiar contraseña
|
||||
showAlert('success', data.message);
|
||||
setTimeout(() => {
|
||||
this.disabled = false;
|
||||
this.innerHTML = btnOriginalText;
|
||||
}, 30000);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
mostrarError("❌ Error al reenviar código.");
|
||||
window.location.href = '/IMPORTADORES/login/cambiar_password';
|
||||
}, 1500);
|
||||
} else {
|
||||
// Error - mostrar mensaje
|
||||
showAlert('error', data.message);
|
||||
// Rehabilitar botón
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = '<i class="fas fa-check"></i> Verificar 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'));
|
||||
// Si hay bloqueo, redirigir
|
||||
if (data.blocked) {
|
||||
setTimeout(() => {
|
||||
window.location.href = data.redirect || '/IMPORTADORES/login';
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 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'));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
showAlert('error', 'Error de conexión. Intenta nuevamente.');
|
||||
// Rehabilitar botón
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = '<i class="fas fa-check"></i> Verificar Código';
|
||||
});
|
||||
});
|
||||
|
||||
// Manejar reenvío de código
|
||||
document.getElementById('resendLink').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const link = this;
|
||||
const originalText = link.innerHTML;
|
||||
|
||||
// Mostrar loading
|
||||
link.innerHTML = '<i class="fas fa-spinner fa-spin me-1"></i> Reenviando...';
|
||||
link.style.pointerEvents = 'none';
|
||||
|
||||
// Enviar solicitud AJAX
|
||||
fetch('/IMPORTADORES/login/reenviar_codigo', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
showAlert('success', data.message);
|
||||
} else {
|
||||
showAlert('error', data.message);
|
||||
}
|
||||
|
||||
// Restaurar link
|
||||
link.innerHTML = originalText;
|
||||
link.style.pointerEvents = 'auto';
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
showAlert('error', 'Error al reenviar código. Intenta nuevamente.');
|
||||
|
||||
// Restaurar link
|
||||
link.innerHTML = originalText;
|
||||
link.style.pointerEvents = 'auto';
|
||||
});
|
||||
});
|
||||
|
||||
function showAlert(type, message) {
|
||||
// Remover alertas anteriores
|
||||
const existingAlerts = document.querySelectorAll('.alert-modern');
|
||||
existingAlerts.forEach(alert => alert.remove());
|
||||
|
||||
// Crear nueva alerta
|
||||
const alertDiv = document.createElement('div');
|
||||
alertDiv.className = `alert-modern alert-${type === 'success' ? 'success' : 'danger'}`;
|
||||
alertDiv.innerHTML = `
|
||||
<i class="fas fa-${type === 'success' ? 'check-circle' : 'exclamation-triangle'} me-2"></i>
|
||||
${message}
|
||||
`;
|
||||
|
||||
// Insertar antes del formulario
|
||||
const form = document.getElementById('verificationForm');
|
||||
form.parentNode.insertBefore(alertDiv, form);
|
||||
|
||||
// Auto-remover después de 5 segundos si es error
|
||||
if (type === 'error') {
|
||||
setTimeout(() => {
|
||||
alertDiv.remove();
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user