@@ -14,166 +14,166 @@ 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 | - * Whether is true the ReCAPTCHA is inactive |
|
| 40 | - * @var boolean |
|
| 41 | - */ |
|
| 42 | - protected $skip_by_ip = false; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * The API request URI |
|
| 46 | - */ |
|
| 47 | - protected $api_url = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 48 | - |
|
| 49 | - public function __construct($api_site_key, $api_secret_key, $version = 'v2') { |
|
| 50 | - |
|
| 51 | - $this->setApiSiteKey($api_site_key); |
|
| 52 | - $this->setApiSecretKey($api_secret_key); |
|
| 53 | - $this->setVersion($version); |
|
| 54 | - $this->setSkipByIp($this->skipByIp()); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $api_site_key |
|
| 59 | - * |
|
| 60 | - * @return ReCaptchaBuilder |
|
| 61 | - */ |
|
| 62 | - public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder { |
|
| 63 | - |
|
| 64 | - $this->api_site_key = $api_site_key; |
|
| 65 | - |
|
| 66 | - return $this; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param string $api_secret_key |
|
| 71 | - * |
|
| 72 | - * @return ReCaptchaBuilder |
|
| 73 | - */ |
|
| 74 | - public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder { |
|
| 75 | - |
|
| 76 | - $this->api_secret_key = $api_secret_key; |
|
| 77 | - |
|
| 78 | - return $this; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param string $version |
|
| 83 | - * |
|
| 84 | - * @return ReCaptchaBuilder |
|
| 85 | - */ |
|
| 86 | - public function setVersion(string $version): ReCaptchaBuilder { |
|
| 87 | - |
|
| 88 | - $this->version = $version; |
|
| 89 | - |
|
| 90 | - return $this; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - public function getVersion(): string { |
|
| 97 | - |
|
| 98 | - return $this->version; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param bool $skip_by_ip |
|
| 103 | - * |
|
| 104 | - * @return ReCaptchaBuilder |
|
| 105 | - */ |
|
| 106 | - public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder { |
|
| 107 | - |
|
| 108 | - $this->skip_by_ip = $skip_by_ip; |
|
| 109 | - |
|
| 110 | - return $this; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Checks whether the user IP address is among IPs "to be skipped" |
|
| 115 | - * |
|
| 116 | - * @return boolean |
|
| 117 | - */ |
|
| 118 | - public function skipByIp(): bool { |
|
| 119 | - |
|
| 120 | - return (in_array(request()->ip(), config('recaptcha.skip_ip', []))); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Write script HTML tag in you HTML code |
|
| 125 | - * Insert before </head> tag |
|
| 126 | - * |
|
| 127 | - * @param string|null $formId |
|
| 128 | - * @param array|null $configuration |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - * @throws Exception |
|
| 132 | - */ |
|
| 133 | - public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string { |
|
| 134 | - |
|
| 135 | - if ($this->skip_by_ip) { |
|
| 136 | - return ''; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - switch ($this->version) { |
|
| 140 | - case 'v3': |
|
| 141 | - $html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>"; |
|
| 142 | - break; |
|
| 143 | - default: |
|
| 144 | - $html = "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>"; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - if ($this->version == 'invisible') { |
|
| 148 | - if (!$formId) { |
|
| 149 | - throw new Exception("formId required", 1); |
|
| 150 | - } |
|
| 151 | - $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 | + * Whether is true the ReCAPTCHA is inactive |
|
| 40 | + * @var boolean |
|
| 41 | + */ |
|
| 42 | + protected $skip_by_ip = false; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * The API request URI |
|
| 46 | + */ |
|
| 47 | + protected $api_url = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 48 | + |
|
| 49 | + public function __construct($api_site_key, $api_secret_key, $version = 'v2') { |
|
| 50 | + |
|
| 51 | + $this->setApiSiteKey($api_site_key); |
|
| 52 | + $this->setApiSecretKey($api_secret_key); |
|
| 53 | + $this->setVersion($version); |
|
| 54 | + $this->setSkipByIp($this->skipByIp()); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $api_site_key |
|
| 59 | + * |
|
| 60 | + * @return ReCaptchaBuilder |
|
| 61 | + */ |
|
| 62 | + public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder { |
|
| 63 | + |
|
| 64 | + $this->api_site_key = $api_site_key; |
|
| 65 | + |
|
| 66 | + return $this; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param string $api_secret_key |
|
| 71 | + * |
|
| 72 | + * @return ReCaptchaBuilder |
|
| 73 | + */ |
|
| 74 | + public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder { |
|
| 75 | + |
|
| 76 | + $this->api_secret_key = $api_secret_key; |
|
| 77 | + |
|
| 78 | + return $this; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param string $version |
|
| 83 | + * |
|
| 84 | + * @return ReCaptchaBuilder |
|
| 85 | + */ |
|
| 86 | + public function setVersion(string $version): ReCaptchaBuilder { |
|
| 87 | + |
|
| 88 | + $this->version = $version; |
|
| 89 | + |
|
| 90 | + return $this; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @return string |
|
| 95 | + */ |
|
| 96 | + public function getVersion(): string { |
|
| 97 | + |
|
| 98 | + return $this->version; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param bool $skip_by_ip |
|
| 103 | + * |
|
| 104 | + * @return ReCaptchaBuilder |
|
| 105 | + */ |
|
| 106 | + public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder { |
|
| 107 | + |
|
| 108 | + $this->skip_by_ip = $skip_by_ip; |
|
| 109 | + |
|
| 110 | + return $this; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Checks whether the user IP address is among IPs "to be skipped" |
|
| 115 | + * |
|
| 116 | + * @return boolean |
|
| 117 | + */ |
|
| 118 | + public function skipByIp(): bool { |
|
| 119 | + |
|
| 120 | + return (in_array(request()->ip(), config('recaptcha.skip_ip', []))); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Write script HTML tag in you HTML code |
|
| 125 | + * Insert before </head> tag |
|
| 126 | + * |
|
| 127 | + * @param string|null $formId |
|
| 128 | + * @param array|null $configuration |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + * @throws Exception |
|
| 132 | + */ |
|
| 133 | + public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string { |
|
| 134 | + |
|
| 135 | + if ($this->skip_by_ip) { |
|
| 136 | + return ''; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + switch ($this->version) { |
|
| 140 | + case 'v3': |
|
| 141 | + $html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>"; |
|
| 142 | + break; |
|
| 143 | + default: |
|
| 144 | + $html = "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>"; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + if ($this->version == 'invisible') { |
|
| 148 | + if (!$formId) { |
|
| 149 | + throw new Exception("formId required", 1); |
|
| 150 | + } |
|
| 151 | + $html .= '<script> |
|
| 152 | 152 | function biscolabLaravelReCaptcha(token) { |
| 153 | 153 | document.getElementById("' . $formId . '").submit(); |
| 154 | 154 | } |
| 155 | 155 | </script>'; |
| 156 | - } |
|
| 157 | - elseif ($this->version == 'v3') { |
|
| 156 | + } |
|
| 157 | + elseif ($this->version == 'v3') { |
|
| 158 | 158 | |
| 159 | - $action = array_get($configuration, 'action', 'homepage'); |
|
| 159 | + $action = array_get($configuration, 'action', 'homepage'); |
|
| 160 | 160 | |
| 161 | - $js_custom_validation = array_get($configuration, 'custom_validation', ''); |
|
| 161 | + $js_custom_validation = array_get($configuration, 'custom_validation', ''); |
|
| 162 | 162 | |
| 163 | - // Check if set custom_validation. That function will override default fetch validation function |
|
| 164 | - if ($js_custom_validation) { |
|
| 163 | + // Check if set custom_validation. That function will override default fetch validation function |
|
| 164 | + if ($js_custom_validation) { |
|
| 165 | 165 | |
| 166 | - $validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : ''; |
|
| 167 | - } |
|
| 168 | - else { |
|
| 166 | + $validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : ''; |
|
| 167 | + } |
|
| 168 | + else { |
|
| 169 | 169 | |
| 170 | - $js_then_callback = array_get($configuration, 'callback_then', ''); |
|
| 171 | - $js_callback_catch = array_get($configuration, 'callback_catch', ''); |
|
| 170 | + $js_then_callback = array_get($configuration, 'callback_then', ''); |
|
| 171 | + $js_callback_catch = array_get($configuration, 'callback_catch', ''); |
|
| 172 | 172 | |
| 173 | - $js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : ''; |
|
| 174 | - $js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : ''; |
|
| 173 | + $js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : ''; |
|
| 174 | + $js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : ''; |
|
| 175 | 175 | |
| 176 | - $validate_function = " |
|
| 176 | + $validate_function = " |
|
| 177 | 177 | fetch('/" . config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name', 'token') . "=' + token, { |
| 178 | 178 | headers: { |
| 179 | 179 | \"X-Requested-With\": \"XMLHttpRequest\", |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | .catch(function(err) { |
| 187 | 187 | {$js_callback_catch} |
| 188 | 188 | });"; |
| 189 | - } |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - $html .= "<script> |
|
| 191 | + $html .= "<script> |
|
| 192 | 192 | var csrfToken = document.head.querySelector('meta[name=\"csrf-token\"]'); |
| 193 | 193 | grecaptcha.ready(function() { |
| 194 | 194 | grecaptcha.execute('{$this->api_site_key}', {action: '{$action}'}).then(function(token) { |
@@ -196,63 +196,63 @@ discard block |
||
| 196 | 196 | }); |
| 197 | 197 | }); |
| 198 | 198 | </script>"; |
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $html; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * @param array|null $configuration |
|
| 206 | - * |
|
| 207 | - * @return string |
|
| 208 | - */ |
|
| 209 | - public function htmlScriptTagJsApiV3(?array $configuration = []): string { |
|
| 210 | - |
|
| 211 | - return $this->htmlScriptTagJsApi('', $configuration); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Call out to reCAPTCHA and process the response |
|
| 216 | - * |
|
| 217 | - * @param string $response |
|
| 218 | - * |
|
| 219 | - * @return boolean |
|
| 220 | - */ |
|
| 221 | - public function validate($response) { |
|
| 222 | - |
|
| 223 | - if ($this->skip_by_ip) { |
|
| 224 | - return true; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $params = http_build_query([ |
|
| 228 | - 'secret' => $this->api_secret_key, |
|
| 229 | - 'remoteip' => request()->getClientIp(), |
|
| 230 | - 'response' => $response, |
|
| 231 | - ]); |
|
| 232 | - |
|
| 233 | - $url = $this->api_url . '?' . $params; |
|
| 234 | - |
|
| 235 | - if (function_exists('curl_version')) { |
|
| 236 | - $curl = curl_init($url); |
|
| 237 | - curl_setopt($curl, CURLOPT_HEADER, false); |
|
| 238 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 239 | - curl_setopt($curl, CURLOPT_TIMEOUT, 1); |
|
| 240 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
| 241 | - $curl_response = curl_exec($curl); |
|
| 242 | - } |
|
| 243 | - else { |
|
| 244 | - $curl_response = file_get_contents($url); |
|
| 245 | - } |
|
| 246 | - if (is_null($curl_response) || empty($curl_response)) { |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 249 | - $response = json_decode(trim($curl_response), true); |
|
| 250 | - |
|
| 251 | - if ($this->version == 'v3') { |
|
| 252 | - return $response; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - return $response['success']; |
|
| 256 | - |
|
| 257 | - } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $html; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * @param array|null $configuration |
|
| 206 | + * |
|
| 207 | + * @return string |
|
| 208 | + */ |
|
| 209 | + public function htmlScriptTagJsApiV3(?array $configuration = []): string { |
|
| 210 | + |
|
| 211 | + return $this->htmlScriptTagJsApi('', $configuration); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Call out to reCAPTCHA and process the response |
|
| 216 | + * |
|
| 217 | + * @param string $response |
|
| 218 | + * |
|
| 219 | + * @return boolean |
|
| 220 | + */ |
|
| 221 | + public function validate($response) { |
|
| 222 | + |
|
| 223 | + if ($this->skip_by_ip) { |
|
| 224 | + return true; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $params = http_build_query([ |
|
| 228 | + 'secret' => $this->api_secret_key, |
|
| 229 | + 'remoteip' => request()->getClientIp(), |
|
| 230 | + 'response' => $response, |
|
| 231 | + ]); |
|
| 232 | + |
|
| 233 | + $url = $this->api_url . '?' . $params; |
|
| 234 | + |
|
| 235 | + if (function_exists('curl_version')) { |
|
| 236 | + $curl = curl_init($url); |
|
| 237 | + curl_setopt($curl, CURLOPT_HEADER, false); |
|
| 238 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 239 | + curl_setopt($curl, CURLOPT_TIMEOUT, 1); |
|
| 240 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
| 241 | + $curl_response = curl_exec($curl); |
|
| 242 | + } |
|
| 243 | + else { |
|
| 244 | + $curl_response = file_get_contents($url); |
|
| 245 | + } |
|
| 246 | + if (is_null($curl_response) || empty($curl_response)) { |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | + $response = json_decode(trim($curl_response), true); |
|
| 250 | + |
|
| 251 | + if ($this->version == 'v3') { |
|
| 252 | + return $response; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + return $response['success']; |
|
| 256 | + |
|
| 257 | + } |
|
| 258 | 258 | } |
| 259 | 259 | \ No newline at end of file |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | $html .= '<script> |
| 152 | 152 | function biscolabLaravelReCaptcha(token) { |
| 153 | - document.getElementById("' . $formId . '").submit(); |
|
| 153 | + document.getElementById("' . $formId.'").submit(); |
|
| 154 | 154 | } |
| 155 | 155 | </script>'; |
| 156 | 156 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : ''; |
| 175 | 175 | |
| 176 | 176 | $validate_function = " |
| 177 | - fetch('/" . config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name', 'token') . "=' + token, { |
|
| 177 | + fetch('/" . config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate')."?".config('recaptcha.default_token_parameter_name', 'token')."=' + token, { |
|
| 178 | 178 | headers: { |
| 179 | 179 | \"X-Requested-With\": \"XMLHttpRequest\", |
| 180 | 180 | \"X-CSRF-TOKEN\": csrfToken.content |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | 'response' => $response, |
| 231 | 231 | ]); |
| 232 | 232 | |
| 233 | - $url = $this->api_url . '?' . $params; |
|
| 233 | + $url = $this->api_url.'?'.$params; |
|
| 234 | 234 | |
| 235 | 235 | if (function_exists('curl_version')) { |
| 236 | 236 | $curl = curl_init($url); |
@@ -153,8 +153,7 @@ discard block |
||
| 153 | 153 | document.getElementById("' . $formId . '").submit(); |
| 154 | 154 | } |
| 155 | 155 | </script>'; |
| 156 | - } |
|
| 157 | - elseif ($this->version == 'v3') { |
|
| 156 | + } elseif ($this->version == 'v3') { |
|
| 158 | 157 | |
| 159 | 158 | $action = array_get($configuration, 'action', 'homepage'); |
| 160 | 159 | |
@@ -164,8 +163,7 @@ discard block |
||
| 164 | 163 | if ($js_custom_validation) { |
| 165 | 164 | |
| 166 | 165 | $validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : ''; |
| 167 | - } |
|
| 168 | - else { |
|
| 166 | + } else { |
|
| 169 | 167 | |
| 170 | 168 | $js_then_callback = array_get($configuration, 'callback_then', ''); |
| 171 | 169 | $js_callback_catch = array_get($configuration, 'callback_catch', ''); |
@@ -239,8 +237,7 @@ discard block |
||
| 239 | 237 | curl_setopt($curl, CURLOPT_TIMEOUT, 1); |
| 240 | 238 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
| 241 | 239 | $curl_response = curl_exec($curl); |
| 242 | - } |
|
| 243 | - else { |
|
| 240 | + } else { |
|
| 244 | 241 | $curl_response = file_get_contents($url); |
| 245 | 242 | } |
| 246 | 243 | if (is_null($curl_response) || empty($curl_response)) { |
@@ -19,88 +19,88 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class ReCaptchaServiceProvider extends ServiceProvider { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Indicates if loading of the provider is deferred. |
|
| 24 | - * |
|
| 25 | - * @var bool |
|
| 26 | - */ |
|
| 27 | - protected $defer = false; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * |
|
| 31 | - */ |
|
| 32 | - public function boot() { |
|
| 33 | - |
|
| 34 | - $this->addValidationRule(); |
|
| 35 | - $this->loadRoutesFrom(__DIR__ . '/routes/routes.php'); |
|
| 36 | - |
|
| 37 | - $this->publishes([ |
|
| 38 | - __DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
| 39 | - ]); |
|
| 40 | - |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Extends Validator to include a recaptcha type |
|
| 45 | - */ |
|
| 46 | - public function addValidationRule() { |
|
| 47 | - |
|
| 48 | - Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) { |
|
| 49 | - |
|
| 50 | - return app('recaptcha')->validate($value); |
|
| 51 | - }, trans('validation.recaptcha')); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Register the service provider. |
|
| 56 | - * |
|
| 57 | - * @return void |
|
| 58 | - */ |
|
| 59 | - public function register() { |
|
| 60 | - |
|
| 61 | - $this->mergeConfigFrom( |
|
| 62 | - __DIR__ . '/../config/recaptcha.php', 'recaptcha' |
|
| 63 | - ); |
|
| 64 | - |
|
| 65 | - $this->registerReCaptchaBuilder(); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Register the HTML builder instance. |
|
| 70 | - * |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - protected function registerReCaptchaBuilder() { |
|
| 74 | - |
|
| 75 | - $this->app->singleton('recaptcha', function ($app) { |
|
| 76 | - |
|
| 77 | - $recaptcha_class = ''; |
|
| 78 | - |
|
| 79 | - switch (config('recaptcha.version')) { |
|
| 80 | - case 'v3' : |
|
| 81 | - $recaptcha_class = ReCaptchaBuilderV3::class; |
|
| 82 | - break; |
|
| 83 | - case 'v2' : |
|
| 84 | - $recaptcha_class = ReCaptchaBuilderV2::class; |
|
| 85 | - break; |
|
| 86 | - case 'invisible': |
|
| 87 | - $recaptcha_class = ReCaptchaBuilderInvisible::class; |
|
| 88 | - break; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return new $recaptcha_class(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key')); |
|
| 92 | - |
|
| 93 | - }); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Get the services provided by the provider. |
|
| 98 | - * |
|
| 99 | - * @return array |
|
| 100 | - */ |
|
| 101 | - public function provides() { |
|
| 102 | - |
|
| 103 | - return ['recaptcha']; |
|
| 104 | - } |
|
| 22 | + /** |
|
| 23 | + * Indicates if loading of the provider is deferred. |
|
| 24 | + * |
|
| 25 | + * @var bool |
|
| 26 | + */ |
|
| 27 | + protected $defer = false; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * |
|
| 31 | + */ |
|
| 32 | + public function boot() { |
|
| 33 | + |
|
| 34 | + $this->addValidationRule(); |
|
| 35 | + $this->loadRoutesFrom(__DIR__ . '/routes/routes.php'); |
|
| 36 | + |
|
| 37 | + $this->publishes([ |
|
| 38 | + __DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
| 39 | + ]); |
|
| 40 | + |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Extends Validator to include a recaptcha type |
|
| 45 | + */ |
|
| 46 | + public function addValidationRule() { |
|
| 47 | + |
|
| 48 | + Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) { |
|
| 49 | + |
|
| 50 | + return app('recaptcha')->validate($value); |
|
| 51 | + }, trans('validation.recaptcha')); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Register the service provider. |
|
| 56 | + * |
|
| 57 | + * @return void |
|
| 58 | + */ |
|
| 59 | + public function register() { |
|
| 60 | + |
|
| 61 | + $this->mergeConfigFrom( |
|
| 62 | + __DIR__ . '/../config/recaptcha.php', 'recaptcha' |
|
| 63 | + ); |
|
| 64 | + |
|
| 65 | + $this->registerReCaptchaBuilder(); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Register the HTML builder instance. |
|
| 70 | + * |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + protected function registerReCaptchaBuilder() { |
|
| 74 | + |
|
| 75 | + $this->app->singleton('recaptcha', function ($app) { |
|
| 76 | + |
|
| 77 | + $recaptcha_class = ''; |
|
| 78 | + |
|
| 79 | + switch (config('recaptcha.version')) { |
|
| 80 | + case 'v3' : |
|
| 81 | + $recaptcha_class = ReCaptchaBuilderV3::class; |
|
| 82 | + break; |
|
| 83 | + case 'v2' : |
|
| 84 | + $recaptcha_class = ReCaptchaBuilderV2::class; |
|
| 85 | + break; |
|
| 86 | + case 'invisible': |
|
| 87 | + $recaptcha_class = ReCaptchaBuilderInvisible::class; |
|
| 88 | + break; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return new $recaptcha_class(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key')); |
|
| 92 | + |
|
| 93 | + }); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Get the services provided by the provider. |
|
| 98 | + * |
|
| 99 | + * @return array |
|
| 100 | + */ |
|
| 101 | + public function provides() { |
|
| 102 | + |
|
| 103 | + return ['recaptcha']; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | } |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | public function boot() { |
| 33 | 33 | |
| 34 | 34 | $this->addValidationRule(); |
| 35 | - $this->loadRoutesFrom(__DIR__ . '/routes/routes.php'); |
|
| 35 | + $this->loadRoutesFrom(__DIR__.'/routes/routes.php'); |
|
| 36 | 36 | |
| 37 | 37 | $this->publishes([ |
| 38 | - __DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
| 38 | + __DIR__.'/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
| 39 | 39 | ]); |
| 40 | 40 | |
| 41 | 41 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function addValidationRule() { |
| 47 | 47 | |
| 48 | - Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) { |
|
| 48 | + Validator::extendImplicit('recaptcha', function($attribute, $value, $parameters, $validator) { |
|
| 49 | 49 | |
| 50 | 50 | return app('recaptcha')->validate($value); |
| 51 | 51 | }, trans('validation.recaptcha')); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | public function register() { |
| 60 | 60 | |
| 61 | 61 | $this->mergeConfigFrom( |
| 62 | - __DIR__ . '/../config/recaptcha.php', 'recaptcha' |
|
| 62 | + __DIR__.'/../config/recaptcha.php', 'recaptcha' |
|
| 63 | 63 | ); |
| 64 | 64 | |
| 65 | 65 | $this->registerReCaptchaBuilder(); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | protected function registerReCaptchaBuilder() { |
| 74 | 74 | |
| 75 | - $this->app->singleton('recaptcha', function ($app) { |
|
| 75 | + $this->app->singleton('recaptcha', function($app) { |
|
| 76 | 76 | |
| 77 | 77 | $recaptcha_class = ''; |
| 78 | 78 | |