Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d20b1fa7d7 | |||
| bdc7bef169 | |||
| 963ab50f37 | |||
| 9488d7cee7 | |||
| 0b8045544b | |||
| d67e4d76e2 | |||
| 20131bbe7f | |||
| c624f06b88 | |||
| e879a92ac2 | |||
| c18576e97d | |||
| fd4301d741 | |||
| afff6cfb4a | |||
| cbdbd8bc4b |
+3
-2
@@ -10,11 +10,12 @@
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
<link rel="stylesheet" href="css/buscadorSala.css">
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php include_once("cabecera.php"); ?>
|
||||
<header id="cabecera-container"></header>
|
||||
|
||||
<main class="container py-4">
|
||||
|
||||
@@ -99,9 +100,9 @@
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
<script src="js/sala.js"></script>
|
||||
<script src="js/buscadorSala.js"></script>
|
||||
<script src="js/cabecera.js"></script>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
+19
-5
@@ -1,3 +1,15 @@
|
||||
<head>
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- FontAwesome para iconos -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
||||
<!-- Google Fonts para estilo Kahoot -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- cabecera.html -->
|
||||
<nav class="navbar navbar-expand-lg navbar-kahoot py-3 mb-4">
|
||||
<div class="container">
|
||||
@@ -84,13 +96,15 @@
|
||||
<label for="regPasswordConfirm">Confirmar contraseña</label>
|
||||
</div>
|
||||
<input type="hidden" name="orden" value="registrar">
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<input type="submit" value="Registrarse" class="btn btn-success rounded-pill px-4" id="botonAceptarRegistro"></input>
|
||||
</div>
|
||||
</form>
|
||||
<div id="errorRegistro" class="text-danger fw-bold mt-2"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-success rounded-pill px-4" id="botonAceptarRegistro">Registrarse</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/triviagmatico/includes/conexionBD.php';
|
||||
|
||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||
|
||||
class Categoria{
|
||||
|
||||
|
||||
@@ -229,7 +229,13 @@ class Juego
|
||||
* - la respuesta pertenece a esa pregunta
|
||||
* - el usuario no ha respondido ya esa pregunta
|
||||
*/
|
||||
public static function registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta)
|
||||
public static function registrarRespuesta(
|
||||
$idPartida,
|
||||
$idUsuario,
|
||||
$idPartidaxPregunta,
|
||||
$idRespuesta,
|
||||
$tiempoRespuesta
|
||||
)
|
||||
{
|
||||
$conexion = conexionBD();
|
||||
if (is_array($conexion)) {
|
||||
@@ -298,7 +304,8 @@ class Juego
|
||||
null,
|
||||
$idPartidaxPregunta,
|
||||
$idUsuario,
|
||||
$idRespuesta
|
||||
$idRespuesta,
|
||||
$tiempoRespuesta
|
||||
);
|
||||
$guardado = $almacenada->guardarRespuesta();
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ class Respuesta{
|
||||
$consulta->bindParam(':idPregunta', $this->idPregunta);
|
||||
$consulta->bindParam(':nombreRespuesta', $this->nombreRespuesta);
|
||||
$consulta->bindParam(':correcta', $this->correcta);
|
||||
|
||||
|
||||
$consulta->execute();
|
||||
$respuesta = [
|
||||
'exito' => 'La respuesta se guardó correctamente.',
|
||||
|
||||
@@ -7,43 +7,53 @@ class RespuestaAlmacenada {
|
||||
public $idPartidaxPregunta;
|
||||
public $idUsuario;
|
||||
public $idRespuesta;
|
||||
public $tiempoRespuesta;
|
||||
|
||||
public function __construct($idRespuestaAlmacenada = null, $idPartidaxPregunta = null, $idUsuario = null, $idRespuesta = null) {
|
||||
public function __construct($idRespuestaAlmacenada = null, $idPartidaxPregunta = null, $idUsuario = null, $idRespuesta = null, $tiempoRespuesta = null) {
|
||||
$this->idRespuestaAlmacenada = $idRespuestaAlmacenada;
|
||||
$this->idPartidaxPregunta = $idPartidaxPregunta;
|
||||
$this->idUsuario = $idUsuario;
|
||||
$this->idRespuesta = $idRespuesta;
|
||||
$this->tiempoRespuesta = $tiempoRespuesta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Guarda la respuesta que ha seleccionado un usuario en una pregunta de la partida.
|
||||
*/
|
||||
public function guardarRespuesta() {
|
||||
$conexion = conexionBD();
|
||||
if (is_array($conexion)) return $conexion;
|
||||
$conexion = conexionBD();
|
||||
|
||||
try {
|
||||
$sql = "INSERT INTO respuestaalmacenada (idPartidaxPregunta, idUsuario, idRespuesta)
|
||||
VALUES (:idPartidaxPregunta, :idUsuario, :idRespuesta)";
|
||||
$consulta = $conexion->prepare($sql);
|
||||
|
||||
$consulta->bindParam(':idPartidaxPregunta', $this->idPartidaxPregunta);
|
||||
$consulta->bindParam(':idUsuario', $this->idUsuario);
|
||||
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
|
||||
$consulta->execute();
|
||||
|
||||
return [
|
||||
'exito' => 'Respuesta del usuario almacenada correctamente.',
|
||||
'exito_tecnico' => $conexion->lastInsertId()
|
||||
];
|
||||
} catch (PDOException $error) {
|
||||
return [
|
||||
'error' => 'Ocurrió un error al guardar la respuesta del jugador.',
|
||||
'error_tecnico' => $error->getMessage()
|
||||
];
|
||||
}
|
||||
if (is_array($conexion)) {
|
||||
return $conexion;
|
||||
}
|
||||
|
||||
try {
|
||||
$sql = "INSERT INTO respuestaalmacenada
|
||||
(idPartidaxPregunta, idUsuario, idRespuesta, tiempoRespuesta)
|
||||
VALUES
|
||||
(:idPartidaxPregunta, :idUsuario, :idRespuesta, :tiempoRespuesta)";
|
||||
|
||||
$consulta = $conexion->prepare($sql);
|
||||
|
||||
$consulta->bindParam(':idPartidaxPregunta', $this->idPartidaxPregunta);
|
||||
$consulta->bindParam(':idUsuario', $this->idUsuario);
|
||||
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
|
||||
$consulta->bindParam(':tiempoRespuesta', $this->tiempoRespuesta);
|
||||
|
||||
$consulta->execute();
|
||||
|
||||
return [
|
||||
'exito' => 'Respuesta almacenada correctamente.'
|
||||
];
|
||||
|
||||
} catch (PDOException $error) {
|
||||
return [
|
||||
'error' => 'Ocurrió un error al guardar la respuesta.',
|
||||
'error_tecnico' => $error->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene los aciertos totales de un usuario en una partida específica.
|
||||
* Útil para calcular las estadísticas individuales al terminar el juego.
|
||||
|
||||
@@ -74,34 +74,47 @@ switch ($orden) {
|
||||
|
||||
case 'responder':
|
||||
|
||||
if (!isset($_POST['idPartidaxPregunta']) || !isset($_POST['idRespuesta'])){
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos para registrar la respuesta.'
|
||||
]);
|
||||
if (
|
||||
!isset($_POST['idPartidaxPregunta']) ||
|
||||
!isset($_POST['idRespuesta']) ||
|
||||
!isset($_POST['tiempoRespuesta'])
|
||||
) {
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos para registrar la respuesta.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta']);
|
||||
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta']);
|
||||
$idRespuesta = intval($_POST['idRespuesta']);
|
||||
$tiempoRespuesta = intval($_POST['tiempoRespuesta']);
|
||||
|
||||
$idRespuesta = intval($_POST['idRespuesta']);
|
||||
|
||||
if ($idPartidaxPregunta <= 0 || $idRespuesta <= 0){
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Los datos de la respuesta no son válidos.'
|
||||
]);
|
||||
if (
|
||||
$idPartidaxPregunta <= 0 ||
|
||||
$idRespuesta <= 0 ||
|
||||
$tiempoRespuesta < 0
|
||||
) {
|
||||
echo json_encode([
|
||||
'error' => 'Los datos de la respuesta no son válidos.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Registramos la respuesta del usuario
|
||||
// Registramos la respuesta del usuario junto con su tiempo de respuesta
|
||||
|
||||
$resultado = Juego::registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta);
|
||||
$resultado = Juego::registrarRespuesta(
|
||||
$idPartida,
|
||||
$idUsuario,
|
||||
$idPartidaxPregunta,
|
||||
$idRespuesta,
|
||||
$tiempoRespuesta
|
||||
);
|
||||
|
||||
echo json_encode($resultado);
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
// Finalizar la partida y registrar los aciertos del usuario
|
||||
|
||||
|
||||
@@ -4,13 +4,20 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Triviagmático</title>
|
||||
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
||||
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- FontAwesome para iconos -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
||||
<!-- Google Fonts para estilo Kahoot -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php include 'cabecera.php'; ?>
|
||||
<header id="cabecera-container"></header>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="row justify-content-center align-items-center g-4">
|
||||
@@ -46,6 +53,7 @@
|
||||
<!-- JS de Bootstrap -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="js/index.js"></script>
|
||||
<script src="js/cabecera.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+110
-108
@@ -1,14 +1,19 @@
|
||||
let idUsuarioSesion = null;
|
||||
|
||||
$(document).ready(function () {
|
||||
comprobarSesion();
|
||||
// Cargar la cabecera HTML e iniciar comprobación de sesión SOLO al terminar de cargar
|
||||
$("#cabecera-container").load("cabecera.html", function (response, status, xhr) {
|
||||
if (status === "error") {
|
||||
console.error("Error al cargar cabecera.html:", xhr.status, xhr.statusText);
|
||||
} else {
|
||||
comprobarSesion();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Función auxiliar para escapar texto HTML
|
||||
function escapeHTML(str) {
|
||||
return $("<div>")
|
||||
.text(str ?? "")
|
||||
.html();
|
||||
return $("<div>").text(str ?? "").html();
|
||||
}
|
||||
|
||||
// Comprobar estado de sesión al cargar la página
|
||||
@@ -16,83 +21,75 @@ function comprobarSesion() {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
dataType: "json",
|
||||
data: { orden: "comprobarSesion" },
|
||||
}).done(function (respuesta) {
|
||||
try {
|
||||
if (typeof respuesta === "string") {
|
||||
respuesta = JSON.parse(respuesta);
|
||||
}
|
||||
})
|
||||
.done(function (respuesta) {
|
||||
const contenedor = $("#contenedorUsuarioCabecera");
|
||||
if (!contenedor.length) return; // Si aún no existe el contenedor en HTML, cancelamos
|
||||
|
||||
const contenedor = $("#contenedorUsuarioCabecera");
|
||||
contenedor.empty();
|
||||
contenedor.empty();
|
||||
|
||||
if (respuesta.activa && respuesta.usuario) {
|
||||
// Recogemos el idUsuario de la sesion en una variable para usarlo (no me lo volváis a borrar por favor os lo pido)
|
||||
idUsuarioSesion = respuesta.usuario.idUsuario;
|
||||
// Obtenemos la ruta del avatar o la de por defecto
|
||||
const avatarUrl =
|
||||
respuesta.usuario.avatar || "img/avatars/defaultProfile.jpeg";
|
||||
if (respuesta && respuesta.activa && respuesta.usuario) {
|
||||
// Guardar idUsuario globalmente
|
||||
idUsuarioSesion = respuesta.usuario.idUsuario;
|
||||
const avatarUrl = respuesta.usuario.avatar || "img/avatars/defaultProfile.jpeg";
|
||||
|
||||
// Usuario autenticado: Mostrar Menú Dropdown con el avatar
|
||||
const htmlUsuario = `
|
||||
<div class="dropdown">
|
||||
<button class="btn user-dropdown-btn dropdown-toggle d-flex align-items-center gap-2"
|
||||
type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<img src="${escapeHTML(avatarUrl)}" alt="Avatar" class="rounded-circle" style="width: 32px; height: 32px; object-fit: cover;">
|
||||
<span>${escapeHTML(respuesta.usuario.nombreUsuario)}</span>
|
||||
</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">
|
||||
<i class="fa-solid fa-user text-primary"></i> Perfil
|
||||
</a>
|
||||
</li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a class="dropdown-item logout-item d-flex align-items-center gap-2" href="#" id="botonCerrarSesion">
|
||||
<i class="fa-solid fa-right-from-bracket"></i> Cerrar Sesión
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
`;
|
||||
contenedor.html(htmlUsuario);
|
||||
|
||||
// Si estamos en la página principal, mostramos el botón JUGAR
|
||||
if ($("#colBotonJugar").length) {
|
||||
$("#colBotonJugar").removeClass("d-none");
|
||||
$("#colRanking")
|
||||
.removeClass("col-lg-8")
|
||||
.addClass("col-lg-7 col-xl-8");
|
||||
}
|
||||
} else {
|
||||
// No hay sesión: Mostrar botones de Login y Registro
|
||||
const htmlInvitado = `
|
||||
<button type="button" class="btn btn-kahoot-login rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
||||
<i class="fa-solid fa-right-to-bracket me-1"></i> Iniciar Sesión
|
||||
// Usuario autenticado: Menú desplegable
|
||||
const htmlUsuario = `
|
||||
<div class="dropdown">
|
||||
<button class="btn user-dropdown-btn dropdown-toggle d-flex align-items-center gap-2"
|
||||
type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<img src="${escapeHTML(avatarUrl)}" alt="Avatar" class="rounded-circle" style="width: 32px; height: 32px; object-fit: cover;">
|
||||
<span>${escapeHTML(respuesta.usuario.nombreUsuario)}</span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-kahoot-register rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalRegistro">
|
||||
<i class="fa-solid fa-user-plus me-1"></i> Registrarse
|
||||
</button>
|
||||
`;
|
||||
contenedor.html(htmlInvitado);
|
||||
<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">
|
||||
<i class="fa-solid fa-user text-primary"></i> Perfil
|
||||
</a>
|
||||
</li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a class="dropdown-item logout-item d-flex align-items-center gap-2" href="#" id="botonCerrarSesion">
|
||||
<i class="fa-solid fa-right-from-bracket"></i> Cerrar Sesión
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
`;
|
||||
contenedor.html(htmlUsuario);
|
||||
|
||||
// Si estamos en la página principal, ocultamos el botón JUGAR
|
||||
if ($("#colBotonJugar").length) {
|
||||
$("#colBotonJugar").addClass("d-none");
|
||||
$("#colRanking")
|
||||
.removeClass("col-lg-7 col-xl-8")
|
||||
.addClass("col-lg-8");
|
||||
}
|
||||
// Si estamos en la página principal, mostramos el botón JUGAR
|
||||
if ($("#colBotonJugar").length) {
|
||||
$("#colBotonJugar").removeClass("d-none");
|
||||
$("#colRanking").removeClass("col-lg-8").addClass("col-lg-7 col-xl-8");
|
||||
}
|
||||
} else {
|
||||
// No hay sesión: Botones de Login y Registro
|
||||
const htmlInvitado = `
|
||||
<button type="button" class="btn btn-kahoot-login rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
||||
<i class="fa-solid fa-right-to-bracket me-1"></i> Iniciar Sesión
|
||||
</button>
|
||||
<button type="button" class="btn btn-kahoot-register rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalRegistro">
|
||||
<i class="fa-solid fa-user-plus me-1"></i> Registrarse
|
||||
</button>
|
||||
`;
|
||||
contenedor.html(htmlInvitado);
|
||||
|
||||
if ($("#colBotonJugar").length) {
|
||||
$("#colBotonJugar").addClass("d-none");
|
||||
$("#colRanking").removeClass("col-lg-7 col-xl-8").addClass("col-lg-8");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error al procesar la respuesta de la sesión:", e);
|
||||
}
|
||||
})
|
||||
.fail(function (xhr, status, error) {
|
||||
console.error("Error en comprobarSesion AJAX:", error, xhr.responseText);
|
||||
});
|
||||
}
|
||||
|
||||
// Registro
|
||||
$("#formRegistro").on("submit", function (event) {
|
||||
// Registro de usuario
|
||||
$(document).on("click", "#botonAceptarRegistro", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let nombreUsuario = $("#regNombre").val().trim();
|
||||
@@ -100,61 +97,64 @@ $("#formRegistro").on("submit", function (event) {
|
||||
let contrasena = $("#regPassword").val();
|
||||
let contrasenaConfirmacion = $("#regPasswordConfirm").val();
|
||||
|
||||
$("#regNombre").removeClass("is-invalid");
|
||||
$("#regEmail").removeClass("is-invalid");
|
||||
$("#regPassword").removeClass("is-invalid");
|
||||
$("#regPasswordConfirm").removeClass("is-invalid");
|
||||
$("#errorRegistro").text("");
|
||||
// Resetear estados visuales
|
||||
$("#regNombre, #regEmail, #regPassword, #regPasswordConfirm").removeClass("is-invalid");
|
||||
$("#errorRegistro").removeClass("text-danger text-success").text("").show();
|
||||
|
||||
if (contrasena !== contrasenaConfirmacion) {
|
||||
$("#regPassword").addClass("is-invalid");
|
||||
$("#regPasswordConfirm").addClass("is-invalid");
|
||||
$("#errorRegistro").text("Las contraseñas no coinciden.");
|
||||
$("#regPassword, #regPasswordConfirm").addClass("is-invalid");
|
||||
$("#errorRegistro").addClass("text-danger").text("Las contraseñas no coinciden.");
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
dataType: "json",
|
||||
data: {
|
||||
nombreUsuario: nombreUsuario,
|
||||
email: email,
|
||||
contrasena: contrasena,
|
||||
orden: "registrarUsuario",
|
||||
},
|
||||
}).done(function (respuesta) {
|
||||
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||
|
||||
})
|
||||
.done(function (respuesta) {
|
||||
if (respuesta.error) {
|
||||
$("#errorRegistro").text(respuesta.error);
|
||||
$("#regNombre").addClass("is-invalid");
|
||||
$("#regEmail").addClass("is-invalid");
|
||||
$("#errorRegistro").addClass("text-danger").text(respuesta.error);
|
||||
$("#regNombre, #regEmail").addClass("is-invalid");
|
||||
} else {
|
||||
// Mostrar mensaje de confirmación
|
||||
$("#errorRegistro")
|
||||
.removeClass("text-danger")
|
||||
.addClass("text-success")
|
||||
.text(respuesta.exito);
|
||||
.addClass("text-success fw-bold")
|
||||
.text(respuesta.exito || "¡Registro completado con éxito!");
|
||||
|
||||
$("#formRegistro")[0].reset();
|
||||
if ($("#formRegistro").length) {
|
||||
$("#formRegistro")[0].reset();
|
||||
}
|
||||
|
||||
// Recargar para iniciar sesión tras 1.5 segundos
|
||||
setTimeout(function () {
|
||||
location.reload();
|
||||
}, 1000);
|
||||
}, 1500);
|
||||
}
|
||||
})
|
||||
.fail(function (xhr, status, error) {
|
||||
console.error("Error en el registro:", error, xhr.responseText);
|
||||
$("#errorRegistro").addClass("text-danger").text("Error de conexión con el servidor.");
|
||||
});
|
||||
});
|
||||
|
||||
// Login
|
||||
$("#botonAceptarLogin").click(function (event) {
|
||||
// Login de usuario
|
||||
$(document).on("click", "#botonAceptarLogin", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let email = $("#loginEmail").val().trim();
|
||||
let contrasena = $("#loginPassword").val();
|
||||
let recuerdame = $("#recordar").is(":checked");
|
||||
|
||||
$("#loginEmail").removeClass("is-invalid");
|
||||
$("#loginPassword").removeClass("is-invalid");
|
||||
$("#errorLogin").text("");
|
||||
$("#loginEmail, #loginPassword").removeClass("is-invalid");
|
||||
$("#errorLogin").removeClass("text-success").addClass("text-danger").text("").show();
|
||||
|
||||
if (email === "" || contrasena === "") {
|
||||
$("#errorLogin").text("Todos los campos son obligatorios.");
|
||||
@@ -166,41 +166,43 @@ $("#botonAceptarLogin").click(function (event) {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
dataType: "json",
|
||||
data: {
|
||||
email: email,
|
||||
contrasena: contrasena,
|
||||
recuerdame: recuerdame,
|
||||
orden: "comprobarUsuario",
|
||||
},
|
||||
}).done(function (respuesta) {
|
||||
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||
|
||||
})
|
||||
.done(function (respuesta) {
|
||||
if (respuesta.error) {
|
||||
$("#loginEmail").addClass("is-invalid");
|
||||
$("#loginPassword").addClass("is-invalid");
|
||||
$("#loginEmail, #loginPassword").addClass("is-invalid");
|
||||
$("#errorLogin").text(respuesta.error);
|
||||
} else {
|
||||
// Login correcto: Recargar la vista
|
||||
location.reload();
|
||||
}
|
||||
})
|
||||
.fail(function (xhr, status, error) {
|
||||
console.error("Error en el login:", error, xhr.responseText);
|
||||
$("#errorLogin").text("Error de conexión o respuesta no válida del servidor.");
|
||||
});
|
||||
});
|
||||
|
||||
// Cerrar sesión
|
||||
// Cerrar sesión
|
||||
$(document).on("click", "#botonCerrarSesion", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
dataType: "json",
|
||||
data: { orden: "cerrarSesion" },
|
||||
}).done(function (respuesta) {
|
||||
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||
|
||||
if (respuesta.error) {
|
||||
console.log(respuesta.error);
|
||||
} else {
|
||||
window.location.href = "index.php";
|
||||
}
|
||||
})
|
||||
.done(function (respuesta) {
|
||||
window.location.href = "index.php";
|
||||
})
|
||||
.fail(function () {
|
||||
window.location.href = "index.php";
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+6
-6
@@ -50,10 +50,9 @@ function cambiarNombre() {
|
||||
$("#nuevoNombre").val("");
|
||||
|
||||
|
||||
if (typeof comprobarEstadoSesion === "function") {
|
||||
comprobarEstadoSesion();
|
||||
}
|
||||
comprobarSesion();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,6 +70,7 @@ function borrarNombre() {
|
||||
|
||||
function seleccionarFoto() {
|
||||
$("#inputFoto").click();
|
||||
|
||||
}
|
||||
|
||||
$("#inputFoto").change(function () {
|
||||
@@ -79,6 +79,7 @@ $("#inputFoto").change(function () {
|
||||
if (!archivo) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Comprobamos que sea una imagen
|
||||
if (!archivo.type.startsWith("image/")) {
|
||||
@@ -110,9 +111,8 @@ $("#inputFoto").change(function () {
|
||||
);
|
||||
|
||||
// Actualizamos también el avatar superior en la cabecera
|
||||
if (typeof comprobarEstadoSesion === "function") {
|
||||
comprobarEstadoSesion();
|
||||
}
|
||||
|
||||
comprobarSesion();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+2
-2
@@ -41,7 +41,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
||||
|
||||
<body>
|
||||
|
||||
<?php include_once 'cabecera.php'; ?>
|
||||
<header id="cabecera-container"></header>
|
||||
|
||||
<div class="perfil-container">
|
||||
|
||||
@@ -310,7 +310,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
||||
|
||||
<!-- Tu JavaScript -->
|
||||
<script src="js/perfil.js"></script>
|
||||
|
||||
<script src="js/cabecera.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user