2016-08-20 23:24:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace CustomValidations;
|
|
|
|
|
|
|
|
use Respect\Validation\Rules\AbstractRule;
|
|
|
|
|
|
|
|
class Captcha extends AbstractRule {
|
|
|
|
|
|
|
|
public function validate($reCaptchaResponse) {
|
|
|
|
$reCaptchaPrivateKey = \Setting::getSetting('recaptcha-private')->getValue();
|
2017-01-13 21:06:49 +01:00
|
|
|
$apiKey = \APIKey::getDataStore(\Controller::request('apiKey'), 'token');
|
2016-08-20 23:24:22 +02:00
|
|
|
|
2017-01-13 21:06:49 +01:00
|
|
|
if (!$reCaptchaPrivateKey || !$apiKey->isNull()) return true;
|
2016-08-20 23:24:22 +02:00
|
|
|
|
|
|
|
$reCaptcha = new \ReCaptcha\ReCaptcha($reCaptchaPrivateKey);
|
|
|
|
$reCaptchaValidation = $reCaptcha->verify($reCaptchaResponse, $_SERVER['REMOTE_ADDR']);
|
|
|
|
|
|
|
|
return $reCaptchaValidation->isSuccess();
|
|
|
|
}
|
|
|
|
}
|