-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathReCaptcha.php
More file actions
52 lines (43 loc) · 1.13 KB
/
ReCaptcha.php
File metadata and controls
52 lines (43 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Netgen\InformationCollection\API\Value\Captcha;
use Netgen\InformationCollection\API\Service\CaptchaValue;
use ReCaptcha\ReCaptcha as BaseReCaptcha;
use Symfony\Component\HttpFoundation\Request;
class ReCaptcha implements CaptchaValue
{
/**
* @var \ReCaptcha\ReCaptcha
*/
protected $reCaptcha;
/**
* ReCaptcha constructor.
*
* @param \ReCaptcha\ReCaptcha $reCaptcha
*/
public function __construct(BaseReCaptcha $reCaptcha)
{
$this->reCaptcha = $reCaptcha;
}
/**
* {@inheritdoc}
*/
public function isValid(Request $request): bool
{
$clientIp = $request->getClientIp() === '::1' ? 'localhost' : $request->getClientIp();
$response = $this->reCaptcha->verify(
$request->request->get('g-recaptcha-response'),
$clientIp
);
return $response->isSuccess();
}
/**
* Returns aggregated captcha implementation.
*
* @return \ReCaptcha\ReCaptcha
*/
public function getInnerCaptcha(): BaseReCaptcha
{
return $this->reCaptcha;
}
}