Skip to content

Commit

Permalink
Merge branch 'lucia-final-master-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
spariva committed Jun 14, 2024
2 parents 0e0ddfa + e08a000 commit 7b6605b
Show file tree
Hide file tree
Showing 42 changed files with 1,327 additions and 1,868 deletions.
10 changes: 0 additions & 10 deletions config/config.php

This file was deleted.

9 changes: 7 additions & 2 deletions config/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
Dotenv\Dotenv::createImmutable(dirname(__DIR__))->load();
if ($_ENV['TEST'] === false) {
throw new Exception("Environment variables not loaded");
} else if ($_ENV['APP_ENV'] === 'local') {
error_reporting(E_ALL);
ini_set('display_errors', 1);
} else {
error_reporting(0);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
}

session_start();

define('DOC_ROOT', dirname(__DIR__));

require DOC_ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';

spl_autoload_register(function ($class) {
$file = str_replace("\\", DIRECTORY_SEPARATOR, $class);
$path = DOC_ROOT . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR . "php" . DIRECTORY_SEPARATOR . $file . ".php";
Expand Down
1 change: 1 addition & 0 deletions db/create_db.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP TABLE IF EXISTS api_tokens;
DROP TABLE IF EXISTS rating;
DROP TABLE IF EXISTS tokens;
DROP TABLE IF EXISTS playlist;
Expand Down
42 changes: 12 additions & 30 deletions public/acceptFriend.php
Original file line number Diff line number Diff line change
@@ -1,79 +1,61 @@
<?php

require_once '../config/init.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$friend = $_POST['friend'];
$friend = $_POST['friend'];
$aceptar = $_POST['aceptar'];
$rechazar = $_POST['rechazar'];
echo 'paso 0';


if (empty($username) || empty($friend)) {

header("Location: ./usuario.php?mensaje=El usuario introducido no existe");
echo 'error';

header("Location: ./usuario.php?mensaje=El usuario introducido no existe");
exit();
}

if($aceptar != null) {
// Código para aceptar la solicitud de amistad
if ($aceptar != null) {
$db = DbConnection::getInstance()->getConnection();
echo 'empezamos conexion';

$stmt = $db->prepare("INSERT INTO friends (USER_NAME, FRIEND_NAME) VALUES (:username, :friend)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':friend', $friend);
$result1 = $stmt->execute();
echo 'paso 1';


$stmt = $db->prepare("INSERT INTO friends (USER_NAME, FRIEND_NAME) VALUES (:friend, :username)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':friend', $friend);
$result2 = $stmt->execute();
echo 'paso 2';


$stmt = $db->prepare("DELETE FROM requests WHERE REQUEST_USER = :friend AND REQUESTED_USER = :username");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':friend', $friend);
$result3 = $stmt->execute();
echo 'paso 3';


$result = $result1 && $result2 && $result3; // Ambas consultas deben ser exitosas
header("Location: ./usuario.php?mensaje=Ahora sois amigos :)");
exit();

} elseif($rechazar != null) {
echo 'empezamos conexion rechazar';
// Código para rechazar la solicitud de amistad
} elseif ($rechazar != null) {
$db = DbConnection::getInstance()->getConnection();

echo "DELETE FROM requests WHERE REQUEST_USER = " . $username . " AND REQUESTED_USER = " . $friend . "";


$stmt = $db->prepare("DELETE FROM requests WHERE REQUEST_USER = :friend AND REQUESTED_USER = :username");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':friend', $friend);
$result4 = $stmt->execute();

//header("Location: ./usuario.php?mensaje=Solicitud rechazada");
header("Location: ./usuario.php?mensaje=DELETE FROM requests WHERE REQUEST_USER = " . $username . " AND REQUESTED_USER = " . $friend);
header("Location: ./usuario.php?mensaje=Solicitud rechazada");
exit();

}

echo 'El usuario introducido no existe o ya ha sido añadido';



if ($result) {

header("Location: ./usuario.php?mensaje=Ahora sois amigos :)");
exit();
} else {
echo "Error: " . $stmt->errorInfo()[2];
header("Location: ./usuario.php?mensaje=Hubo un problema, vuelve a intentarlo :(");
exit();
}
}
21 changes: 8 additions & 13 deletions public/anadirPlaylist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,23 @@
$url = $_POST['urlPlaylist'];
$username = $_POST['username'];

// Extract the URL between src=" and "
//preg_match('/src="([^"]*)"/', $url, $matches);
//$url = $matches[1] ?? '';

echo 'Esta playlist ya ha sido añadida por otro usuario.';

try{
try {
$db = DbConnection::getInstance()->getConnection();
$stmt = $db->prepare("INSERT INTO playlist VALUES (?, ?)");
$result = $stmt->execute([$url, $username]);

if ($result) {
// Redirect to index.php on success
header("Location: ./index.php?playlist=".$url."&mensaje=Playlist añadida correctamente");
header("Location: ./index.php?mensaje=Playlist añadida correctamente");
exit();
} else {
// Echo error message on failure
header("Location: ./index.php?playlist=".$url."&error=Esta playlist ya ha sido añadida por otro usuario");
echo "Error: " . $stmt->errorInfo()[2];
header("Location: ./index.php?playlist=" . $url . "&mensaje=Esta playlist ya ha sido añadida por otro usuario :(");
exit();
}
}catch(error){
echo "Error: " . $error;
} catch (Exception $error) {
header("Location: ./index.php?playlist=" . $url . "&mensaje=Esta playlist ya ha sido añadida por otro usuario :(");
exit();
}
header("Location: ./index.php?playlist=".$url."&error=Esta playlist ya ha sido añadida por otro usuario");

Expand Down
Loading

0 comments on commit 7b6605b

Please sign in to comment.