Cambios
This commit is contained in:
@@ -302,12 +302,24 @@
|
||||
e.preventDefault();
|
||||
|
||||
let isValid = true;
|
||||
const inputs = document.querySelectorAll('input.form-control, select.form-select');
|
||||
|
||||
// Validar todos los campos
|
||||
inputs.forEach(input => {
|
||||
if (!input.checkValidity()) {
|
||||
input.classList.add('shake');
|
||||
isValid = false;
|
||||
setTimeout(() => input.classList.remove('shake'), 500);
|
||||
}
|
||||
});
|
||||
|
||||
// Si todo es válido, enviar el formulario
|
||||
if (isValid) {
|
||||
this.submit(); // Esta línea faltaba en tu código original
|
||||
} else {
|
||||
// Mostrar mensaje de error si lo deseas
|
||||
Swal.fire({ title: 'Campos incompletos', text: 'Por favor complete todos los campos requeridos', icon: 'error' });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@
|
||||
<div class="col-md-4 animate__animated animate__fadeInUp" style="animation-delay: <?= $delay ?>s;">
|
||||
<div class="card shadow-sm p-3 card-hover position-relative h-100">
|
||||
<div class="card-body p-0 d-flex flex-column">
|
||||
<h5 class="text-success mb-3">Aprobar de usuarios</h5>
|
||||
<h5 class="text-success mb-3">Aprobar usuarios</h5>
|
||||
<p class="text-muted small flex-grow-1 mb-4">Aprueba los usuarios que solicitaron un registro.</p>
|
||||
<div class="mt-auto">
|
||||
<button class="btn btn-success btn-sm mt-auto w-100 btn-animated"
|
||||
|
||||
@@ -143,7 +143,7 @@ if ($tipoUsuario === 'agente_aduanal') {
|
||||
|
||||
<div class="col-md-4 d-flex align-items-end form-group-animated">
|
||||
<button type="submit" class="btn btn-success W-100 btn-animated">
|
||||
<i class="fas fa-plus"></i> Registrar Estado
|
||||
Registrar
|
||||
</button>
|
||||
<a href="/IMPORTADORES/locaciones/lista" class="btn btn-secondary ms-2 W-100 btn-animated">Cancelar</a>
|
||||
</div>
|
||||
@@ -186,7 +186,7 @@ if ($tipoUsuario === 'agente_aduanal') {
|
||||
|
||||
<div class="col-md-4 d-flex align-items-end form-group-animated">
|
||||
<button type="submit" class="btn btn-success W-100 btn-animated">
|
||||
<i class="fas fa-plus"></i> Registrar Ciudad
|
||||
Registrar
|
||||
</button>
|
||||
<a href="/IMPORTADORES/locaciones/lista" class="btn btn-secondary ms-2 W-100 btn-animated">Cancelar</a>
|
||||
</div>
|
||||
|
||||
@@ -173,16 +173,16 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const form = document.getElementById('formCodigo');
|
||||
const mensaje = document.getElementById('mensaje');
|
||||
const inputCodigo = document.getElementById('codigo');
|
||||
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 btnReenviar = document.getElementById('btnReenviarRespaldo');
|
||||
const clearBtn = document.getElementById('clearCode');
|
||||
const intentosInfo = document.getElementById('intentosInfo');
|
||||
|
||||
let intentosRealizados = 0;
|
||||
const maxIntentos = 3; // ⬅️ Cambiado de 5 a 3 para el controlador interno
|
||||
const maxIntentos = 5;
|
||||
|
||||
// Auto-focus en el input al cargar
|
||||
inputCodigo.focus();
|
||||
@@ -220,6 +220,14 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
}
|
||||
});
|
||||
|
||||
// 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();
|
||||
@@ -227,7 +235,7 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
const codigo = inputCodigo.value.trim();
|
||||
if (!validarCodigo(codigo)) return;
|
||||
|
||||
enviarCodigoInterno(codigo);
|
||||
enviarCodigo(codigo);
|
||||
});
|
||||
|
||||
// Validación del código
|
||||
@@ -252,8 +260,8 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// ⬅️ NUEVA FUNCIÓN: Enviar código para verificación INTERNA
|
||||
function enviarCodigoInterno(codigo) {
|
||||
// Enviar código para verificación
|
||||
function enviarCodigo(codigo) {
|
||||
// Mostrar estado de carga
|
||||
btnVerificar.disabled = true;
|
||||
btnVerificar.classList.add('loading');
|
||||
@@ -262,43 +270,34 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
const formData = new FormData();
|
||||
formData.append('codigo', codigo);
|
||||
|
||||
fetch('/IMPORTADORES/reset/verificarCodigoInterno', {
|
||||
fetch('/IMPORTADORES/login/verificarCodigo', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
credentials: 'same-origin'
|
||||
})
|
||||
.then(response => {
|
||||
// ⬅️ IMPORTANTE: Verificar si la respuesta es un redirect (302/200 HTML)
|
||||
if (response.ok && response.headers.get('content-type')?.includes('text/html')) {
|
||||
// Si el servidor devolvió HTML, significa que hubo un redirect exitoso
|
||||
mostrarExito("✅ Código verificado correctamente. Redirigiendo...");
|
||||
inputCodigo.classList.add('success');
|
||||
inputCodigo.disabled = true;
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/IMPORTADORES/reset/cambiarPasswordInternoView';
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
// Si no es HTML, intentar parsear como JSON (para errores)
|
||||
return response.json();
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (!data) return; // Ya fue manejado arriba como éxito
|
||||
|
||||
// Manejar respuestas de error JSON
|
||||
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/reset/cambiarPasswordInternoView';
|
||||
window.location.href = '/IMPORTADORES/login/cambiarPasswordVista';
|
||||
}, 1500);
|
||||
|
||||
} else {
|
||||
manejarCodigoIncorrectoInterno(data);
|
||||
// Código incorrecto
|
||||
manejarCodigoIncorrecto(data);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -315,56 +314,35 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
});
|
||||
}
|
||||
|
||||
// ⬅️ NUEVA FUNCIÓN: Manejar errores específicos del controlador interno
|
||||
function manejarCodigoIncorrectoInterno(data) {
|
||||
// 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 || "❌ Código incorrecto.");
|
||||
mostrarError(data.message);
|
||||
inputCodigo.classList.add('error');
|
||||
|
||||
// Limpiar input y enfocar para nuevo intento
|
||||
limpiarYEnfocarInput();
|
||||
|
||||
// Actualizar contador de intentos
|
||||
actualizarContadorIntentosInterno();
|
||||
actualizarContadorIntentos();
|
||||
|
||||
// Si se excedieron los intentos (3 para interno)
|
||||
if (intentosRealizados >= maxIntentos) {
|
||||
bloquearFormularioInterno();
|
||||
// Si se bloqueó el código
|
||||
if (data.blocked) {
|
||||
bloquearFormulario();
|
||||
}
|
||||
}
|
||||
|
||||
// ⬅️ MODIFICADA: Actualizar contador de intentos para interno
|
||||
function actualizarContadorIntentosInterno() {
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
// ⬅️ MODIFICADA: Bloquear formulario para interno
|
||||
function bloquearFormularioInterno() {
|
||||
inputCodigo.disabled = true;
|
||||
btnVerificar.disabled = true;
|
||||
if (btnReenviar) btnReenviar.disabled = true;
|
||||
|
||||
intentosInfo.innerHTML = `
|
||||
<i class="fas fa-ban text-danger me-1"></i>
|
||||
<span class="text-danger">Demasiados intentos fallidos</span>
|
||||
`;
|
||||
|
||||
mostrarError("❌ Demasiados intentos fallidos. Redirigiendo...");
|
||||
|
||||
// Redirigir a la página de seguridad después de 3 segundos
|
||||
setTimeout(() => {
|
||||
window.location.href = '/IMPORTADORES/seguridad/index';
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// Limpiar input y enfocar
|
||||
function limpiarYEnfocarInput() {
|
||||
setTimeout(() => {
|
||||
@@ -372,7 +350,7 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
inputCodigo.classList.remove('error');
|
||||
inputCodigo.focus();
|
||||
clearBtn.style.display = 'none';
|
||||
}, 1500);
|
||||
}, 1500); // Esperar 1.5 segundos antes de limpiar
|
||||
}
|
||||
|
||||
// Actualizar contador visual
|
||||
@@ -385,6 +363,35 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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>`;
|
||||
@@ -407,39 +414,40 @@ if (!isset($_SESSION['email_recuperacion'])) {
|
||||
mensaje.innerHTML = '';
|
||||
}
|
||||
|
||||
// Manejo del botón de reenvío (si existe)
|
||||
if (btnReenviar) {
|
||||
btnReenviar.addEventListener("click", function() {
|
||||
const btnOriginalText = this.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);
|
||||
|
||||
this.disabled = true;
|
||||
this.innerHTML = '<i class="fas fa-spinner fa-spin me-1"></i>Enviando...';
|
||||
|
||||
fetch("/IMPORTADORES/reset/reenviarCodigoInterno", {
|
||||
method: "POST",
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
body: "accion=reenviarCodigo"
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
mostrarInfo(data.message);
|
||||
|
||||
setTimeout(() => {
|
||||
this.disabled = false;
|
||||
this.innerHTML = btnOriginalText;
|
||||
}, 30000);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
mostrarError("❌ Error al reenviar código.");
|
||||
|
||||
// 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
|
||||
// Manejar tecla Enter en cualquier parte del formulario
|
||||
document.addEventListener('keypress', function(e) {
|
||||
if (e.key === 'Enter' && !btnVerificar.disabled) {
|
||||
form.dispatchEvent(new Event('submit'));
|
||||
|
||||
@@ -85,7 +85,6 @@
|
||||
<th>País Origen/Destino</th>
|
||||
<th>País Comprador/Vendedor</th>
|
||||
<th>Uso Mercancía</th>
|
||||
<th>Estado Mercancía</th>
|
||||
<th>Preferencia</th>
|
||||
<th>Frecuencia Uso</th>
|
||||
<th>Acciones</th>
|
||||
@@ -104,7 +103,6 @@
|
||||
<td><?= htmlspecialchars($row['pais_origen_destino']) ?></td>
|
||||
<td><?= htmlspecialchars($row['pais_comprador_vendedor']) ?></td>
|
||||
<td><?= htmlspecialchars($row['uso_mercancia']) ?></td>
|
||||
<td><?= htmlspecialchars($row['estado_mercancia']) ?></td>
|
||||
<td><?= htmlspecialchars($row['preferencia']) ?></td>
|
||||
<td><?= htmlspecialchars($row['frecuencia_uso']) ?></td>
|
||||
<td class="text-center">
|
||||
|
||||
@@ -98,9 +98,9 @@
|
||||
<td><?= $ag['creado_en'] ? $ag['creado_en']->format('Y-m-d H:i') : '' ?></td>
|
||||
<td>
|
||||
<?php if (!empty($ag['estado_solicitud']) && $ag['estado_solicitud'] === 'PENDIENTE'): ?>
|
||||
<a href="/IMPORTADORES/importadores/cancelarVinculacion?id=<?= $ag['id_agencia'] ?>" class="btn btn-sm btn-danger mt-auto w-auto btn-animated">Cancelar solicitud</a>
|
||||
<button onclick="confirmCancelRequest(<?= $ag['id_agencia'] ?>)" class="btn btn-sm btn-danger mt-auto w-auto btn-animated">Cancelar solicitud</button>
|
||||
<?php else: ?>
|
||||
<a href="/IMPORTADORES/importadores/vincular?id=<?= $ag['id_agencia'] ?>" class="btn btn-sm btn-success mt-auto w-auto btn-animated">Vincular</a>
|
||||
<button onclick="confirmLinkAgency(<?= $ag['id_agencia'] ?>)" class="btn btn-sm btn-success mt-auto w-auto btn-animated">Vincular</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -121,6 +121,36 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function confirmLinkAgency(id) {
|
||||
Swal.fire({
|
||||
title: '¿Quieres vincularte a esta agencia?',
|
||||
text: 'Podrás usarla para tus operaciones.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Sí, vincularme',
|
||||
cancelButtonText: 'Cancelar'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
window.location.href = `/IMPORTADORES/importadores/vincular?id=${id}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function confirmCancelRequest(id) {
|
||||
Swal.fire({
|
||||
title: '¿Quieres cancelar la solicitud?',
|
||||
text: 'Esta acción no se puede deshacer.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Sí, cancelar solicitud',
|
||||
cancelButtonText: 'Cancelar'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
window.location.href = `/IMPORTADORES/importadores/cancelarVinculacion?id=${id}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php if (isset($_GET['success'])): ?>
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
<a href="/IMPORTADORES/vinculaciones/nuevaVinculacion" class="btn btn-success mb-3 mt-auto w-auto btn-animated fade-in-up">➕ Nueva Vinculación</a>
|
||||
<!-- TABLA DE VINCULACIÓN USUARIO -->
|
||||
<div class="card p-3 shadow-sm card-hover position-relative h-auto fade-in-up">
|
||||
<h5 class="mb-3">🏪 Agencia Vinculadas</h5>
|
||||
<h5 class="mb-3">🏪 Agencias Vinculadas</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover align-middle" id="tabla-vinculaciones-usuario">
|
||||
<thead>
|
||||
@@ -101,7 +101,7 @@
|
||||
<?php if ($v['id_agencia'] == ($_SESSION['id_agencia_en_uso'] ?? null)): ?>
|
||||
<span class="badge bg-secondary">En uso</span>
|
||||
<?php else: ?>
|
||||
<a href="/IMPORTADORES/importadores/cambiarAgenciaActiva?id=<?= $v['id_agencia'] ?>" class="btn btn-sm btn-success mt-auto w-auto btn-animated">Usar Agencia</a>
|
||||
<button onclick="confirmChangeAgency(<?= $v['id_agencia'] ?>)" class="btn btn-sm btn-success mt-auto w-auto btn-animated">Usar Agencia</button>
|
||||
<?php endif; ?>
|
||||
<button onclick="confirmUnlink(<?= $v['id_relacion'] ?>)" class="btn btn-sm btn-danger mt-auto w-auto btn-animated">Desvincular</button>
|
||||
</td>
|
||||
@@ -138,6 +138,21 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function confirmChangeAgency(id) {
|
||||
Swal.fire({
|
||||
title: '¿Quieres cambiar de agencia?',
|
||||
text: 'Dejaras de usar la agencia actual y cambiarás a la nueva.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Sí, cambiar agencia',
|
||||
cancelButtonText: 'Cancelar'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
window.location.href = `/IMPORTADORES/importadores/cambiarAgenciaActiva?id=${id}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php if (isset($_GET['success'])): ?>
|
||||
|
||||
Reference in New Issue
Block a user