seguir MVC en perfil

This commit is contained in:
2026-10-01 14:24:57 +02:00
parent 77e512be5b
commit f74b518d22
3 changed files with 34 additions and 15 deletions
+2 -3
View File
@@ -43,7 +43,7 @@ function comprobarSesion() {
</button>
<ul class="dropdown-menu dropdown-menu-end user-dropdown-menu" aria-labelledby="userDropdown">
<li>
<a class="dropdown-item d-flex align-items-center gap-2" href="perfil.php">
<a class="dropdown-item d-flex align-items-center gap-2" href="perfil.html">
<i class="fa-solid fa-user text-primary"></i> Perfil
</a>
</li>
@@ -202,5 +202,4 @@ $(document).on("click", "#botonCerrarSesion", function (event) {
window.location.href = "index.php";
}
});
});
});
+27 -4
View File
@@ -1,3 +1,26 @@
// COMPROBAR SESIÓN Y MOSTRAR NOMBRE/AVATAR
// (antes en perfil.php)
$.ajax({
method: "POST",
url: "controladores/controladorUsuario.php",
data: { orden: "comprobarSesion" },
}).done(function (respuesta) {
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
if (!respuesta.activa) {
// Sin sesión: fuera de aquí
window.location.href = "index.php";
return;
}
$("#nombre").text(respuesta.usuario.nombreUsuario || "Usuario");
$("#fotoPerfil").attr(
"src",
respuesta.usuario.avatar || "img/avatars/defaultProfile.jpeg"
);
});
// =========================
// MOSTRAR ESTADISTICAS
// =========================
@@ -50,8 +73,8 @@ function cambiarNombre() {
$("#nuevoNombre").val("");
if (typeof comprobarEstadoSesion === "function") {
comprobarEstadoSesion();
if (typeof comprobarSesion === "function") {
comprobarSesion();
}
}
});
@@ -110,8 +133,8 @@ $("#inputFoto").change(function () {
);
// Actualizamos también el avatar superior en la cabecera
if (typeof comprobarEstadoSesion === "function") {
comprobarEstadoSesion();
if (typeof comprobarSesion === "function") {
comprobarSesion();
}
}
});