diff --git a/public/API/getMail.php b/public/API/getMail.php deleted file mode 100644 index b2f438b113e2f7f78d036114fd6212d49096c500..0000000000000000000000000000000000000000 --- a/public/API/getMail.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php -include("./lib/config.php"); - -require("./vendor/autoload.php"); -use GuzzleHttp\Client; - -$data = array( - 'secret' => $secretkey, - 'response' => $_POST['h-captcha-response'] -); -$client = new Client(); - -$response = $client->post("https://hcaptcha.com/siteverify", [ - "form_params" => $data -]); - -$responseData = json_decode($response->getBody()); -if($responseData->success) { - echo("$contactmail"); -} else { - echo("Failed to verify Captcha"); -} \ No newline at end of file diff --git a/public/API/queries/mailAddress.php b/public/API/queries/mailAddress.php new file mode 100644 index 0000000000000000000000000000000000000000..df35464278845b79349b84b63ec640b9b41817e2 --- /dev/null +++ b/public/API/queries/mailAddress.php @@ -0,0 +1,22 @@ +<?php +use GuzzleHttp\Client; + +function mailAddress($hCaptchaResponse) { + include("./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) { + return "$contactmail"; + } else { + return "Failed to verify Captcha"; + } +} \ No newline at end of file diff --git a/public/API/queries/queries.php b/public/API/queries/queries.php index fe1d471be062864b5dafc6936da7fe7a175054ee..e7558057e1717ff17046004e6755747a7d84ee70 100644 --- a/public/API/queries/queries.php +++ b/public/API/queries/queries.php @@ -5,6 +5,7 @@ use GraphQL\Type\Definition\Type; require "./queries/skills.php"; require "./queries/blogPost.php"; require "./queries/comments.php"; +require "./queries/mailAddress.php"; $queryType = new ObjectType([ 'name' => 'Query', @@ -13,6 +14,13 @@ $queryType = new ObjectType([ 'type' => Type::string(), 'resolve' => fn ($rootValue, $args) => $sitekey, ], + 'mailAddress' => [ + 'type' => Type::string(), + "args" => [ + "hCaptchaResponse" => Type::string() + ], + 'resolve' => fn ($rootValue, $args) => mailAddress($args["hCaptchaResponse"]), + ], 'skills' => [ 'type' => Type::listOf(Type::string()), 'resolve' => fn ($rootValue, $args) => getSkills(), diff --git a/public/impressum.html b/public/impressum.html index 92ca021d5381c9f87c8817fc116cf00f6a6ea16b..55ec96f6fb92889d2abd8e4fefcef34bae6df3a5 100644 --- a/public/impressum.html +++ b/public/impressum.html @@ -49,20 +49,24 @@ <a href="https://hcaptcha.com/privacy">Privacy Policy</a> and <a href="https://hcaptcha.com/terms">Terms of Service</a> apply. <script type="text/javascript"> - function onSubmit(token) { - let xmlhttp = new XMLHttpRequest(); - xmlhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - let button = document.getElementById("emailButton"); - let emailElement = document.createElement("p"); - emailElement.className = "emailBox"; - emailElement.innerText = this.responseText; - button.parentNode.replaceChild(emailElement, button); - } + async function onSubmit(token) { + var graphql = JSON.stringify({ + query: 'query($hCaptchaResponse: String!) { mailAddress(hCaptchaResponse: $hCaptchaResponse)}', + variables: { + "hCaptchaResponse": token + } + }) + var requestOptions = { + method: 'POST', + body: graphql, }; - xmlhttp.open("POST", "/API/getMail.php", true); - xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xmlhttp.send("h-captcha-response=" + token); + let mailAddress = (await (await fetch("http://localhost:1234/API/graphql.php", requestOptions)).json()).data.mailAddress; + + let button = document.getElementById("emailButton"); + let emailElement = document.createElement("p"); + emailElement.className = "emailBox"; + emailElement.innerText = mailAddress; + button.parentNode.replaceChild(emailElement, button); } </script> </div>