Conditions | 5 |
Paths | 4 |
Total Lines | 19 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
39 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
40 | { |
||
41 | if (!self::hasAttribute($request, ClientIp::KEY)) { |
||
42 | throw new RuntimeException('Recaptcha middleware needs ClientIp executed before'); |
||
43 | } |
||
44 | |||
45 | if (Utils\Helpers::isPost($request)) { |
||
46 | $recaptcha = new GoogleRecaptcha($this->secret); |
||
47 | |||
48 | $data = $request->getParsedBody(); |
||
49 | $res = $recaptcha->verify(isset($data['g-recaptcha-response']) ? $data['g-recaptcha-response'] : '', ClientIp::getIp($request)); |
||
50 | |||
51 | if (!$res->isSuccess()) { |
||
52 | return $response->withStatus(403); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | return $next($request, $response); |
||
57 | } |
||
58 | } |
||
59 |