Skip to content

Commit

Permalink
✨ Added option for setting recaptcha score
Browse files Browse the repository at this point in the history
  • Loading branch information
IamSwap committed Apr 17, 2020
1 parent e113156 commit 0bd9abf
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/GoogleRecaptchaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ public function boot()
}

// Register validator
Validator::extend('recaptcha', function ($attribute, $value, $parameters, $validator) {
Validator::extend('recaptcha1', function ($attribute, $value, $parameters, $validator) {
$recaptcha = new ReCaptcha(config('google-recaptcha.secret'));

$response = $recaptcha->verify($value, request()->ip());

return $response->isSuccess();
if (! $response->isSuccess()) {
return false;
}

// calculate score
if (isset($parameters[0])) {
if ($response->getScore() < $parameters[0]) {
return false;
}
}

return true;
}, 'Failed to verify recaptcha!');
}

Expand Down

0 comments on commit 0bd9abf

Please sign in to comment.