Skip to content

Commit

Permalink
Changed captcha plugin to use Composer racaptcha (nocaptcha) lib inst…
Browse files Browse the repository at this point in the history
…ead of static. Confirmed v2 use, ahead of impending death of v1.
  • Loading branch information
cheesegrits committed Mar 25, 2018
1 parent a44dee7 commit 99dd24c
Show file tree
Hide file tree
Showing 37 changed files with 1,832 additions and 44 deletions.
13 changes: 4 additions & 9 deletions plugins/fabrik_element/captcha/captcha.php
Expand Up @@ -11,6 +11,9 @@
// No direct access
defined('_JEXEC') or die('Restricted access');

use ReCaptcha\ReCaptcha;

require_once JPATH_ROOT . '/plugins/fabrik_element/captcha/vendor/autoload.php';
/**
* Plugin element to captcha
*
Expand Down Expand Up @@ -333,16 +336,8 @@ public function validate($data, $repeatCounter = 0)
{
if ($input->get('g-recaptcha-response'))
{
require_once JPATH_SITE . '/plugins/fabrik_element/captcha/libs/ReCaptcha/ReCaptcha.php';
require_once JPATH_SITE . '/plugins/fabrik_element/captcha/libs/ReCaptcha/RequestMethod.php';
require_once JPATH_SITE . '/plugins/fabrik_element/captcha/libs/ReCaptcha/RequestMethod/Post.php';
require_once JPATH_SITE . '/plugins/fabrik_element/captcha/libs/ReCaptcha/RequestMethod/Socket.php';
require_once JPATH_SITE . '/plugins/fabrik_element/captcha/libs/ReCaptcha/RequestMethod/SocketPost.php';
require_once JPATH_SITE . '/plugins/fabrik_element/captcha/libs/ReCaptcha/RequestParameters.php';
require_once JPATH_SITE . '/plugins/fabrik_element/captcha/libs/ReCaptcha/Response.php';

$privateKey = $params->get('recaptcha_privatekey');
$noCaptcha = new \ReCaptcha\ReCaptcha($privateKey, new \ReCaptcha\RequestMethod\SocketPost());
$noCaptcha = new ReCaptcha($privateKey, new \ReCaptcha\RequestMethod\SocketPost());
$response = $input->get('g-recaptcha-response');
$server = $input->server->get('REMOTE_ADDR');
$resp = $noCaptcha->verify($response, $server);
Expand Down
5 changes: 5 additions & 0 deletions plugins/fabrik_element/captcha/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"google/recaptcha": "~1.1"
}
}
63 changes: 63 additions & 0 deletions plugins/fabrik_element/captcha/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,14 @@
<?php
defined('JPATH_BASE') or die;

$d = $displayData;
?>
<script>
function nocaptchaSubmitForm() {
Fabrik.getBlock('<?php echo $d->formId; ?>').doSubmit();
}
</script>

<div class ="g-recaptcha" data-sitekey="<?php echo $d->site_key; ?>" data-bind="<?php echo $d->btnId; ?>" data-callback="nocaptchaSubmitForm"></div>

<script src="https://www.google.com/recaptcha/api.js?hl=<?php echo $d->lang; ?>" async defer></script>
7 changes: 7 additions & 0 deletions plugins/fabrik_element/captcha/vendor/autoload.php
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit87f051b7c7baf609b29e5e7f79ec515a::getLoader();

0 comments on commit 99dd24c

Please sign in to comment.