Skip to content

Commit

Permalink
Validation fails. Error code: timeout-or-duplicate greggilbert#140
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkmt2 committed Jul 1, 2018
1 parent c2ed383 commit 6d973f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/RecaptchaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public function boot()
*/
public function addValidator()
{
$this->app->validator->extendImplicit('recaptcha', function ($attribute, $value, $parameters) {
$captcha = app('recaptcha.service');
$captcha = app('recaptcha.service');

$this->app->validator->extendImplicit('recaptcha', function ($attribute, $value, $parameters) use($captcha) {
$challenge = app('request')->input($captcha->getResponseKey());

return $captcha->check($challenge, $value);
Expand Down
7 changes: 6 additions & 1 deletion src/Service/CheckRecaptchaV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
class CheckRecaptchaV2 implements RecaptchaInterface
{
private $cached;

/**
* Call out to reCAPTCHA and process the response
Expand All @@ -18,6 +19,10 @@ class CheckRecaptchaV2 implements RecaptchaInterface
*/
public function check($challenge, $response)
{
if ($this->cached) {
return $this->cached;
}

$parameters = http_build_query([
'secret' => value(app('config')->get('recaptcha.private_key')),
'remoteip' => app('request')->getClientIp(),
Expand Down Expand Up @@ -52,7 +57,7 @@ public function check($challenge, $response)

$decodedResponse = json_decode($checkResponse, true);

return $decodedResponse['success'];
return $this->cached = $decodedResponse['success'];
}

public function getTemplate()
Expand Down

0 comments on commit 6d973f6

Please sign in to comment.