|
12 | 12 |
|
13 | 13 | use Exception;
|
14 | 14 |
|
| 15 | +/** |
| 16 | + * Class ReCaptchaBuilder |
| 17 | + * @package Biscolab\ReCaptcha |
| 18 | + */ |
15 | 19 | class ReCaptchaBuilder {
|
16 | 20 |
|
| 21 | + /** |
| 22 | + * @var string |
| 23 | + */ |
| 24 | + const DEFAULT_API_VERSION = 'v2'; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var int |
| 28 | + */ |
| 29 | + const DEFAULT_CURL_TIMEOUT = 10; |
| 30 | + |
17 | 31 | /**
|
18 | 32 | * The Site key
|
19 | 33 | * please visit https://developers.google.com/recaptcha/docs/start
|
@@ -53,7 +67,20 @@ class ReCaptchaBuilder {
|
53 | 67 | */
|
54 | 68 | protected $api_url = 'https://www.google.com/recaptcha/api/siteverify';
|
55 | 69 |
|
56 |
| - public function __construct($api_site_key, $api_secret_key, $version = 'v2', $curl_timeout = 3) { |
| 70 | + /** |
| 71 | + * ReCaptchaBuilder constructor. |
| 72 | + * |
| 73 | + * @param string $api_site_key |
| 74 | + * @param string $api_secret_key |
| 75 | + * @param null|string $version |
| 76 | + * @param int|null $curl_timeout |
| 77 | + */ |
| 78 | + public function __construct( |
| 79 | + string $api_site_key, |
| 80 | + string $api_secret_key, |
| 81 | + ?string $version = self::DEFAULT_API_VERSION, |
| 82 | + ?int $curl_timeout = self::DEFAULT_CURL_TIMEOUT |
| 83 | + ) { |
57 | 84 |
|
58 | 85 | $this->setApiSiteKey($api_site_key);
|
59 | 86 | $this->setApiSecretKey($api_secret_key);
|
@@ -88,6 +115,7 @@ public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
|
88 | 115 |
|
89 | 116 | /**
|
90 | 117 | * @param int $curl_timeout
|
| 118 | + * |
91 | 119 | * @return ReCaptchaBuilder
|
92 | 120 | */
|
93 | 121 | public function setCurlTimeout(int $curl_timeout): ReCaptchaBuilder {
|
@@ -141,9 +169,10 @@ public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder {
|
141 | 169 | * @return array|mixed
|
142 | 170 | */
|
143 | 171 | public function getIpWhitelist() {
|
| 172 | + |
144 | 173 | $whitelist = config('recaptcha.skip_ip', []);
|
145 | 174 |
|
146 |
| - if(!is_array($whitelist)) { |
| 175 | + if (!is_array($whitelist)) { |
147 | 176 | $whitelist = explode(',', $whitelist);
|
148 | 177 | }
|
149 | 178 |
|
@@ -214,7 +243,9 @@ function biscolabLaravelReCaptcha(token) {
|
214 | 243 | $js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : '';
|
215 | 244 |
|
216 | 245 | $validate_function = "
|
217 |
| - fetch('/" . config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name', 'token') . "=' + token, { |
| 246 | + fetch('/" . config('recaptcha.default_validation_route', |
| 247 | + 'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name', |
| 248 | + 'token') . "=' + token, { |
218 | 249 | headers: {
|
219 | 250 | \"X-Requested-With\": \"XMLHttpRequest\",
|
220 | 251 | \"X-CSRF-TOKEN\": csrfToken.content
|
|
0 commit comments