7 Commits

5 changed files with 1500 additions and 1415 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/triviagmatico/includes/conexionBD.php';
require_once __DIR__ . '/../includes/conexionBD.php';
class Categoria{ class Categoria{
+14 -1
View File
@@ -60,12 +60,25 @@ function comprobarSesion() {
`; `;
contenedor.html(htmlUsuario); contenedor.html(htmlUsuario);
// Si estamos en la página de perfil, rellenamos nombre y foto
if ($("#nombre").length) {
$("#nombre").text(respuesta.usuario.nombreUsuario);
// ?t= evita que el navegador enseñe la foto antigua en caché
$("#fotoPerfil").attr("src", avatarUrl + "?t=" + new Date().getTime());
}
// Si estamos en la página principal, mostramos el botón JUGAR // Si estamos en la página principal, mostramos el botón JUGAR
if ($("#colBotonJugar").length) { if ($("#colBotonJugar").length) {
$("#colBotonJugar").removeClass("d-none"); $("#colBotonJugar").removeClass("d-none");
$("#colRanking").removeClass("col-lg-8").addClass("col-lg-7 col-xl-8"); $("#colRanking").removeClass("col-lg-8").addClass("col-lg-7 col-xl-8");
} }
} else { } else {
// Si estamos en el perfil y no hay sesión, volvemos al inicio
if ($("#nombre").length) {
window.location.href = "index.php";
return;
}
// No hay sesión: Botones de Login y Registro // No hay sesión: Botones de Login y Registro
const htmlInvitado = ` const htmlInvitado = `
<button type="button" class="btn btn-kahoot-login rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalLogin"> <button type="button" class="btn btn-kahoot-login rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalLogin">
@@ -205,4 +218,4 @@ $(document).on("click", "#botonCerrarSesion", function (event) {
.fail(function () { .fail(function () {
window.location.href = "index.php"; window.location.href = "index.php";
}); });
}); });
+6 -6
View File
@@ -50,10 +50,9 @@ function cambiarNombre() {
$("#nuevoNombre").val(""); $("#nuevoNombre").val("");
if (typeof comprobarEstadoSesion === "function") { comprobarSesion();
comprobarEstadoSesion();
}
} }
}); });
} }
@@ -71,6 +70,7 @@ function borrarNombre() {
function seleccionarFoto() { function seleccionarFoto() {
$("#inputFoto").click(); $("#inputFoto").click();
} }
$("#inputFoto").change(function () { $("#inputFoto").change(function () {
@@ -79,6 +79,7 @@ $("#inputFoto").change(function () {
if (!archivo) { if (!archivo) {
return; return;
} }
// Comprobamos que sea una imagen // Comprobamos que sea una imagen
if (!archivo.type.startsWith("image/")) { if (!archivo.type.startsWith("image/")) {
@@ -110,9 +111,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") {
comprobarEstadoSesion(); comprobarSesion();
}
} }
}); });
}); });
File diff suppressed because it is too large Load Diff
+3 -19
View File
@@ -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">
@@ -61,15 +47,13 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
<div class="col-md-6 text-center"> <div class="col-md-6 text-center">
<!-- Nombre --> <!-- Nombre -->
<h1 id="nombre" class="nombre"> <h1 id="nombre" class="nombre"></h1>
<?= $nombreUsuario ?>
</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">
@@ -310,7 +294,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
<!-- Tu JavaScript --> <!-- Tu JavaScript -->
<script src="js/perfil.js"></script> <script src="js/perfil.js"></script>
<script src="js/cabecera.js"></script> <script src="js/cabecera.js"></script>
</body> </body>
</html> </html>