Compare commits
2 Commits
lobby
...
MVC_perfil.php
| Author | SHA1 | Date | |
|---|---|---|---|
| f74b518d22 | |||
| 77e512be5b |
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirección si el usuario no ha iniciado sesión
|
||||||
|
if (!isset($_SESSION['idUsuario'])) {
|
||||||
|
header('Location: login.php');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$nombreUsuario = htmlspecialchars($_SESSION['nombreUsuario'] ?? 'Usuario');
|
||||||
|
$avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultProfile.jpeg');
|
||||||
|
?>
|
||||||
+1
-2
@@ -43,7 +43,7 @@ function comprobarSesion() {
|
|||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu dropdown-menu-end user-dropdown-menu" aria-labelledby="userDropdown">
|
<ul class="dropdown-menu dropdown-menu-end user-dropdown-menu" aria-labelledby="userDropdown">
|
||||||
<li>
|
<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
|
<i class="fa-solid fa-user text-primary"></i> Perfil
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -203,4 +203,3 @@ $(document).on("click", "#botonCerrarSesion", function (event) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+27
-4
@@ -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
|
// MOSTRAR ESTADISTICAS
|
||||||
// =========================
|
// =========================
|
||||||
@@ -50,8 +73,8 @@ function cambiarNombre() {
|
|||||||
$("#nuevoNombre").val("");
|
$("#nuevoNombre").val("");
|
||||||
|
|
||||||
|
|
||||||
if (typeof comprobarEstadoSesion === "function") {
|
if (typeof comprobarSesion === "function") {
|
||||||
comprobarEstadoSesion();
|
comprobarSesion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -110,8 +133,8 @@ $("#inputFoto").change(function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Actualizamos también el avatar superior en la cabecera
|
// Actualizamos también el avatar superior en la cabecera
|
||||||
if (typeof comprobarEstadoSesion === "function") {
|
if (typeof comprobarSesion === "function") {
|
||||||
comprobarEstadoSesion();
|
comprobarSesion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+5
-18
@@ -1,17 +1,3 @@
|
|||||||
<?php
|
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
|
||||||
session_start();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirección si el usuario no ha iniciado sesión
|
|
||||||
if (!isset($_SESSION['idUsuario'])) {
|
|
||||||
header('Location: login.php');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
$nombreUsuario = htmlspecialchars($_SESSION['nombreUsuario'] ?? 'Usuario');
|
|
||||||
$avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultProfile.jpeg');
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html lang="es">
|
||||||
|
|
||||||
@@ -41,7 +27,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<?php include_once 'cabecera.php'; ?>
|
<div id="cabecera"></div>
|
||||||
|
|
||||||
<div class="perfil-container">
|
<div class="perfil-container">
|
||||||
|
|
||||||
@@ -62,14 +48,14 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
|||||||
|
|
||||||
<!-- Nombre -->
|
<!-- Nombre -->
|
||||||
<h1 id="nombre" class="nombre">
|
<h1 id="nombre" class="nombre">
|
||||||
<?= $nombreUsuario ?>
|
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<!-- FOTO DE PERFIL -->
|
<!-- FOTO DE PERFIL -->
|
||||||
<div class="foto-container">
|
<div class="foto-container">
|
||||||
|
|
||||||
<img id="fotoPerfil"
|
<img id="fotoPerfil"
|
||||||
src="<?= $avatarUsuario ?>"
|
src="img/avatars/defaultProfile.jpeg"
|
||||||
alt="Foto de perfil"
|
alt="Foto de perfil"
|
||||||
class="avatar rounded-circle">
|
class="avatar rounded-circle">
|
||||||
|
|
||||||
@@ -293,7 +279,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
|||||||
Cancelar
|
Cancelar
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button type="submit" form="formCrearPregunta" class="btn btn-kahoot-login" id="btnCrearPregunta">
|
<button type="submit" form="formCrearPregunta" class="btn btn-kahoot-register" id="btnCrearPregunta">
|
||||||
<i class="bi bi-check-lg me-1"></i>
|
<i class="bi bi-check-lg me-1"></i>
|
||||||
Crear pregunta
|
Crear pregunta
|
||||||
</button>
|
</button>
|
||||||
@@ -309,6 +295,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
|
||||||
<!-- Tu JavaScript -->
|
<!-- Tu JavaScript -->
|
||||||
|
<script>$("#cabecera").load("cabecera.php");</script>
|
||||||
<script src="js/perfil.js"></script>
|
<script src="js/perfil.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user