diff --git a/controladores/controladorPerfil.php b/controladores/controladorPerfil.php new file mode 100644 index 0000000..bcf9e42 --- /dev/null +++ b/controladores/controladorPerfil.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/js/cabecera.js b/js/cabecera.js index 09eb81b..fa8c4be 100644 --- a/js/cabecera.js +++ b/js/cabecera.js @@ -202,5 +202,4 @@ $(document).on("click", "#botonCerrarSesion", function (event) { window.location.href = "index.php"; } }); -}); - +}); \ No newline at end of file diff --git a/js/perfil.js b/js/perfil.js index 02859fb..9c5e3ea 100644 --- a/js/perfil.js +++ b/js/perfil.js @@ -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(); } } }); diff --git a/perfil.php b/perfil.php index 0488cfe..9a2c893 100644 --- a/perfil.php +++ b/perfil.php @@ -1,17 +1,3 @@ - @@ -41,7 +27,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro - +
@@ -62,14 +48,14 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro

- +

Foto de perfil @@ -293,7 +279,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro Cancelar - @@ -309,6 +295,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro +