diff --git a/php/ajax/add-comment.php b/php/ajax/add-comment.php index a985aeb..18613c8 100644 --- a/php/ajax/add-comment.php +++ b/php/ajax/add-comment.php @@ -4,6 +4,7 @@ if (session_status() === PHP_SESSION_NONE) { } require_once "../model/CommentManager.php"; +require_once "../model/UserManager.php"; /** * Prüft, ob die Anfrage durch JavaScript per AJAX gesendet wurde. @@ -40,7 +41,6 @@ function sendCommentResponse( $additionalData ) ); - exit(); } @@ -162,13 +162,29 @@ try { $parentCommentId ); + $userManager = UserManager::getInstance(); + $user = $userManager->findUser($_SESSION["user_email"]); + + $authorName = $_SESSION["user_email"]; + + if ($user !== null) { + $vorname = trim($user["vorname"] ?? ""); + $nachname = trim($user["nachname"] ?? ""); + + $fullName = trim($vorname . " " . $nachname); + + if ($fullName !== "") { + $authorName = $fullName; + } + } + sendCommentResponse( true, "Der Kommentar wurde erfolgreich gespeichert.", $articleId, [ "commentId" => $commentId, - "author" => $_SESSION["user_email"], + "author" => $authorName, "content" => $content, "created" => date("Y-m-d H:i:s"), "parentCommentId" => $parentCommentId