Commit 0f44e59e authored by mmghv's avatar mmghv

Allow verifying multiple times.

Google will only verify a response one time .. so we cache the response to allow multiple calls to verifyResponse() method.
parent cc5d4f50
......@@ -9,8 +9,6 @@ class NoCaptcha
{
const CLIENT_API = 'https://www.google.com/recaptcha/api.js';
const VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
const ON_LOAD_CLASS = 'onloadCallBack';
const RENDER_TYPE = 'explicit';
/**
* The recaptcha secret key.
......@@ -31,6 +29,13 @@ class NoCaptcha
*/
protected $http;
/**
* The cached verified responses.
*
* @var array
*/
protected $verifiedResponses = [];
/**
* NoCaptcha.
*
......@@ -85,13 +90,25 @@ class NoCaptcha
return false;
}
$response = $this->sendRequestVerify([
// Return true if response already verfied before.
if (in_array($response, $this->verifiedResponses)) {
return true;
}
$verifyResponse = $this->sendRequestVerify([
'secret' => $this->secret,
'response' => $response,
'remoteip' => $clientIp,
]);
return isset($response['success']) && $response['success'] === true;
if (isset($verifyResponse['success']) && $verifyResponse['success'] === true) {
// A response can only be verified once from google, so we need to
// cache it to make it work in case we want to verify it multiple times.
$this->verifiedResponses[] = $response;
return true;
} else {
return false;
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment