From 98e716cee7e3ce87f76998f6ce3f2f84f83ca4f0 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 25 Jan 2017 10:49:48 -0500
Subject: [PATCH] Upgrade to new version of ReCaptcha library. (#894)

---
 composer.json                                   |  2 +-
 .../src/VuFind/Controller/Plugin/Recaptcha.php  |  2 +-
 module/VuFind/src/VuFind/Service/Factory.php    | 17 +++++++++--------
 module/VuFind/src/VuFind/Service/ReCaptcha.php  |  2 +-
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/composer.json b/composer.json
index 28864867337..68d2a74872b 100644
--- a/composer.json
+++ b/composer.json
@@ -12,7 +12,7 @@
         "aferrandini/phpqrcode": "1.0.1",
         "jasig/phpcas": "1.3.3",
         "cap60552/php-sip2": "1.0.0",
-        "los/losrecaptcha": "1.0.0",
+        "los/losrecaptcha": "2.0.2",
         "ahand/mobileesp": "dev-master",
         "matthiasmullie/minify": "1.3.35",
         "ocramius/proxy-manager": "1.0.2",
diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Recaptcha.php b/module/VuFind/src/VuFind/Controller/Plugin/Recaptcha.php
index b5c15efc686..8426b33d0a6 100644
--- a/module/VuFind/src/VuFind/Controller/Plugin/Recaptcha.php
+++ b/module/VuFind/src/VuFind/Controller/Plugin/Recaptcha.php
@@ -124,7 +124,7 @@ class Recaptcha extends AbstractPlugin
         } catch (\ZendService\ReCaptcha\Exception $e) {
             $response = false;
         }
-        $captchaPassed = $response && $response->isValid();
+        $captchaPassed = $response && $response->isSuccess();
         if (!$captchaPassed && $this->errorMode != 'none') {
             if ($this->errorMode == 'flash') {
                 $this->getController()->flashMessenger()
diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php
index 0118867d1f1..7be34956db4 100644
--- a/module/VuFind/src/VuFind/Service/Factory.php
+++ b/module/VuFind/src/VuFind/Service/Factory.php
@@ -540,17 +540,18 @@ class Factory
             : (isset($config->Captcha->privateKey)
                 ? $config->Captcha->privateKey
                 : '');
-        $recaptcha = new \VuFind\Service\ReCaptcha(
-            $siteKey, $secretKey, ['ssl' => true]
-        );
+        $httpClient = $sm->get('VuFind\Http')->createClient();
+        $translator = $sm->get('VuFind\Translator');
+        $options = ['lang' => $translator->getLocale()];
         if (isset($config->Captcha->theme)) {
-            $recaptcha->setOption('theme', $config->Captcha->theme);
+            $options['theme'] = $config->Captcha->theme;
         }
-        $translator = $sm->get('VuFind\Translator');
-        $recaptcha->setOption('lang', $translator->getLocale());
+        $recaptcha = new \VuFind\Service\ReCaptcha(
+            $siteKey, $secretKey,
+            new \LosReCaptcha\Service\Request\ZendHttpClient($httpClient),
+            ['ssl' => true], $options
+        );
 
-        $httpClient = $sm->get('VuFind\Http')->createClient();
-        $recaptcha->setHttpClient($httpClient);
         return $recaptcha;
     }
 
diff --git a/module/VuFind/src/VuFind/Service/ReCaptcha.php b/module/VuFind/src/VuFind/Service/ReCaptcha.php
index a8152779436..e693289803e 100644
--- a/module/VuFind/src/VuFind/Service/ReCaptcha.php
+++ b/module/VuFind/src/VuFind/Service/ReCaptcha.php
@@ -20,7 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  * @category VuFind
- * @package  View_Helpers
+ * @package  Service
  * @author   Chris Hallberg <crhallberg@gmail.com>
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org/wiki/development Wiki
-- 
GitLab