Merge branch 'pruebasJorge'
This commit is contained in:
+135
-243
@@ -4,6 +4,7 @@ $(document).ready(function () {
|
||||
comprobarSalaUsuario();
|
||||
});
|
||||
|
||||
// 1. Comprobar si el usuario actual ya pertenece a una sala
|
||||
function comprobarSalaUsuario() {
|
||||
$("#cargandoSalas").remove();
|
||||
|
||||
@@ -11,101 +12,64 @@ function comprobarSalaUsuario() {
|
||||
url: "controladores/ControladorEquipoxUsuario.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "obtenerSalaUsuario",
|
||||
},
|
||||
|
||||
data: { orden: "obtenerSalaUsuario" },
|
||||
success: function (respuesta) {
|
||||
console.log("Sala del usuario:", respuesta);
|
||||
|
||||
if (respuesta.error) {
|
||||
console.error(respuesta.error);
|
||||
|
||||
if (respuesta.error || !respuesta.asociado) {
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
|
||||
$("#contenedorCrearSala").show();
|
||||
cargarSalas();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (respuesta.asociado) {
|
||||
usuarioYaEstaEnEquipo = true;
|
||||
|
||||
$("#contenedorCrearSala").hide();
|
||||
|
||||
cargarSalaUsuario(respuesta.idPartida);
|
||||
} else {
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
|
||||
cargarSalas();
|
||||
usuarioYaEstaEnEquipo = true;
|
||||
$("#contenedorCrearSala").hide(); // Ocultar "Crear Sala" si ya pertenece a una
|
||||
cargarSalaUsuario(respuesta.idPartida);
|
||||
}
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al comprobar la sala del usuario:", error);
|
||||
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
|
||||
cargarSalas();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Cargar únicamente la sala en la que está metido el usuario
|
||||
function cargarSalaUsuario(idPartida) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "buscar",
|
||||
idPartida: idPartida,
|
||||
},
|
||||
|
||||
data: { orden: "buscar", idPartida: idPartida },
|
||||
success: function (partida) {
|
||||
if (partida.error) {
|
||||
console.error(partida.error);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$("#contenedorSalas").empty();
|
||||
|
||||
cargarInformacionSala(partida);
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener la sala del usuario:", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 3. Cargar la lista completa de todas las salas
|
||||
function cargarSalas() {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "listar",
|
||||
},
|
||||
|
||||
data: { orden: "listar" },
|
||||
success: function (partidas) {
|
||||
const contenedor = $("#contenedorSalas");
|
||||
|
||||
contenedor.empty();
|
||||
contenedor.empty();
|
||||
|
||||
if (!Array.isArray(partidas) || partidas.length === 0) {
|
||||
contenedor.html(`
|
||||
<div class="col-12 text-center">
|
||||
<p class="text-muted">
|
||||
No hay salas disponibles.
|
||||
</p>
|
||||
</div>
|
||||
`);
|
||||
|
||||
<div class="col-12 text-center">
|
||||
<p class="text-muted">No hay salas disponibles actualmente.</p>
|
||||
</div>
|
||||
`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,54 +77,42 @@ function cargarSalas() {
|
||||
cargarInformacionSala(partida);
|
||||
});
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener las partidas:", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 4. Obtener equipos y jugadores asociados a una sala concreta
|
||||
function cargarInformacionSala(partida) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "getEquipos",
|
||||
idPartida: partida.idPartida,
|
||||
},
|
||||
|
||||
data: { orden: "getEquipos", idPartida: partida.idPartida },
|
||||
success: function (equipos) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "getJugadores",
|
||||
idPartida: partida.idPartida,
|
||||
},
|
||||
|
||||
data: { orden: "getJugadores", idPartida: partida.idPartida },
|
||||
success: function (jugadores) {
|
||||
mostrarSala(partida, equipos, jugadores);
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener jugadores:", error);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener equipos:", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 5. Renderizar el HTML de la sala y botones según estado
|
||||
function mostrarSala(partida, equipos, jugadores) {
|
||||
const contenedor = $("#contenedorSalas");
|
||||
|
||||
let equiposHTML = "";
|
||||
|
||||
equipos.forEach(function (equipo) {
|
||||
@@ -168,230 +120,195 @@ function mostrarSala(partida, equipos, jugadores) {
|
||||
return jugador.idEquipo == equipo.idEquipo;
|
||||
});
|
||||
|
||||
let jugadoresHTML = "";
|
||||
|
||||
let jugadoresHTML = "";
|
||||
if (jugadoresEquipo.length > 0) {
|
||||
jugadoresEquipo.forEach(function (jugador) {
|
||||
jugadoresHTML += `
|
||||
<div class="jugador">
|
||||
|
||||
<span class="avatar">
|
||||
👤
|
||||
</span>
|
||||
|
||||
${escapeHTML(jugador.nombreUsuario)}
|
||||
|
||||
</div>
|
||||
`;
|
||||
<div class="jugador">
|
||||
<span class="avatar">👤</span>
|
||||
${escapeHTML(jugador.nombreUsuario)}
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
} else {
|
||||
jugadoresHTML = `
|
||||
<div class="text-muted small">
|
||||
Sin jugadores
|
||||
</div>
|
||||
`;
|
||||
jugadoresHTML = `<div class="text-muted small">Sin jugadores</div>`;
|
||||
}
|
||||
|
||||
let botonUnirseHTML = "";
|
||||
|
||||
// Botón "Unirse" solo visible si NO pertenece a ningún equipo
|
||||
let botonUnirseHTML = "";
|
||||
if (!usuarioYaEstaEnEquipo) {
|
||||
botonUnirseHTML = `
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-unirse w-100 btn-unirse-equipo"
|
||||
<button type="button" class="btn btn-unirse w-100 btn-unirse-equipo mt-2"
|
||||
data-id-partida="${partida.idPartida}"
|
||||
data-id-equipo="${equipo.idEquipo}">
|
||||
|
||||
Unirse
|
||||
|
||||
</button>
|
||||
`;
|
||||
Unirse
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
|
||||
equiposHTML += `
|
||||
<div class="equipo">
|
||||
|
||||
<h6>
|
||||
${escapeHTML(equipo.nombreEquipo)}
|
||||
</h6>
|
||||
|
||||
<div class="jugadores">
|
||||
|
||||
${jugadoresHTML}
|
||||
|
||||
</div>
|
||||
|
||||
${botonUnirseHTML}
|
||||
|
||||
<div class="equipo me-2 ms-2 p-3 border rounded">
|
||||
<h6>${escapeHTML(equipo.nombreEquipo)}</h6>
|
||||
<div class="jugadores mb-2">
|
||||
${jugadoresHTML}
|
||||
</div>
|
||||
${botonUnirseHTML}
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
||||
let accionesSalaHTML = "";
|
||||
if (usuarioYaEstaEnEquipo) {
|
||||
accionesSalaHTML = `
|
||||
<div class="sala-acciones text-center mt-4 pt-3 border-top d-flex justify-content-center gap-3">
|
||||
<button type="button" class="btn btn-outline-danger btn-abandonar-sala" data-id-partida="${partida.idPartida}">
|
||||
Abandonar sala
|
||||
</button>
|
||||
<a href="juego.php?idPartida=${partida.idPartida}" class="btn btn-success btn-lg px-4">
|
||||
🎮 ¡Iniciar Partida!
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
const salaHTML = `
|
||||
<div class="col-12 col-md-10 col-lg-8">
|
||||
|
||||
<div class="sala">
|
||||
|
||||
<div class="sala-header">
|
||||
|
||||
${escapeHTML(partida.nombrePartida)}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="sala-body">
|
||||
|
||||
<div class="equipos">
|
||||
|
||||
${equiposHTML}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sala card p-3 shadow-sm mb-4">
|
||||
<div class="sala-header h4 text-center mb-3">
|
||||
${escapeHTML(partida.nombrePartida)}
|
||||
</div>
|
||||
|
||||
<div class="sala-body">
|
||||
<div class="equipos d-flex justify-content-around">
|
||||
${equiposHTML}
|
||||
</div>
|
||||
${accionesSalaHTML}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
`;
|
||||
|
||||
contenedor.append(salaHTML);
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// UNIRSE A UN EQUIPO
|
||||
// ======================================================
|
||||
|
||||
// 6. Evento: Unirse a un Equipo
|
||||
$(document).on("click", ".btn-unirse-equipo", function () {
|
||||
const boton = $(this);
|
||||
|
||||
const idEquipo = boton.data("id-equipo");
|
||||
|
||||
const idPartida = boton.data("id-partida");
|
||||
|
||||
boton.prop("disabled", true);
|
||||
|
||||
boton.text("Uniéndose...");
|
||||
boton.prop("disabled", true).text("Uniéndose...");
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/ControladorEquipoxUsuario.php",
|
||||
|
||||
type: "POST",
|
||||
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "registrarUsuarioEnEquipo",
|
||||
idEquipo: idEquipo,
|
||||
},
|
||||
|
||||
success: function (respuesta) {
|
||||
console.log("Respuesta al unirse:", respuesta);
|
||||
|
||||
if (respuesta.error) {
|
||||
alert(respuesta.error);
|
||||
|
||||
boton.prop("disabled", false);
|
||||
|
||||
boton.text("Unirse");
|
||||
|
||||
boton.prop("disabled", false).text("Unirse");
|
||||
return;
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// UNIÓN CORRECTA
|
||||
// ==========================================
|
||||
|
||||
usuarioYaEstaEnEquipo = true;
|
||||
|
||||
// Ocultamos el botón "Crear sala"
|
||||
|
||||
$("#contenedorCrearSala").hide();
|
||||
|
||||
// Eliminamos las salas actuales
|
||||
|
||||
$("#contenedorSalas").empty();
|
||||
|
||||
// Cargamos directamente la sala
|
||||
// donde acaba de entrar el usuario
|
||||
|
||||
cargarSalaUsuario(idPartida);
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al unirse al equipo:", error);
|
||||
|
||||
console.error("Respuesta del servidor:", xhr.responseText);
|
||||
|
||||
alert("No se ha podido unir al equipo.");
|
||||
|
||||
boton.prop("disabled", false);
|
||||
|
||||
boton.text("Unirse");
|
||||
boton.prop("disabled", false).text("Unirse");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
// ESCAPAR HTML
|
||||
// ======================================================
|
||||
// 7. Evento: Abandonar Sala
|
||||
// Guardamos temporalmente el botón presionado
|
||||
let botonAbandonarReferencia = null;
|
||||
|
||||
function escapeHTML(texto) {
|
||||
return $("<div>")
|
||||
.text(texto ?? "")
|
||||
.html();
|
||||
}
|
||||
// A. Al hacer clic en el botón "Abandonar sala" de la tarjeta, abrimos el modal
|
||||
$(document).on("click", ".btn-abandonar-sala", function () {
|
||||
botonAbandonarReferencia = $(this);
|
||||
const modal = new bootstrap.Modal(document.getElementById('modalAbandonarSala'));
|
||||
modal.show();
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
// CREAR SALA
|
||||
// ======================================================
|
||||
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
||||
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||
const modalEl = document.getElementById('modalAbandonarSala');
|
||||
const modalInstance = bootstrap.Modal.getInstance(modalEl);
|
||||
|
||||
const btnConfirmar = $(this);
|
||||
btnConfirmar.prop("disabled", true).text("Saliendo...");
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/ControladorEquipoxUsuario.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { orden: "salirDeSala" },
|
||||
success: function (respuesta) {
|
||||
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||
|
||||
if (modalInstance) {
|
||||
modalInstance.hide();
|
||||
}
|
||||
|
||||
if (respuesta.error) {
|
||||
alert(respuesta.error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Restablecemos la interfaz a la lista completa de salas
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
$("#contenedorCrearSala").show();
|
||||
cargarSalas();
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al salir de la sala:", error);
|
||||
alert("No se pudo salir de la sala.");
|
||||
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||
if (modalInstance) {
|
||||
modalInstance.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
// 8. Evento: Crear Sala
|
||||
$("#btnCrearSala").on("click", function () {
|
||||
const nombreSala = $("#nombreSala").val().trim();
|
||||
|
||||
const nombreEquipo1 = $("#nombreEquipo1").val().trim();
|
||||
|
||||
const nombreEquipo2 = $("#nombreEquipo2").val().trim();
|
||||
|
||||
let valido = true;
|
||||
|
||||
$(".mensaje-error-sala").remove();
|
||||
|
||||
$(".input-kahoot").removeClass("is-invalid");
|
||||
|
||||
if (nombreSala === "") {
|
||||
mostrarError("#nombreSala", "El nombre de la sala es obligatorio.");
|
||||
|
||||
valido = false;
|
||||
} else if (nombreSala.length < 3) {
|
||||
if (nombreSala === "" || nombreSala.length < 3) {
|
||||
mostrarError(
|
||||
"#nombreSala",
|
||||
"El nombre de la sala debe tener al menos 3 caracteres.",
|
||||
);
|
||||
|
||||
valido = false;
|
||||
}
|
||||
|
||||
if (nombreEquipo1 === "") {
|
||||
mostrarError("#nombreEquipo1", "El nombre del equipo 1 es obligatorio.");
|
||||
|
||||
valido = false;
|
||||
} else if (nombreEquipo1.length < 2) {
|
||||
if (nombreEquipo1 === "" || nombreEquipo1.length < 2) {
|
||||
mostrarError(
|
||||
"#nombreEquipo1",
|
||||
"El nombre del equipo debe tener al menos 2 caracteres.",
|
||||
);
|
||||
|
||||
valido = false;
|
||||
}
|
||||
|
||||
if (nombreEquipo2 === "") {
|
||||
mostrarError("#nombreEquipo2", "El nombre del equipo 2 es obligatorio.");
|
||||
|
||||
valido = false;
|
||||
} else if (nombreEquipo2.length < 2) {
|
||||
if (nombreEquipo2 === "" || nombreEquipo2.length < 2) {
|
||||
mostrarError(
|
||||
"#nombreEquipo2",
|
||||
"El nombre del equipo debe tener al menos 2 caracteres.",
|
||||
);
|
||||
|
||||
valido = false;
|
||||
}
|
||||
|
||||
@@ -404,22 +321,16 @@ $("#btnCrearSala").on("click", function () {
|
||||
"#nombreEquipo2",
|
||||
"Los dos equipos deben tener nombres diferentes.",
|
||||
);
|
||||
|
||||
valido = false;
|
||||
}
|
||||
|
||||
if (!valido) {
|
||||
return;
|
||||
}
|
||||
if (!valido) return;
|
||||
|
||||
// Deshabilitamos el botón mientras se crea la sala
|
||||
const boton = $("#btnCrearSala");
|
||||
|
||||
boton.prop("disabled", true);
|
||||
boton.text("Creando sala...");
|
||||
boton.prop("disabled", true).text("Creando sala...");
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php", // <-- cambia esto por la ruta de tu controlador
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: {
|
||||
@@ -428,16 +339,10 @@ $("#btnCrearSala").on("click", function () {
|
||||
nombreEquipo1: nombreEquipo1,
|
||||
nombreEquipo2: nombreEquipo2,
|
||||
},
|
||||
|
||||
success: function (respuesta) {
|
||||
console.log("Respuesta del servidor:", respuesta);
|
||||
|
||||
if (respuesta.error) {
|
||||
alert(respuesta.error);
|
||||
|
||||
boton.prop("disabled", false);
|
||||
boton.text("Crear sala");
|
||||
|
||||
boton.prop("disabled", false).text("Crear sala");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -446,43 +351,30 @@ $("#btnCrearSala").on("click", function () {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al crear la sala:", error);
|
||||
console.error("Respuesta:", xhr.responseText);
|
||||
|
||||
alert("No se ha podido crear la sala.");
|
||||
|
||||
boton.prop("disabled", false);
|
||||
boton.text("Crear sala");
|
||||
boton.prop("disabled", false).text("Crear sala");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
// MOSTRAR ERROR
|
||||
// ======================================================
|
||||
// Auxiliares
|
||||
function escapeHTML(texto) {
|
||||
return $("<div>")
|
||||
.text(texto ?? "")
|
||||
.html();
|
||||
}
|
||||
|
||||
function mostrarError(selector, mensaje) {
|
||||
const input = $(selector);
|
||||
|
||||
input.addClass("is-invalid");
|
||||
|
||||
input.after(`
|
||||
<div class="mensaje-error-sala text-danger mt-1 small">
|
||||
|
||||
${mensaje}
|
||||
|
||||
</div>
|
||||
`);
|
||||
input.after(
|
||||
`<div class="mensaje-error-sala text-danger mt-1 small">${mensaje}</div>`,
|
||||
);
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// QUITAR ERROR AL ESCRIBIR
|
||||
// ======================================================
|
||||
|
||||
$(".input-kahoot").on("input", function () {
|
||||
$(document).on("input", ".input-kahoot", function () {
|
||||
$(this).removeClass("is-invalid");
|
||||
|
||||
$(this).next(".mensaje-error-sala").remove();
|
||||
});
|
||||
|
||||
+22
-46
@@ -1,13 +1,11 @@
|
||||
// Función de escape colocada arriba para evitar el ReferenceError
|
||||
function escapeHTML(str) {
|
||||
return $("<div>").text(str ?? "").html();
|
||||
}
|
||||
|
||||
// Comprobar estado de sesión al cargar la página
|
||||
$(document).ready(function () {
|
||||
comprobarSesion();
|
||||
});
|
||||
|
||||
// Función auxiliar para escapar texto HTML y evitar XSS
|
||||
function escapeHTML(str) {
|
||||
return $("<div>").text(str ?? "").html();
|
||||
}
|
||||
|
||||
// Comprobar estado de sesión al cargar la página
|
||||
function comprobarSesion() {
|
||||
@@ -20,12 +18,12 @@ function comprobarSesion() {
|
||||
if (typeof respuesta === "string") {
|
||||
respuesta = JSON.parse(respuesta);
|
||||
}
|
||||
|
||||
|
||||
const contenedor = $("#contenedorUsuarioCabecera");
|
||||
contenedor.empty();
|
||||
|
||||
if (respuesta.activa && respuesta.usuario) {
|
||||
// 1. Renderizar Menú de Usuario en la Cabecera
|
||||
// Usuario autenticado: Mostrar Menú Dropdown
|
||||
const htmlUsuario = `
|
||||
<div class="dropdown">
|
||||
<button class="btn user-dropdown-btn dropdown-toggle d-flex align-items-center gap-2"
|
||||
@@ -50,12 +48,14 @@ function comprobarSesion() {
|
||||
`;
|
||||
contenedor.html(htmlUsuario);
|
||||
|
||||
// 2. Muestra el botón JUGAR y ajusta columnas
|
||||
$("#colBotonJugar").removeClass("d-none");
|
||||
$("#colRanking").removeClass("col-lg-8").addClass("col-lg-7 col-xl-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 {
|
||||
// 1. Renderizar Botones de Invitado
|
||||
// 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
|
||||
@@ -66,9 +66,11 @@ function comprobarSesion() {
|
||||
`;
|
||||
contenedor.html(htmlInvitado);
|
||||
|
||||
// 2. Ocultar el botón JUGAR y expandir ranking
|
||||
$("#colBotonJugar").addClass("d-none");
|
||||
$("#colRanking").removeClass("col-lg-7 col-xl-8").addClass("col-lg-8");
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error al procesar la respuesta de la sesión:", e);
|
||||
@@ -76,9 +78,10 @@ function comprobarSesion() {
|
||||
});
|
||||
}
|
||||
|
||||
// Registro
|
||||
// Evento Registro
|
||||
$("#botonAceptarRegistro").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let nombreUsuario = $("#regNombre").val().trim();
|
||||
let email = $("#regEmail").val().trim();
|
||||
let contrasena = $("#regPassword").val();
|
||||
@@ -128,7 +131,7 @@ $("#botonAceptarRegistro").click(function (event) {
|
||||
});
|
||||
});
|
||||
|
||||
// Login
|
||||
// Evento Login
|
||||
$("#botonAceptarLogin").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -167,7 +170,7 @@ $("#botonAceptarLogin").click(function (event) {
|
||||
});
|
||||
});
|
||||
|
||||
// Cerrar sesión
|
||||
// Evento Cerrar sesión (usa delegación de eventos por crearse dinámicamente)
|
||||
$(document).on("click", "#botonCerrarSesion", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -256,31 +259,6 @@ $("#botonAceptarLogin").click(function (event) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
data: {
|
||||
email: email,
|
||||
contrasena: contrasena,
|
||||
orden: "comprobarUsuario",
|
||||
},
|
||||
}).done(function (respuesta) {
|
||||
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||
|
||||
if (respuesta.error) {
|
||||
$("#loginEmail").addClass("is-invalid");
|
||||
$("#loginPassword").addClass("is-invalid");
|
||||
$("#errorLogin").text(respuesta.error);
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Cerrar sesión (Usa delegación de eventos por si el botón se crea dinámicamente)
|
||||
$(document).on("click", "#botonCerrarSesion", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
@@ -294,6 +272,4 @@ $(document).on("click", "#botonCerrarSesion", function (event) {
|
||||
window.location.href = "index.php";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user