This commit is contained in:
Cyberes 2020-10-24 19:18:54 -06:00
parent 34c438b04f
commit d97d9d3462
1 changed files with 32 additions and 0 deletions

View File

@ -379,6 +379,11 @@ class SpecialContact extends UnlistedSpecialPage
' replyto ' . ($replyTo == null ? '-/-' : $replyTo->toString()) . "\n"
);
// verify captcha
echo $request;
$verfiy = self::verifyCaptcha($recaptchaResponse);
echo $verify;
$mailResult = UserMailer::send(
$contactRecipientAddress,
$senderAddress,
@ -431,4 +436,31 @@ class SpecialContact extends UnlistedSpecialPage
{
return $this->msg($value ? 'htmlform-yes' : 'htmlform-no')->inContentLanguage()->text();
}
private function verifyCaptcha($recaptchaResponse)
{
global $wgRequest;
$x = $wgRequest->getHeader("REMOTE_ADDR");
echo $x;
$post_data = http_build_query(
array(
'secret' => CAPTCHA_SECRET,
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $_SERVER['REMOTE_ADDR']
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $post_data
)
);
$context = stream_context_create($opts);
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context);
$result = json_decode($response);
if (!$result->success) {
throw new Exception('Gah! CAPTCHA verification failed. Please email me directly at: jstark at jonathanstark dot com', 1);
}
}
}