Skip to content

Commit

Permalink
Merge pull request #1 from creode-dev/skip-recaptcha-verify-event
Browse files Browse the repository at this point in the history
Skip recaptcha verify event
  • Loading branch information
creode-dev authored Jan 18, 2023
2 parents feefd6f + 273a2e9 commit 415bc94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/events/SkipRecaptchaEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace juban\googlerecaptcha\events;

use yii\base\Event;

class SkipRecaptchaEvent extends Event
{
/**
* Should skip verification
*
* @var bool
*/
public bool $skipVerification = false;
}
11 changes: 11 additions & 0 deletions src/services/Recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\helpers\Json;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ConnectException;
use juban\googlerecaptcha\events\SkipRecaptchaEvent;
use juban\googlerecaptcha\GoogleRecaptcha;
use yii\helpers\VarDumper;
use yii\web\ForbiddenHttpException;
Expand All @@ -30,11 +31,21 @@
*/
class Recaptcha extends Component
{

const EVENT_SKIP_RECAPTCHA_VERIFICATION = 'skipRecaptchaVerification';

// Public Methods
// =========================================================================

public function verify(): bool
{
// Event
$skipRecaptchaEvent = new SkipRecaptchaEvent();
$this->trigger(self::EVENT_SKIP_RECAPTCHA_VERIFICATION, $skipRecaptchaEvent);
if ($skipRecaptchaEvent->skipVerification === true) {
return true;
}

$request = Craft::$app->getRequest();
$recaptchaResponse = $request->getParam('g-recaptcha-response');
if ($recaptchaResponse === null) {
Expand Down

0 comments on commit 415bc94

Please sign in to comment.