get impressum mail from graphQL
This commit is contained in:
parent
9b12fe2c94
commit
abe8db6e8b
4 changed files with 47 additions and 35 deletions
|
@ -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");
|
|
||||||
}
|
|
22
public/API/queries/mailAddress.php
Normal file
22
public/API/queries/mailAddress.php
Normal file
|
@ -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";
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ use GraphQL\Type\Definition\Type;
|
||||||
require "./queries/skills.php";
|
require "./queries/skills.php";
|
||||||
require "./queries/blogPost.php";
|
require "./queries/blogPost.php";
|
||||||
require "./queries/comments.php";
|
require "./queries/comments.php";
|
||||||
|
require "./queries/mailAddress.php";
|
||||||
|
|
||||||
$queryType = new ObjectType([
|
$queryType = new ObjectType([
|
||||||
'name' => 'Query',
|
'name' => 'Query',
|
||||||
|
@ -13,6 +14,13 @@ $queryType = new ObjectType([
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => fn ($rootValue, $args) => $sitekey,
|
'resolve' => fn ($rootValue, $args) => $sitekey,
|
||||||
],
|
],
|
||||||
|
'mailAddress' => [
|
||||||
|
'type' => Type::string(),
|
||||||
|
"args" => [
|
||||||
|
"hCaptchaResponse" => Type::string()
|
||||||
|
],
|
||||||
|
'resolve' => fn ($rootValue, $args) => mailAddress($args["hCaptchaResponse"]),
|
||||||
|
],
|
||||||
'skills' => [
|
'skills' => [
|
||||||
'type' => Type::listOf(Type::string()),
|
'type' => Type::listOf(Type::string()),
|
||||||
'resolve' => fn ($rootValue, $args) => getSkills(),
|
'resolve' => fn ($rootValue, $args) => getSkills(),
|
||||||
|
|
|
@ -49,20 +49,24 @@
|
||||||
<a href="https://hcaptcha.com/privacy">Privacy Policy</a> and
|
<a href="https://hcaptcha.com/privacy">Privacy Policy</a> and
|
||||||
<a href="https://hcaptcha.com/terms">Terms of Service</a> apply.
|
<a href="https://hcaptcha.com/terms">Terms of Service</a> apply.
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function onSubmit(token) {
|
async function onSubmit(token) {
|
||||||
let xmlhttp = new XMLHttpRequest();
|
var graphql = JSON.stringify({
|
||||||
xmlhttp.onreadystatechange = function() {
|
query: 'query($hCaptchaResponse: String!) { mailAddress(hCaptchaResponse: $hCaptchaResponse)}',
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
variables: {
|
||||||
let button = document.getElementById("emailButton");
|
"hCaptchaResponse": token
|
||||||
let emailElement = document.createElement("p");
|
}
|
||||||
emailElement.className = "emailBox";
|
})
|
||||||
emailElement.innerText = this.responseText;
|
var requestOptions = {
|
||||||
button.parentNode.replaceChild(emailElement, button);
|
method: 'POST',
|
||||||
}
|
body: graphql,
|
||||||
};
|
};
|
||||||
xmlhttp.open("POST", "/API/getMail.php", true);
|
let mailAddress = (await (await fetch("http://localhost:1234/API/graphql.php", requestOptions)).json()).data.mailAddress;
|
||||||
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
|
||||||
xmlhttp.send("h-captcha-response=" + token);
|
let button = document.getElementById("emailButton");
|
||||||
|
let emailElement = document.createElement("p");
|
||||||
|
emailElement.className = "emailBox";
|
||||||
|
emailElement.innerText = mailAddress;
|
||||||
|
button.parentNode.replaceChild(emailElement, button);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue