Skip to content

Commit

Permalink
Merge pull request #247 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 6.2.1 Workaround recaptcha error and catch potential future error.
  • Loading branch information
Baggerone authored Oct 26, 2022
2 parents 66bc8ca + 4162204 commit 4a559ea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions application/common/helpers/Utils.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace common\helpers;

use ReCaptcha\ReCaptcha;
use ReCaptcha\RequestMethod\CurlPost as ReCaptchaCurlPost;
use yii\base\Security;
use yii\helpers\Html;
use yii\helpers\Json;
Expand Down Expand Up @@ -218,8 +220,13 @@ public static function getRandomDigits($length = 4)
*/
public static function isRecaptchaResponseValid($verificationToken, $ipAddress)
{
$recaptcha = new \ReCaptcha\ReCaptcha(\Yii::$app->params['recaptcha']['secretKey']);
$response = $recaptcha->verify($verificationToken, $ipAddress);
$recaptcha = new ReCaptcha(\Yii::$app->params['recaptcha']['secretKey'], new ReCaptchaCurlPost());

try {
$response = $recaptcha->verify($verificationToken, $ipAddress);
} catch (\Exception $e) {
throw new \Exception('Error attempting to verify recaptcha token: ' . $e->getMessage(), 1666090198);
}

if ($response->isSuccess()) {
return true;
Expand Down

0 comments on commit 4a559ea

Please sign in to comment.