@@ -16,29 +16,29 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class ReCaptchaBuilderInvisible extends ReCaptchaBuilder { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * ReCaptchaBuilderInvisible constructor. |
|
| 21 | - * |
|
| 22 | - * @param string $api_site_key |
|
| 23 | - * @param string $api_secret_key |
|
| 24 | - * @param int $curl_timeout |
|
| 25 | - */ |
|
| 26 | - public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) { |
|
| 19 | + /** |
|
| 20 | + * ReCaptchaBuilderInvisible constructor. |
|
| 21 | + * |
|
| 22 | + * @param string $api_site_key |
|
| 23 | + * @param string $api_secret_key |
|
| 24 | + * @param int $curl_timeout |
|
| 25 | + */ |
|
| 26 | + public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) { |
|
| 27 | 27 | |
| 28 | - parent::__construct($api_site_key, $api_secret_key, 'invisible', $curl_timeout); |
|
| 29 | - } |
|
| 28 | + parent::__construct($api_site_key, $api_secret_key, 'invisible', $curl_timeout); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Write HTML <button> tag in your HTML code |
|
| 33 | - * Insert before </form> tag |
|
| 34 | - * |
|
| 35 | - * @param string $buttonInnerHTML |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public function htmlFormButton($buttonInnerHTML = 'Submit'): string { |
|
| 31 | + /** |
|
| 32 | + * Write HTML <button> tag in your HTML code |
|
| 33 | + * Insert before </form> tag |
|
| 34 | + * |
|
| 35 | + * @param string $buttonInnerHTML |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public function htmlFormButton($buttonInnerHTML = 'Submit'): string { |
|
| 40 | 40 | |
| 41 | - return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : ''; |
|
| 42 | - } |
|
| 41 | + return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : ''; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | } |
| 45 | 45 | \ No newline at end of file |
@@ -16,26 +16,26 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class ReCaptchaBuilderV2 extends ReCaptchaBuilder { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * ReCaptchaBuilderV2 constructor. |
|
| 21 | - * |
|
| 22 | - * @param string $api_site_key |
|
| 23 | - * @param string $api_secret_key |
|
| 24 | - * @param int $curl_timeout |
|
| 25 | - */ |
|
| 26 | - public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) { |
|
| 19 | + /** |
|
| 20 | + * ReCaptchaBuilderV2 constructor. |
|
| 21 | + * |
|
| 22 | + * @param string $api_site_key |
|
| 23 | + * @param string $api_secret_key |
|
| 24 | + * @param int $curl_timeout |
|
| 25 | + */ |
|
| 26 | + public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) { |
|
| 27 | 27 | |
| 28 | - parent::__construct($api_site_key, $api_secret_key, 'v2', $curl_timeout); |
|
| 29 | - } |
|
| 28 | + parent::__construct($api_site_key, $api_secret_key, 'v2', $curl_timeout); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Write ReCAPTCHA HTML tag in your FORM |
|
| 33 | - * Insert before </form> tag |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - public function htmlFormSnippet(): string { |
|
| 31 | + /** |
|
| 32 | + * Write ReCAPTCHA HTML tag in your FORM |
|
| 33 | + * Insert before </form> tag |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + public function htmlFormSnippet(): string { |
|
| 37 | 37 | |
| 38 | - return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="' . $this->api_site_key . '"></div>' : ''; |
|
| 39 | - } |
|
| 38 | + return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="' . $this->api_site_key . '"></div>' : ''; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | \ No newline at end of file |
@@ -14,206 +14,206 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | class ReCaptchaBuilder { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The Site key |
|
| 19 | - * please visit https://developers.google.com/recaptcha/docs/start |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $api_site_key; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * The Secret key |
|
| 26 | - * please visit https://developers.google.com/recaptcha/docs/start |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $api_secret_key; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * The chosen ReCAPTCHA version |
|
| 33 | - * please visit https://developers.google.com/recaptcha/docs/start |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $version; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * The curl timeout |
|
| 40 | - * please visit https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html |
|
| 41 | - * @var int |
|
| 42 | - */ |
|
| 43 | - protected $curl_timeout; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Whether is true the ReCAPTCHA is inactive |
|
| 47 | - * @var boolean |
|
| 48 | - */ |
|
| 49 | - protected $skip_by_ip = false; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The API request URI |
|
| 53 | - */ |
|
| 54 | - protected $api_url = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 55 | - |
|
| 56 | - public function __construct($api_site_key, $api_secret_key, $version = 'v2', $curl_timeout = 3) { |
|
| 57 | - |
|
| 58 | - $this->setApiSiteKey($api_site_key); |
|
| 59 | - $this->setApiSecretKey($api_secret_key); |
|
| 60 | - $this->setVersion($version); |
|
| 61 | - $this->setCurlTimeout($curl_timeout); |
|
| 62 | - $this->setSkipByIp($this->skipByIp()); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param string $api_site_key |
|
| 67 | - * |
|
| 68 | - * @return ReCaptchaBuilder |
|
| 69 | - */ |
|
| 70 | - public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder { |
|
| 71 | - |
|
| 72 | - $this->api_site_key = $api_site_key; |
|
| 73 | - |
|
| 74 | - return $this; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param string $api_secret_key |
|
| 79 | - * |
|
| 80 | - * @return ReCaptchaBuilder |
|
| 81 | - */ |
|
| 82 | - public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder { |
|
| 83 | - |
|
| 84 | - $this->api_secret_key = $api_secret_key; |
|
| 85 | - |
|
| 86 | - return $this; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param int $curl_timeout |
|
| 91 | - * @return ReCaptchaBuilder |
|
| 92 | - */ |
|
| 93 | - public function setCurlTimeout(int $curl_timeout): ReCaptchaBuilder { |
|
| 94 | - |
|
| 95 | - $this->curl_timeout = $curl_timeout; |
|
| 96 | - |
|
| 97 | - return $this; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return int |
|
| 102 | - */ |
|
| 103 | - public function getCurlTimeout(): int { |
|
| 104 | - |
|
| 105 | - return $this->curl_timeout; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param string $version |
|
| 110 | - * |
|
| 111 | - * @return ReCaptchaBuilder |
|
| 112 | - */ |
|
| 113 | - public function setVersion(string $version): ReCaptchaBuilder { |
|
| 114 | - |
|
| 115 | - $this->version = $version; |
|
| 116 | - |
|
| 117 | - return $this; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function getVersion(): string { |
|
| 124 | - |
|
| 125 | - return $this->version; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param bool $skip_by_ip |
|
| 130 | - * |
|
| 131 | - * @return ReCaptchaBuilder |
|
| 132 | - */ |
|
| 133 | - public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder { |
|
| 134 | - |
|
| 135 | - $this->skip_by_ip = $skip_by_ip; |
|
| 136 | - |
|
| 137 | - return $this; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return array|mixed |
|
| 142 | - */ |
|
| 143 | - public function getIpWhitelist() { |
|
| 144 | - $whitelist = config('recaptcha.skip_ip', []); |
|
| 145 | - |
|
| 146 | - if(!is_array($whitelist)) { |
|
| 147 | - $whitelist = explode(',', $whitelist); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $whitelist; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Checks whether the user IP address is among IPs "to be skipped" |
|
| 155 | - * |
|
| 156 | - * @return boolean |
|
| 157 | - */ |
|
| 158 | - public function skipByIp(): bool { |
|
| 159 | - |
|
| 160 | - return (in_array(request()->ip(), $this->getIpWhitelist())); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Write script HTML tag in you HTML code |
|
| 165 | - * Insert before </head> tag |
|
| 166 | - * |
|
| 167 | - * @param string|null $formId |
|
| 168 | - * @param array|null $configuration |
|
| 169 | - * |
|
| 170 | - * @return string |
|
| 171 | - * @throws Exception |
|
| 172 | - */ |
|
| 173 | - public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string { |
|
| 174 | - |
|
| 175 | - if ($this->skip_by_ip) { |
|
| 176 | - return ''; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - switch ($this->version) { |
|
| 180 | - case 'v3': |
|
| 181 | - $html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>"; |
|
| 182 | - break; |
|
| 183 | - default: |
|
| 184 | - $html = "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>"; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if ($this->version == 'invisible') { |
|
| 188 | - if (!$formId) { |
|
| 189 | - throw new Exception("formId required", 1); |
|
| 190 | - } |
|
| 191 | - $html .= '<script> |
|
| 17 | + /** |
|
| 18 | + * The Site key |
|
| 19 | + * please visit https://developers.google.com/recaptcha/docs/start |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $api_site_key; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * The Secret key |
|
| 26 | + * please visit https://developers.google.com/recaptcha/docs/start |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $api_secret_key; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * The chosen ReCAPTCHA version |
|
| 33 | + * please visit https://developers.google.com/recaptcha/docs/start |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $version; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * The curl timeout |
|
| 40 | + * please visit https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html |
|
| 41 | + * @var int |
|
| 42 | + */ |
|
| 43 | + protected $curl_timeout; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Whether is true the ReCAPTCHA is inactive |
|
| 47 | + * @var boolean |
|
| 48 | + */ |
|
| 49 | + protected $skip_by_ip = false; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The API request URI |
|
| 53 | + */ |
|
| 54 | + protected $api_url = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 55 | + |
|
| 56 | + public function __construct($api_site_key, $api_secret_key, $version = 'v2', $curl_timeout = 3) { |
|
| 57 | + |
|
| 58 | + $this->setApiSiteKey($api_site_key); |
|
| 59 | + $this->setApiSecretKey($api_secret_key); |
|
| 60 | + $this->setVersion($version); |
|
| 61 | + $this->setCurlTimeout($curl_timeout); |
|
| 62 | + $this->setSkipByIp($this->skipByIp()); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param string $api_site_key |
|
| 67 | + * |
|
| 68 | + * @return ReCaptchaBuilder |
|
| 69 | + */ |
|
| 70 | + public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder { |
|
| 71 | + |
|
| 72 | + $this->api_site_key = $api_site_key; |
|
| 73 | + |
|
| 74 | + return $this; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param string $api_secret_key |
|
| 79 | + * |
|
| 80 | + * @return ReCaptchaBuilder |
|
| 81 | + */ |
|
| 82 | + public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder { |
|
| 83 | + |
|
| 84 | + $this->api_secret_key = $api_secret_key; |
|
| 85 | + |
|
| 86 | + return $this; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param int $curl_timeout |
|
| 91 | + * @return ReCaptchaBuilder |
|
| 92 | + */ |
|
| 93 | + public function setCurlTimeout(int $curl_timeout): ReCaptchaBuilder { |
|
| 94 | + |
|
| 95 | + $this->curl_timeout = $curl_timeout; |
|
| 96 | + |
|
| 97 | + return $this; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return int |
|
| 102 | + */ |
|
| 103 | + public function getCurlTimeout(): int { |
|
| 104 | + |
|
| 105 | + return $this->curl_timeout; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param string $version |
|
| 110 | + * |
|
| 111 | + * @return ReCaptchaBuilder |
|
| 112 | + */ |
|
| 113 | + public function setVersion(string $version): ReCaptchaBuilder { |
|
| 114 | + |
|
| 115 | + $this->version = $version; |
|
| 116 | + |
|
| 117 | + return $this; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function getVersion(): string { |
|
| 124 | + |
|
| 125 | + return $this->version; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param bool $skip_by_ip |
|
| 130 | + * |
|
| 131 | + * @return ReCaptchaBuilder |
|
| 132 | + */ |
|
| 133 | + public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder { |
|
| 134 | + |
|
| 135 | + $this->skip_by_ip = $skip_by_ip; |
|
| 136 | + |
|
| 137 | + return $this; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @return array|mixed |
|
| 142 | + */ |
|
| 143 | + public function getIpWhitelist() { |
|
| 144 | + $whitelist = config('recaptcha.skip_ip', []); |
|
| 145 | + |
|
| 146 | + if(!is_array($whitelist)) { |
|
| 147 | + $whitelist = explode(',', $whitelist); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $whitelist; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Checks whether the user IP address is among IPs "to be skipped" |
|
| 155 | + * |
|
| 156 | + * @return boolean |
|
| 157 | + */ |
|
| 158 | + public function skipByIp(): bool { |
|
| 159 | + |
|
| 160 | + return (in_array(request()->ip(), $this->getIpWhitelist())); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Write script HTML tag in you HTML code |
|
| 165 | + * Insert before </head> tag |
|
| 166 | + * |
|
| 167 | + * @param string|null $formId |
|
| 168 | + * @param array|null $configuration |
|
| 169 | + * |
|
| 170 | + * @return string |
|
| 171 | + * @throws Exception |
|
| 172 | + */ |
|
| 173 | + public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string { |
|
| 174 | + |
|
| 175 | + if ($this->skip_by_ip) { |
|
| 176 | + return ''; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + switch ($this->version) { |
|
| 180 | + case 'v3': |
|
| 181 | + $html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>"; |
|
| 182 | + break; |
|
| 183 | + default: |
|
| 184 | + $html = "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>"; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if ($this->version == 'invisible') { |
|
| 188 | + if (!$formId) { |
|
| 189 | + throw new Exception("formId required", 1); |
|
| 190 | + } |
|
| 191 | + $html .= '<script> |
|
| 192 | 192 | function biscolabLaravelReCaptcha(token) { |
| 193 | 193 | document.getElementById("' . $formId . '").submit(); |
| 194 | 194 | } |
| 195 | 195 | </script>'; |
| 196 | - } |
|
| 197 | - elseif ($this->version == 'v3') { |
|
| 196 | + } |
|
| 197 | + elseif ($this->version == 'v3') { |
|
| 198 | 198 | |
| 199 | - $action = array_get($configuration, 'action', 'homepage'); |
|
| 199 | + $action = array_get($configuration, 'action', 'homepage'); |
|
| 200 | 200 | |
| 201 | - $js_custom_validation = array_get($configuration, 'custom_validation', ''); |
|
| 201 | + $js_custom_validation = array_get($configuration, 'custom_validation', ''); |
|
| 202 | 202 | |
| 203 | - // Check if set custom_validation. That function will override default fetch validation function |
|
| 204 | - if ($js_custom_validation) { |
|
| 203 | + // Check if set custom_validation. That function will override default fetch validation function |
|
| 204 | + if ($js_custom_validation) { |
|
| 205 | 205 | |
| 206 | - $validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : ''; |
|
| 207 | - } |
|
| 208 | - else { |
|
| 206 | + $validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : ''; |
|
| 207 | + } |
|
| 208 | + else { |
|
| 209 | 209 | |
| 210 | - $js_then_callback = array_get($configuration, 'callback_then', ''); |
|
| 211 | - $js_callback_catch = array_get($configuration, 'callback_catch', ''); |
|
| 210 | + $js_then_callback = array_get($configuration, 'callback_then', ''); |
|
| 211 | + $js_callback_catch = array_get($configuration, 'callback_catch', ''); |
|
| 212 | 212 | |
| 213 | - $js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : ''; |
|
| 214 | - $js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : ''; |
|
| 213 | + $js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : ''; |
|
| 214 | + $js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : ''; |
|
| 215 | 215 | |
| 216 | - $validate_function = " |
|
| 216 | + $validate_function = " |
|
| 217 | 217 | fetch('/" . config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name', 'token') . "=' + token, { |
| 218 | 218 | headers: { |
| 219 | 219 | \"X-Requested-With\": \"XMLHttpRequest\", |
@@ -226,9 +226,9 @@ discard block |
||
| 226 | 226 | .catch(function(err) { |
| 227 | 227 | {$js_callback_catch} |
| 228 | 228 | });"; |
| 229 | - } |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $html .= "<script> |
|
| 231 | + $html .= "<script> |
|
| 232 | 232 | var csrfToken = document.head.querySelector('meta[name=\"csrf-token\"]'); |
| 233 | 233 | grecaptcha.ready(function() { |
| 234 | 234 | grecaptcha.execute('{$this->api_site_key}', {action: '{$action}'}).then(function(token) { |
@@ -236,90 +236,90 @@ discard block |
||
| 236 | 236 | }); |
| 237 | 237 | }); |
| 238 | 238 | </script>"; |
| 239 | - } |
|
| 240 | - |
|
| 241 | - return $html; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @param array|null $configuration |
|
| 246 | - * |
|
| 247 | - * @return string |
|
| 248 | - */ |
|
| 249 | - public function htmlScriptTagJsApiV3(?array $configuration = []): string { |
|
| 250 | - |
|
| 251 | - return $this->htmlScriptTagJsApi('', $configuration); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Call out to reCAPTCHA and process the response |
|
| 256 | - * |
|
| 257 | - * @param string $response |
|
| 258 | - * |
|
| 259 | - * @return boolean|array |
|
| 260 | - */ |
|
| 261 | - public function validate($response) { |
|
| 262 | - |
|
| 263 | - if ($this->skip_by_ip) { |
|
| 264 | - if ($this->returnArray()) { |
|
| 265 | - // Add 'skip_by_ip' field to response |
|
| 266 | - return [ |
|
| 267 | - 'skip_by_ip' => true, |
|
| 268 | - 'score' => 0.9, |
|
| 269 | - 'success' => true |
|
| 270 | - ]; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - return true; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $params = http_build_query([ |
|
| 277 | - 'secret' => $this->api_secret_key, |
|
| 278 | - 'remoteip' => request()->getClientIp(), |
|
| 279 | - 'response' => $response, |
|
| 280 | - ]); |
|
| 281 | - |
|
| 282 | - $url = $this->api_url . '?' . $params; |
|
| 283 | - |
|
| 284 | - if (function_exists('curl_version')) { |
|
| 285 | - $curl = curl_init($url); |
|
| 286 | - curl_setopt($curl, CURLOPT_HEADER, false); |
|
| 287 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 288 | - curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout); |
|
| 289 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
| 290 | - $curl_response = curl_exec($curl); |
|
| 291 | - } |
|
| 292 | - else { |
|
| 293 | - $curl_response = file_get_contents($url); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - if (is_null($curl_response) || empty($curl_response)) { |
|
| 297 | - if ($this->returnArray()) { |
|
| 298 | - // Add 'error' field to response |
|
| 299 | - return [ |
|
| 300 | - 'error' => 'cURL response empty', |
|
| 301 | - 'score' => 0.1, |
|
| 302 | - 'success' => false |
|
| 303 | - ]; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - return false; |
|
| 307 | - } |
|
| 308 | - $response = json_decode(trim($curl_response), true); |
|
| 309 | - |
|
| 310 | - if ($this->returnArray()) { |
|
| 311 | - return $response; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $response['success']; |
|
| 315 | - |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @return bool |
|
| 320 | - */ |
|
| 321 | - protected function returnArray(): bool { |
|
| 322 | - |
|
| 323 | - return ($this->version == 'v3'); |
|
| 324 | - } |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + return $html; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @param array|null $configuration |
|
| 246 | + * |
|
| 247 | + * @return string |
|
| 248 | + */ |
|
| 249 | + public function htmlScriptTagJsApiV3(?array $configuration = []): string { |
|
| 250 | + |
|
| 251 | + return $this->htmlScriptTagJsApi('', $configuration); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Call out to reCAPTCHA and process the response |
|
| 256 | + * |
|
| 257 | + * @param string $response |
|
| 258 | + * |
|
| 259 | + * @return boolean|array |
|
| 260 | + */ |
|
| 261 | + public function validate($response) { |
|
| 262 | + |
|
| 263 | + if ($this->skip_by_ip) { |
|
| 264 | + if ($this->returnArray()) { |
|
| 265 | + // Add 'skip_by_ip' field to response |
|
| 266 | + return [ |
|
| 267 | + 'skip_by_ip' => true, |
|
| 268 | + 'score' => 0.9, |
|
| 269 | + 'success' => true |
|
| 270 | + ]; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + return true; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $params = http_build_query([ |
|
| 277 | + 'secret' => $this->api_secret_key, |
|
| 278 | + 'remoteip' => request()->getClientIp(), |
|
| 279 | + 'response' => $response, |
|
| 280 | + ]); |
|
| 281 | + |
|
| 282 | + $url = $this->api_url . '?' . $params; |
|
| 283 | + |
|
| 284 | + if (function_exists('curl_version')) { |
|
| 285 | + $curl = curl_init($url); |
|
| 286 | + curl_setopt($curl, CURLOPT_HEADER, false); |
|
| 287 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 288 | + curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout); |
|
| 289 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
| 290 | + $curl_response = curl_exec($curl); |
|
| 291 | + } |
|
| 292 | + else { |
|
| 293 | + $curl_response = file_get_contents($url); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + if (is_null($curl_response) || empty($curl_response)) { |
|
| 297 | + if ($this->returnArray()) { |
|
| 298 | + // Add 'error' field to response |
|
| 299 | + return [ |
|
| 300 | + 'error' => 'cURL response empty', |
|
| 301 | + 'score' => 0.1, |
|
| 302 | + 'success' => false |
|
| 303 | + ]; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + return false; |
|
| 307 | + } |
|
| 308 | + $response = json_decode(trim($curl_response), true); |
|
| 309 | + |
|
| 310 | + if ($this->returnArray()) { |
|
| 311 | + return $response; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $response['success']; |
|
| 315 | + |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @return bool |
|
| 320 | + */ |
|
| 321 | + protected function returnArray(): bool { |
|
| 322 | + |
|
| 323 | + return ($this->version == 'v3'); |
|
| 324 | + } |
|
| 325 | 325 | } |
| 326 | 326 | \ No newline at end of file |