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