| 1 |
<?php |
| 2 |
|
| 3 |
namespace Depicter\Controllers\Ajax; |
| 4 |
|
| 5 |
use Depicter\Utility\Sanitize; |
| 6 |
use WPEmerge\Requests\RequestInterface; |
| 7 |
|
| 8 |
class GoogleRecaptchaController |
| 9 |
{ |
| 10 |
|
| 11 |
/** |
| 12 |
* form submit spam checker |
| 13 |
* |
| 14 |
* @param RequestInterface $request |
| 15 |
* @param $view |
| 16 |
* |
| 17 |
* @return \Psr\Http\Message\ResponseInterface |
| 18 |
*/ |
| 19 |
public function verify( RequestInterface $request, $view ) { |
| 20 |
$token = Sanitize::textfield( $request->body( 'g-recaptcha-response', '' ) ); |
| 21 |
|
| 22 |
if ( empty( $token ) ) { |
| 23 |
return \Depicter::json([ |
| 24 |
'errors' => [ __( 'google recaptcha response parameter required.', 'depicter' ) ] |
| 25 |
])->withStatus( 400 ); |
| 26 |
} |
| 27 |
|
| 28 |
$isValid = \Depicter::recaptcha()->verify( $token ); |
| 29 |
if ( $isValid['success'] ) { |
| 30 |
return \Depicter::json( [ 'success' => true ] )->withStatus( 200 ); |
| 31 |
} |
| 32 |
|
| 33 |
return \Depicter::json([ |
| 34 |
'errors' => [ $isValid['message'] ] |
| 35 |
])->withStatus( 400 ); |
| 36 |
} |
| 37 |
} |
| 38 |
|