diff --git a/build/gulp-extensions.json b/build/gulp-extensions.json index 9e837363e903..fd16ef33fbc1 100644 --- a/build/gulp-extensions.json +++ b/build/gulp-extensions.json @@ -10,7 +10,7 @@ }, "plugins" : { "redform" : ["economic", "helpscout", "redmemberbillinginfo", "salesforce", "aesirmember", "aesirecommerce"], - "redform_captcha" : ["hiddencaptcha", "recaptcha", "simplemath"], + "redform_captcha" : ["hiddencaptcha", "recaptcha", "simplemath", "hcaptcha"], "redform_field" : [ "dawa", "acymailing", diff --git a/build/joomla-gulp-extensions/plugins/redform_captcha/hcaptcha.js b/build/joomla-gulp-extensions/plugins/redform_captcha/hcaptcha.js new file mode 100644 index 000000000000..b7c175c7d37e --- /dev/null +++ b/build/joomla-gulp-extensions/plugins/redform_captcha/hcaptcha.js @@ -0,0 +1,7 @@ +var base = require('../baseplugin'); +var path = require('path'); + +var name = path.basename(__filename).replace('.js', ''); +var group = path.basename(path.dirname(__filename)); + +base.addPlugin(group, name); diff --git a/plugins/redform_captcha/hcaptcha/hcaptcha.php b/plugins/redform_captcha/hcaptcha/hcaptcha.php new file mode 100644 index 000000000000..d1848012f3cc --- /dev/null +++ b/plugins/redform_captcha/hcaptcha/hcaptcha.php @@ -0,0 +1,79 @@ +addScript('https://hcaptcha.com/1/api.js', [], ['defer' => true, 'async' => true]); + + $attributes = [ + 'data-sitekey' => $this->params->get('siteKey'), + 'data-theme' => $this->params->get('theme', 'light'), + 'data-size' => $this->params->get('size', 'normal'), + ]; + + $text = '
'; + + return true; + } + + /** + * onCheckCaptcha trigger + * + * @param bool &$result result + * + * @return bool + */ + public function onCheckCaptcha(&$result) + { + $app = Factory::getApplication(); + $input = $app->input; + $response = $input->post->getString('h-captcha-response'); + $result = false; + + if (empty($response)) + { + return $result; + } + + try + { + $response = HttpFactory::getHttp() + ->post( + 'https://hcaptcha.com/siteverify', + [ + 'secret' => $this->params->get('secretKey'), + 'response' => $response, + 'sitekey' => $this->params->get('siteKey'), + 'remoteip' => $input->server->get('REMOTE_ADDR') + ] + ); + + $responseData = json_decode($response->body); + $result = $responseData->success; + } + catch (Exception $e) + { + } + + return $result; + } +} diff --git a/plugins/redform_captcha/hcaptcha/hcaptcha.xml b/plugins/redform_captcha/hcaptcha/hcaptcha.xml new file mode 100644 index 000000000000..c94b3d00863d --- /dev/null +++ b/plugins/redform_captcha/hcaptcha/hcaptcha.xml @@ -0,0 +1,49 @@ + +