From b818a962d532ded06a18f28d7d5d21d94dc69399 Mon Sep 17 00:00:00 2001
From: Jonas Leder <jonas.leder@jobrouter.com>
Date: Mon, 14 Mar 2022 15:38:13 +0100
Subject: [PATCH] reformat file and fix new comment function

---
 public/API/queries/comments.php | 40 ++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/public/API/queries/comments.php b/public/API/queries/comments.php
index cb3f33a..3b3d46b 100644
--- a/public/API/queries/comments.php
+++ b/public/API/queries/comments.php
@@ -15,7 +15,8 @@ $commentField = new ObjectType([
     ],
 ]);
 
-function comments($article, $conn) {
+function comments($article, $conn)
+{
     $response = [];
     $result = $conn->query("SELECT * FROM comments WHERE article='$article'");
     while ($row = $result->fetch_assoc()) {
@@ -29,37 +30,36 @@ function comments($article, $conn) {
         array_push($response, $commentElement);
     }
     return $response;
-
 }
 
-function newComment($conn, $article, $name, $email, $comment, $hCaptchaResponse) {
+function newComment($conn, $article, $name, $email, $comment, $hCaptchaResponse)
+{
     require "./lib/config.php";
     $data = array(
         'secret' => $secretkey,
         'response' => $hCaptchaResponse
     );
     $client = new Client();
-    
+
     $response = $client->post("https://hcaptcha.com/siteverify", [
         "form_params" => $data
     ]);
-    
+
     $responseData = json_decode($response->getBody());
-    if(! $responseData->success) {
+    if (!$responseData->success) {
         return "Failed to verify Captcha";
-
-        $article = $conn->escape_string($article);
-        $name = $conn->escape_string($name);
-        $email = $conn->escape_string($email);
-        $comment = $conn->escape_string($comment);
-    
-        $sql = "INSERT INTO comments (name, email, comment, article) VALUES ('$name', '$email', '$comment', '$article')";
-    
-        if ($conn->query($sql) === TRUE) {
-            return "OK";
-        } else {
-            return "Error: " . $sql . "<br>" . $conn->error;
-        }
     }
 
-}
\ No newline at end of file
+    $article = $conn->escape_string($article);
+    $name = $conn->escape_string($name);
+    $email = $conn->escape_string($email);
+    $comment = $conn->escape_string($comment);
+
+    $sql = "INSERT INTO comments (name, email, comment, article) VALUES ('$name', '$email', '$comment', '$article')";
+
+    if ($conn->query($sql) === TRUE) {
+        return "OK";
+    } else {
+        return "Error: " . $sql . "<br>" . $conn->error;
+    }
+}
-- 
GitLab