Sintaxis
This commit is contained in:
@@ -190,9 +190,9 @@ $dos_factores_estado = obtenerEstadoDosFactores();
|
||||
// Manejo de botones mostrar/ocultar contraseña
|
||||
toggleButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const targetId = this.getAttribute('data-target');
|
||||
const targetId = this.getAttribute('data-target');
|
||||
const targetInput = document.getElementById(targetId);
|
||||
const icon = this.querySelector('i');
|
||||
const icon = this.querySelector('i');
|
||||
|
||||
if (targetInput.type === 'password') {
|
||||
targetInput.type = 'text';
|
||||
@@ -220,8 +220,8 @@ $dos_factores_estado = obtenerEstadoDosFactores();
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const passwordActual = inputActual.value.trim();
|
||||
const passwordNueva = inputNueva.value.trim();
|
||||
const passwordActual = inputActual.value.trim();
|
||||
const passwordNueva = inputNueva.value.trim();
|
||||
const confirmarPassword = inputConfirmar.value.trim();
|
||||
|
||||
if (!validarFormulario(passwordActual, passwordNueva, confirmarPassword)) {
|
||||
@@ -233,7 +233,7 @@ $dos_factores_estado = obtenerEstadoDosFactores();
|
||||
// Función para enviar cambio de contraseña
|
||||
function enviarCambioPassword(actual, nueva, confirmar) {
|
||||
// Mostrar estado de carga
|
||||
btnCambiar.disabled = true;
|
||||
btnCambiar.disabled = true;
|
||||
btnCambiar.classList.add('loading');
|
||||
btnCambiar.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Cambiando contraseña...';
|
||||
|
||||
@@ -243,46 +243,65 @@ $dos_factores_estado = obtenerEstadoDosFactores();
|
||||
formData.append('confirmar_password', confirmar);
|
||||
|
||||
fetch('/IMPORTADORES/reset/cambiarPasswordInterno', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
credentials: 'same-origin'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// Éxito: mostrar mensaje y redirigir
|
||||
mostrarExito(data.message);
|
||||
|
||||
// Deshabilitar formulario
|
||||
deshabilitarFormulario();
|
||||
|
||||
// Redirigir después de 2 segundos
|
||||
setTimeout(() => {
|
||||
if (data.redirect) {
|
||||
window.location.href = data.redirect;
|
||||
} else {
|
||||
window.location.href = '/IMPORTADORES/login'; // Redirigir a login por defecto
|
||||
}
|
||||
}, 2000);
|
||||
.then(response => {
|
||||
// Primero verificar si la respuesta es exitosa
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
// Obtener el texto de la respuesta
|
||||
return response.text();
|
||||
})
|
||||
.then(text => {
|
||||
// Intentar parsear como JSON
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(text);
|
||||
} catch (e) {
|
||||
// Si no es JSON válido, mostrar el error HTML recibido
|
||||
console.error('Respuesta no válida del servidor:', text);
|
||||
throw new Error('El servidor devolvió una respuesta no válida. Revisa la consola para más detalles.');
|
||||
}
|
||||
|
||||
// Procesar la respuesta JSON
|
||||
if (data.success) {
|
||||
// Éxito: mostrar mensaje y redirigir
|
||||
mostrarExito(data.message);
|
||||
|
||||
// Deshabilitar formulario
|
||||
deshabilitarFormulario();
|
||||
|
||||
// Redirigir después de 2 segundos
|
||||
setTimeout(() => {
|
||||
if (data.redirect) {
|
||||
window.location.href = data.redirect;
|
||||
} else {
|
||||
// Error: mostrar mensaje
|
||||
mostrarError(data.message);
|
||||
|
||||
// Limpiar contraseña actual por seguridad
|
||||
inputActual.value = '';
|
||||
inputActual.focus();
|
||||
window.location.href = '/IMPORTADORES/login'; // Redirigir a login por defecto
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
mostrarError("❌ Error de conexión. Intenta nuevamente.");
|
||||
})
|
||||
.finally(() => {
|
||||
// Restaurar botón solo si no fue exitoso
|
||||
if (!btnCambiar.classList.contains('success')) {
|
||||
btnCambiar.disabled = false;
|
||||
btnCambiar.classList.remove('loading');
|
||||
btnCambiar.innerHTML = '<i class="fas fa-lock me-2"></i>Cambiar contraseña';
|
||||
}, 2000);
|
||||
} else {
|
||||
// Error: mostrar mensaje
|
||||
mostrarError(data.message);
|
||||
|
||||
// Limpiar contraseña actual por seguridad
|
||||
inputActual.value = '';
|
||||
inputActual.focus();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
mostrarError("❌ Error de conexión. Intenta nuevamente.");
|
||||
})
|
||||
.finally(() => {
|
||||
// Restaurar botón solo si no fue exitoso
|
||||
if (!btnCambiar.classList.contains('success')) {
|
||||
btnCambiar.disabled = false;
|
||||
btnCambiar.classList.remove('loading');
|
||||
btnCambiar.innerHTML = '<i class="fas fa-lock me-2"></i>Cambiar contraseña';
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -372,12 +391,12 @@ $dos_factores_estado = obtenerEstadoDosFactores();
|
||||
|
||||
// Deshabilitar formulario tras éxito
|
||||
function deshabilitarFormulario() {
|
||||
inputActual.disabled = true;
|
||||
inputNueva.disabled = true;
|
||||
inputActual.disabled = true;
|
||||
inputNueva.disabled = true;
|
||||
inputConfirmar.disabled = true;
|
||||
btnCambiar.disabled = true;
|
||||
btnCambiar.disabled = true;
|
||||
btnCambiar.classList.add('success');
|
||||
btnCambiar.innerHTML = '<i class="fas fa-check me-2"></i>Contraseña cambiada exitosamente';
|
||||
btnCambiar.innerHTML = '<i class="fas fa-check me-2"></i>Contraseña cambiada exitosamente';
|
||||
|
||||
toggleButtons.forEach(btn => btn.disabled = true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user