55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
|
|
require_once __DIR__ . '/../model/Article.php';
|
|
require_once __DIR__ . '/../model/ArticleManager.php';
|
|
require_once __DIR__ . '/../../includes/csrf.php';
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
|
|
header("Location: ../../index.php");
|
|
exit();
|
|
}
|
|
|
|
// 2. Prüfen, ob eine gültige Artikel-ID übergeben wurde
|
|
if (isset($_GET["id"]) && !empty($_GET["id"])) {
|
|
$articleId = intval($_GET["id"]);
|
|
$userEmail = $_SESSION["user_email"];
|
|
|
|
if (!isset($_SESSION["user_email"]) || empty($_SESSION["user_email"])) {
|
|
$_SESSION["message"] = "unauthorized_access";
|
|
header("Location: ../../index.php?pfad=showArticle&id=" . $articleId);
|
|
exit();
|
|
}
|
|
|
|
// CSRF-Token prüfen, bevor der Like-Status verändert wird
|
|
if (!csrf_verify()) {
|
|
$_SESSION["message"] = "invalid_csrf_token";
|
|
header("Location: ../../index.php?pfad=showArticle&id=" . $articleId);
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$articleManager = ArticleManager::getInstance();
|
|
$articleManager->toggleLike($articleId, $userEmail);
|
|
|
|
header("Location: ../../index.php?pfad=showArticle&id=" . $articleId);
|
|
exit();
|
|
|
|
} catch (NotFoundException $e) {
|
|
$_SESSION["message"] = "missing_id";
|
|
header("Location: ../../index.php");
|
|
exit();
|
|
} catch (Exception $e) {
|
|
$_SESSION["message"] = "internal_error";
|
|
header("Location: ../../index.php");
|
|
exit();
|
|
}
|
|
} else {
|
|
$_SESSION["message"] = "missing_id";
|
|
header("Location: ../../index.php");
|
|
exit();
|
|
}
|
|
|
|
?>
|