From 285438ea949b61bc205b5903d7ed7ba6d2b333fe Mon Sep 17 00:00:00 2001 From: Jonas Leder <git@jonasled.de> Date: Wed, 21 Jul 2021 17:28:29 +0200 Subject: [PATCH] fix comment pubish and use guzzle for web requests --- js/customElements/commentsDisplay.js | 1 - js/customElements/newComment.js | 2 +- public/API/composer.json | 3 ++- public/API/composer.lock | 4 ++-- public/API/getMail.php | 18 +++++++++--------- public/API/newComment.php | 17 ++++++++++------- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/js/customElements/commentsDisplay.js b/js/customElements/commentsDisplay.js index 91984cf..b165ebf 100644 --- a/js/customElements/commentsDisplay.js +++ b/js/customElements/commentsDisplay.js @@ -3,7 +3,6 @@ class commentsDisplay extends HTMLElement { super(); let path = window.location.pathname; let pageName = path.split("/").pop(); - pageName = pageName.split(".")[0] let xhr = new XMLHttpRequest(); xhr.onreadystatechange = () => { diff --git a/js/customElements/newComment.js b/js/customElements/newComment.js index bf92254..b150dd8 100644 --- a/js/customElements/newComment.js +++ b/js/customElements/newComment.js @@ -16,7 +16,7 @@ class newComment extends HTMLElement { <input type="text" id="email" name="email"><br><br> <label for="comment">Kommentar:</label><br> - <textarea name="commebodynt" id="comment"></textarea><br><br> + <textarea name="comment" id="comment"></textarea><br><br> <div class="h-captcha" data-theme="dark" data-sitekey="${sitekey}"></div><br> diff --git a/public/API/composer.json b/public/API/composer.json index 77abbce..35c133c 100644 --- a/public/API/composer.json +++ b/public/API/composer.json @@ -1,6 +1,7 @@ { "require": { "aws/aws-sdk-php": "^3.181", - "symforge/chilkat-php": "9.5.0.66" + "symforge/chilkat-php": "9.5.0.66", + "guzzlehttp/guzzle": "^7.0" } } diff --git a/public/API/composer.lock b/public/API/composer.lock index c61f148..a2b14da 100644 --- a/public/API/composer.lock +++ b/public/API/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f1824e693565797fc0614d71a8f79648", + "content-hash": "2183fbeff4a5ee254a85bd0ba5c86597", "packages": [ { "name": "aws/aws-sdk-php", @@ -670,5 +670,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" } diff --git a/public/API/getMail.php b/public/API/getMail.php index f10a90f..b2f438b 100644 --- a/public/API/getMail.php +++ b/public/API/getMail.php @@ -1,20 +1,20 @@ <?php include("./lib/config.php"); + +require("./vendor/autoload.php"); +use GuzzleHttp\Client; + $data = array( 'secret' => $secretkey, 'response' => $_POST['h-captcha-response'] ); +$client = new Client(); -$verify = curl_init(); -curl_setopt($verify, CURLOPT_URL, "https://hcaptcha.com/siteverify"); -curl_setopt($verify, CURLOPT_POST, true); -curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data)); -curl_setopt($verify, CURLOPT_RETURNTRANSFER, true); -$response_ = curl_exec($verify); -$responseData = json_decode($response_); - - +$response = $client->post("https://hcaptcha.com/siteverify", [ + "form_params" => $data +]); +$responseData = json_decode($response->getBody()); if($responseData->success) { echo("$contactmail"); } else { diff --git a/public/API/newComment.php b/public/API/newComment.php index 860a81b..c9e293e 100644 --- a/public/API/newComment.php +++ b/public/API/newComment.php @@ -1,19 +1,22 @@ <?php +require './vendor/autoload.php'; include("./lib/config.php"); include("./lib/mysql.php"); +use GuzzleHttp\Client; + $data = array( 'secret' => $secretkey, 'response' => $_POST['h-captcha-response'] ); -$verify = curl_init(); -curl_setopt($verify, CURLOPT_URL, "https://hcaptcha.com/siteverify"); -curl_setopt($verify, CURLOPT_POST, true); -curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data)); -curl_setopt($verify, CURLOPT_RETURNTRANSFER, true); -$response_ = curl_exec($verify); -$responseData = json_decode($response_); +$client = new Client(); + +$response = $client->post("https://hcaptcha.com/siteverify", [ + "form_params" => $data +]); + +$responseData = json_decode($response->getBody()); -- GitLab