Files
MVE/views/login/verificar_codigo.php
2025-10-21 11:41:30 -06:00

528 lines
15 KiB
PHP

<?php
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
header('Location: /IMPORTADORES/login/recuperar');
exit;
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<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>
:root {
--primary: <?= $color1 ?>;
--secondary: <?= $color2 ?>;
--accent: #10b981;
--surface: #ffffff;
--background: #f8fafc;
--text: #1e293b;
--text-muted: #64748b;
--border: #e2e8f0;
--error: #ef4444;
}
* {
box-sizing: border-box;
}
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;
}
}
</style>
</head>
<body>
<!-- NAVBAR -->
<nav class="navbar navbar-expand-lg">
<div class="container">
<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>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/IMPORTADORES/">Inicio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/IMPORTADORES/registro">Registro</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/IMPORTADORES/login">Iniciar Sesión</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- 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>
<!-- 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; ?>
<?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>
<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
</small>
</div>
<button type="submit" class="btn-modern btn-primary-modern" id="submitBtn">
<i class="fas fa-check"></i>
Verificar Código
</button>
<a href="/IMPORTADORES/login/recuperar" class="btn-modern btn-outline-modern">
<i class="fas fa-arrow-left"></i>
Volver
</a>
</form>
<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>
<div class="container text-center">
<div class="footer-text">
&copy; <?= date('Y') ?> <?= htmlspecialchars($siglas) ?> - <?= htmlspecialchars($nombre) ?><br>
Verificación segura de identidad
</div>
</div>
</footer>
<script>
// 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;
});
// Focus automático al cargar
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('codigo').focus();
});
// 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;
}
// 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(() => {
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';
// Si hay bloqueo, redirigir
if (data.blocked) {
setTimeout(() => {
window.location.href = data.redirect || '/IMPORTADORES/login';
}, 3000);
}
}
})
.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>
</html>