624 lines
18 KiB
PHP
624 lines
18 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];
|
|
|
|
// Verificar que el usuario tenga permiso para cambiar contraseña
|
|
if (!isset($_SESSION['codigo_verificado']) || !isset($_SESSION['email_recuperacion'])) {
|
|
header('Location: /IMPORTADORES/login/recuperar');
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title><?= htmlspecialchars($siglas) ?> | Nueva Contraseña</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="description" content="Establece tu nueva contraseña para acceder a tu cuenta">
|
|
<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;
|
|
--warning: #f59e0b;
|
|
}
|
|
|
|
* {
|
|
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;
|
|
}
|
|
|
|
.password-container {
|
|
max-width: 550px;
|
|
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;
|
|
}
|
|
|
|
.password-container::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
height: 4px;
|
|
background: linear-gradient(90deg, var(--accent), var(--primary));
|
|
}
|
|
|
|
.password-header {
|
|
text-align: center;
|
|
margin-bottom: 2.5rem;
|
|
}
|
|
|
|
.password-icon {
|
|
width: 80px;
|
|
height: 80px;
|
|
background: linear-gradient(135deg, var(--accent), #059669);
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin: 0 auto 1.5rem;
|
|
color: white;
|
|
font-size: 2rem;
|
|
}
|
|
|
|
.password-title {
|
|
font-size: 1.75rem;
|
|
font-weight: 700;
|
|
color: var(--text);
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.password-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);
|
|
}
|
|
|
|
.password-input-group {
|
|
position: relative;
|
|
}
|
|
|
|
.password-toggle {
|
|
position: absolute;
|
|
right: 12px;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
background: none;
|
|
border: none;
|
|
color: var(--text-muted);
|
|
cursor: pointer;
|
|
padding: 0.25rem;
|
|
border-radius: 4px;
|
|
transition: color 0.2s ease;
|
|
}
|
|
|
|
.password-toggle:hover {
|
|
color: var(--accent);
|
|
}
|
|
|
|
.password-strength {
|
|
margin-top: 0.5rem;
|
|
}
|
|
|
|
.strength-bar {
|
|
height: 4px;
|
|
background: var(--border);
|
|
border-radius: 2px;
|
|
overflow: hidden;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.strength-fill {
|
|
height: 100%;
|
|
transition: all 0.3s ease;
|
|
border-radius: 2px;
|
|
}
|
|
|
|
.strength-weak { background: #ef4444; width: 25%; }
|
|
.strength-medium { background: var(--warning); width: 60%; }
|
|
.strength-strong { background: var(--accent); width: 100%; }
|
|
|
|
.strength-text {
|
|
font-size: 0.85rem;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.password-requirements {
|
|
background: linear-gradient(135deg, #f8fafc, #f1f5f9);
|
|
border: 1px solid var(--border);
|
|
border-radius: 12px;
|
|
padding: 1rem;
|
|
margin: 1rem 0;
|
|
}
|
|
|
|
.requirement {
|
|
font-size: 0.85rem;
|
|
color: var(--text-muted);
|
|
margin-bottom: 0.25rem;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.requirement.met {
|
|
color: var(--accent);
|
|
}
|
|
|
|
.requirement i {
|
|
width: 16px;
|
|
font-size: 0.75rem;
|
|
}
|
|
|
|
.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%;
|
|
}
|
|
|
|
.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-primary-modern:disabled {
|
|
opacity: 0.6;
|
|
transform: none;
|
|
box-shadow: none;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.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;
|
|
}
|
|
|
|
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) {
|
|
.password-container {
|
|
margin: 2rem 1rem;
|
|
padding: 2rem 1.5rem;
|
|
}
|
|
|
|
.password-title {
|
|
font-size: 1.5rem;
|
|
}
|
|
}
|
|
</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 NUEVA CONTRASEÑA -->
|
|
<div class="password-container">
|
|
<div class="password-header">
|
|
<div class="password-icon">
|
|
<i class="fas fa-lock"></i>
|
|
</div>
|
|
<h1 class="password-title">Nueva Contraseña</h1>
|
|
<p class="password-subtitle">
|
|
Crea una contraseña segura para proteger tu cuenta de importaciones
|
|
</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; ?>
|
|
|
|
<form action="/IMPORTADORES/login/actualizar_password" method="POST" id="passwordForm">
|
|
<div class="mb-3">
|
|
<label for="password" class="form-label">
|
|
<i class="fas fa-key text-muted"></i>
|
|
Nueva contraseña
|
|
</label>
|
|
<div class="password-input-group">
|
|
<input type="password" name="password" id="password" class="form-control"
|
|
required minlength="8"
|
|
placeholder="Tu nueva contraseña segura">
|
|
<button type="button" class="password-toggle" onclick="togglePassword('password')">
|
|
<i class="fas fa-eye" id="password-icon"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<div class="password-strength">
|
|
<div class="strength-bar">
|
|
<div class="strength-fill" id="strengthBar"></div>
|
|
</div>
|
|
<div class="strength-text" id="strengthText">Ingresa una contraseña</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-4">
|
|
<label for="confirm_password" class="form-label">
|
|
<i class="fas fa-shield-alt text-muted"></i>
|
|
Confirmar contraseña
|
|
</label>
|
|
<div class="password-input-group">
|
|
<input type="password" name="confirm_password" id="confirm_password" class="form-control"
|
|
required minlength="8"
|
|
placeholder="Repite tu nueva contraseña">
|
|
<button type="button" class="password-toggle" onclick="togglePassword('confirm_password')">
|
|
<i class="fas fa-eye" id="confirm_password-icon"></i>
|
|
</button>
|
|
</div>
|
|
<div id="passwordMatch" class="mt-2" style="font-size: 0.85rem;"></div>
|
|
</div>
|
|
|
|
<div class="password-requirements">
|
|
<div class="mb-2" style="font-weight: 600; color: var(--text);">
|
|
<i class="fas fa-info-circle me-2"></i>Requisitos de seguridad:
|
|
</div>
|
|
<div class="requirement" id="req-length">
|
|
<i class="fas fa-circle"></i>
|
|
Mínimo 8 caracteres
|
|
</div>
|
|
<div class="requirement" id="req-uppercase">
|
|
<i class="fas fa-circle"></i>
|
|
Al menos una mayúscula (A-Z)
|
|
</div>
|
|
<div class="requirement" id="req-lowercase">
|
|
<i class="fas fa-circle"></i>
|
|
Al menos una minúscula (a-z)
|
|
</div>
|
|
<div class="requirement" id="req-number">
|
|
<i class="fas fa-circle"></i>
|
|
Al menos un número (0-9)
|
|
</div>
|
|
<div class="requirement" id="req-special">
|
|
<i class="fas fa-circle"></i>
|
|
Al menos un carácter especial (!@#$%^&*)
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn-modern btn-primary-modern" id="submitBtn" disabled>
|
|
<i class="fas fa-save"></i>
|
|
Guardar Nueva Contraseña
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- FOOTER -->
|
|
<footer>
|
|
<div class="container text-center">
|
|
<div class="footer-text">
|
|
© <?= date('Y') ?> <?= htmlspecialchars($siglas) ?> - <?= htmlspecialchars($nombre) ?><br>
|
|
Seguridad avanzada para tu cuenta
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
|
|
<script>
|
|
function togglePassword(inputId) {
|
|
const input = document.getElementById(inputId);
|
|
const icon = document.getElementById(inputId + '-icon');
|
|
|
|
if (input.type === 'password') {
|
|
input.type = 'text';
|
|
icon.classList.remove('fa-eye');
|
|
icon.classList.add('fa-eye-slash');
|
|
} else {
|
|
input.type = 'password';
|
|
icon.classList.remove('fa-eye-slash');
|
|
icon.classList.add('fa-eye');
|
|
}
|
|
}
|
|
|
|
function checkPasswordStrength(password) {
|
|
const requirements = {
|
|
length: password.length >= 8,
|
|
uppercase: /[A-Z]/.test(password),
|
|
lowercase: /[a-z]/.test(password),
|
|
number: /[0-9]/.test(password),
|
|
special: /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)
|
|
};
|
|
|
|
// Actualizar indicadores visuales
|
|
Object.keys(requirements).forEach(req => {
|
|
const element = document.getElementById(`req-${req}`);
|
|
const icon = element.querySelector('i');
|
|
|
|
if (requirements[req]) {
|
|
element.classList.add('met');
|
|
icon.classList.remove('fa-circle');
|
|
icon.classList.add('fa-check-circle');
|
|
} else {
|
|
element.classList.remove('met');
|
|
icon.classList.remove('fa-check-circle');
|
|
icon.classList.add('fa-circle');
|
|
}
|
|
});
|
|
|
|
// Calcular fuerza
|
|
const metCount = Object.values(requirements).filter(Boolean).length;
|
|
const strengthBar = document.getElementById('strengthBar');
|
|
const strengthText = document.getElementById('strengthText');
|
|
|
|
strengthBar.className = 'strength-fill';
|
|
|
|
if (metCount < 3) {
|
|
strengthBar.classList.add('strength-weak');
|
|
strengthText.textContent = 'Contraseña débil';
|
|
strengthText.style.color = '#ef4444';
|
|
} else if (metCount < 5) {
|
|
strengthBar.classList.add('strength-medium');
|
|
strengthText.textContent = 'Contraseña moderada';
|
|
strengthText.style.color = '#f59e0b';
|
|
} else {
|
|
strengthBar.classList.add('strength-strong');
|
|
strengthText.textContent = 'Contraseña fuerte';
|
|
strengthText.style.color = '#10b981';
|
|
}
|
|
|
|
return metCount >= 4; // Requiere al menos 4 de 5 criterios
|
|
}
|
|
|
|
function checkPasswordMatch() {
|
|
const password = document.getElementById('password').value;
|
|
const confirmPassword = document.getElementById('confirm_password').value;
|
|
const matchDiv = document.getElementById('passwordMatch');
|
|
|
|
if (confirmPassword === '') {
|
|
matchDiv.textContent = '';
|
|
return false;
|
|
}
|
|
|
|
if (password === confirmPassword) {
|
|
matchDiv.innerHTML = '<i class="fas fa-check-circle me-1" style="color: #10b981;"></i>Las contraseñas coinciden';
|
|
matchDiv.style.color = '#10b981';
|
|
return true;
|
|
} else {
|
|
matchDiv.innerHTML = '<i class="fas fa-times-circle me-1" style="color: #ef4444;"></i>Las contraseñas no coinciden';
|
|
matchDiv.style.color = '#ef4444';
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function validateForm() {
|
|
const password = document.getElementById('password').value;
|
|
const isStrong = checkPasswordStrength(password);
|
|
const isMatching = checkPasswordMatch();
|
|
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
submitBtn.disabled = !(isStrong && isMatching && password.length >= 8);
|
|
}
|
|
|
|
// Event listeners
|
|
document.getElementById('password').addEventListener('input', validateForm);
|
|
document.getElementById('confirm_password').addEventListener('input', validateForm);
|
|
|
|
// Validación del formulario
|
|
document.getElementById('passwordForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const password = document.getElementById('password').value;
|
|
const confirmPassword = document.getElementById('confirm_password').value;
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
|
|
if (password !== confirmPassword) {
|
|
showAlert('error', 'Las contraseñas no coinciden');
|
|
return;
|
|
}
|
|
|
|
if (!checkPasswordStrength(password)) {
|
|
showAlert('error', 'La contraseña no cumple con los requisitos de seguridad');
|
|
return;
|
|
}
|
|
|
|
// Deshabilitar botón y mostrar loading
|
|
submitBtn.disabled = true;
|
|
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Guardando...';
|
|
|
|
// Enviar formulario normalmente (el método devuelve HTML)
|
|
const formData = new FormData();
|
|
formData.append('password', password);
|
|
formData.append('confirmar', confirmPassword);
|
|
|
|
fetch('/IMPORTADORES/login/actualizar_password', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(html => {
|
|
// Verificar si contiene mensaje de éxito
|
|
if (html.includes('✅ ¡Contraseña actualizada!')) {
|
|
// Mostrar la respuesta HTML del servidor
|
|
document.body.innerHTML = html;
|
|
} else {
|
|
// Es un mensaje de error
|
|
showAlert('error', html.replace(/<[^>]*>/g, '').trim());
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = '<i class="fas fa-save"></i> Guardar Nueva Contraseña';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
showAlert('error', 'Error de conexión. Intenta nuevamente.');
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = '<i class="fas fa-save"></i> Guardar Nueva Contraseña';
|
|
});
|
|
});
|
|
|
|
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('passwordForm');
|
|
form.parentNode.insertBefore(alertDiv, form);
|
|
}
|
|
|
|
// Focus automático
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.getElementById('password').focus();
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|