Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions ReCaptcha/Model/CaptchaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,37 @@

namespace Magento\ReCaptcha\Model;

use Magento\Framework\Exception\LocalizedException;
use Magento\ReCaptchaApi\Api\CaptchaValidatorInterface;
use Magento\ReCaptchaApi\Api\Data\ValidationConfigInterface;
use Psr\Log\LoggerInterface;
use ReCaptcha\ReCaptcha;

/**
* @inheritDoc
*/
class CaptchaValidator implements CaptchaValidatorInterface
{
/**
* @var LoggerInterface
*/
private $logger;

/**
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}

/**
* @inheritdoc
*/
public function validate(
string $reCaptchaResponse,
ValidationConfigInterface $validationConfig
): bool {
$result = false;
$secret = $validationConfig->getPrivateKey();

if ($reCaptchaResponse) {
Expand All @@ -39,14 +53,12 @@ public function validate(
$res = $reCaptcha->verify($reCaptchaResponse, $validationConfig->getRemoteIp());

if (($validationConfig->getCaptchaType() === 'recaptcha_v3') && ($res->getScore() === null)) {
throw new LocalizedException(__('Internal error: Make sure you are using reCaptcha V3 api keys'));
}

if ($res->isSuccess()) {
return true;
$this->logger->alert(__('Internal error: Make sure you are using reCaptcha V3 api keys'));
} else if ($res->isSuccess()) {
$result = true;
}
}

return false;
return $result;
}
}