Merge branch 'cookies'

This commit is contained in:
2026-09-29 13:35:39 +02:00
9 changed files with 376 additions and 3463 deletions
+71 -16
View File
@@ -269,6 +269,60 @@ class Usuario
return null;
}
// Cookies
public static function guardarCookieToken($idUsuario, $token)
{
$conexion = conexionBD();
if (is_array($conexion)) return false;
try {
$sql = "UPDATE usuario SET cookie = :token WHERE idUsuario = :id";
$stmt = $conexion->prepare($sql);
return $stmt->execute([
':token' => $token,
':id' => $idUsuario
]);
} catch (PDOException $e) {
return false;
}
}
public static function buscarPorCookie($token)
{
if (empty($token)) return null;
$conexion = conexionBD();
if (is_array($conexion)) return null;
try {
$sql = "SELECT * FROM usuario WHERE cookie = :token AND cookie IS NOT NULL";
$stmt = $conexion->prepare($sql);
$stmt->execute([':token' => $token]);
$datos = $stmt->fetch(PDO::FETCH_ASSOC);
if ($datos) {
return new Usuario(
$datos['nombreUsuario'],
$datos['contrasena'],
$datos['email'],
$datos['avatar'],
$datos['cookie'],
(int)$datos['aciertos'],
(int)$datos['victorias'],
(int)$datos['derrotas'],
(int)$datos['idUsuario']
);
}
return null;
} catch (PDOException $e) {
return null;
}
}
public function cambiarNombre($nuevoNombre)
{
$conexion = conexionBD();
@@ -384,16 +438,17 @@ class Usuario
}
}
public static function obtenerRanking($limite = 10) {
try {
$conexion = conexionBD();
public static function obtenerRanking($limite = 10)
{
try {
$conexion = conexionBD();
if (is_array($conexion)) {
return [];
}
if (is_array($conexion)) {
return [];
}
$sql = "SELECT
$sql = "SELECT
idUsuario,
nombreUsuario,
avatar,
@@ -408,12 +463,12 @@ class Usuario
FROM usuario
ORDER BY victorias DESC, aciertos DESC
LIMIT " . (int)$limite;
$stmt = $conexion->prepare($sql);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
return [];
$stmt = $conexion->prepare($sql);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
return [];
}
}
}
}
}