Commit f78e1a0c authored by Nguyen Van Anh's avatar Nguyen Van Anh Committed by GitHub

Merge pull request #91 from mmghv/multiple-verify

Allow verifying multiple times.
parents 60aa7396 0f44e59e
......@@ -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