Skip to content

Instantly share code, notes, and snippets.

@emtudo
Last active October 6, 2023 20:17
Show Gist options
  • Save emtudo/0a1fdca699448c0e1cc8b9d42b5d5d8d to your computer and use it in GitHub Desktop.
Save emtudo/0a1fdca699448c0e1cc8b9d42b5d5d8d to your computer and use it in GitHub Desktop.
// Controller
// Metodo do controle que faz a chacagem
protected function checkRecaptcha($token, $ip)
{
$response = (new Client)->post('https://www.google.com/recaptcha/api/siteverify', [
'form_params' => [
'secret' => config('services.recaptcha.secret'),
'response' => $token,
'remoteip' => $ip,
],
]);
$response = json_decode((string) $response->getBody(), true);
return $response['success'];
}
// Metodo que faz a chamada para verificar o recaptcha
public function login(Request $request, Guard $auth, ManagerFractal $manager)
{
if (config('services.recaptcha.enabled') && !$this->checkRecaptcha($request->get('token'), $request->ip())) {
return response()->json('Recaptcha inválido.', 500);
}
// Continue a parte para checar seu login aqui
}
// services.php
'recaptcha' => [
'enabled' => env('RECAPTCHA_ENABLED', true),
'key' => env('RECAPTCHA_SITE_KEY'),
'secret' => env('RECAPTCHA_SECRET_KEY'),
],
// env
RECAPTCHA_ENABLED=true
RECAPTCHA_SITE_KEY=6LeyiC4UAAAAAK5XGb2IBhnY9M0ZtH76wYNmIUW4
RECAPTCHA_SECRET_KEY=6LeyiC4UAAAAABNa7fh3Q14JLKhc6_gFL9jQXUk9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment