@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | $this->addValidationRule(); |
| 22 | 22 | $this->publishes([ |
| 23 | - __DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
| 23 | + __DIR__.'/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
| 24 | 24 | ]); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | |
| 35 | 35 | $this->mergeConfigFrom( |
| 36 | - __DIR__ . '/../config/recaptcha.php', 'recaptcha' |
|
| 36 | + __DIR__.'/../config/recaptcha.php', 'recaptcha' |
|
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | 39 | $this->registerReCaptchaBuilder(); |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | protected function registerReCaptchaBuilder() |
| 48 | 48 | { |
| 49 | - $this->app->singleton('recaptcha', function ($app) { |
|
| 50 | - if(config('recaptcha.version') == 'v2') return new ReCaptchaBuilderV2(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.version')); |
|
| 49 | + $this->app->singleton('recaptcha', function($app) { |
|
| 50 | + if (config('recaptcha.version') == 'v2') return new ReCaptchaBuilderV2(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.version')); |
|
| 51 | 51 | else return new ReCaptchaBuilderInvisible(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.version')); |
| 52 | 52 | }); |
| 53 | 53 | } |
@@ -47,8 +47,11 @@ |
||
| 47 | 47 | protected function registerReCaptchaBuilder() |
| 48 | 48 | { |
| 49 | 49 | $this->app->singleton('recaptcha', function ($app) { |
| 50 | - if(config('recaptcha.version') == 'v2') return new ReCaptchaBuilderV2(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.version')); |
|
| 51 | - else return new ReCaptchaBuilderInvisible(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.version')); |
|
| 50 | + if(config('recaptcha.version') == 'v2') { |
|
| 51 | + return new ReCaptchaBuilderV2(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.version')); |
|
| 52 | + } else { |
|
| 53 | + return new ReCaptchaBuilderInvisible(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.version')); |
|
| 54 | + } |
|
| 52 | 55 | }); |
| 53 | 56 | } |
| 54 | 57 | |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | |
| 14 | 14 | class ReCaptchaBuilderInvisible extends ReCaptchaBuilder { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Write HTML <button> tag in your HTML code |
|
| 18 | - * Insert before </form> tag |
|
| 19 | - */ |
|
| 20 | - public function htmlFormButton($buttonInnerHTML = 'Submit') |
|
| 21 | - { |
|
| 22 | - return ($this->version == 'invisible')? '<button class="g-recaptcha" data-sitekey="'.$this->api_site_key.'" data-callback="biscolabLaravelReCaptcha">'.$buttonInnerHTML.'</button>' : ''; |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * Write HTML <button> tag in your HTML code |
|
| 18 | + * Insert before </form> tag |
|
| 19 | + */ |
|
| 20 | + public function htmlFormButton($buttonInnerHTML = 'Submit') |
|
| 21 | + { |
|
| 22 | + return ($this->version == 'invisible')? '<button class="g-recaptcha" data-sitekey="'.$this->api_site_key.'" data-callback="biscolabLaravelReCaptcha">'.$buttonInnerHTML.'</button>' : ''; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function htmlFormButton($buttonInnerHTML = 'Submit') |
| 21 | 21 | { |
| 22 | - return ($this->version == 'invisible')? '<button class="g-recaptcha" data-sitekey="'.$this->api_site_key.'" data-callback="biscolabLaravelReCaptcha">'.$buttonInnerHTML.'</button>' : ''; |
|
| 22 | + return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="'.$this->api_site_key.'" data-callback="biscolabLaravelReCaptcha">'.$buttonInnerHTML.'</button>' : ''; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | |
| 14 | 14 | class ReCaptchaBuilderV2 extends ReCaptchaBuilder { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Write ReCAPTCHA HTML tag in your FORM |
|
| 18 | - * Insert before </form> tag |
|
| 19 | - */ |
|
| 20 | - public function htmlFormSnippet() |
|
| 21 | - { |
|
| 22 | - return ($this->version == 'v2')? '<div class="g-recaptcha" data-sitekey="'.$this->api_site_key.'"></div>' : ''; |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * Write ReCAPTCHA HTML tag in your FORM |
|
| 18 | + * Insert before </form> tag |
|
| 19 | + */ |
|
| 20 | + public function htmlFormSnippet() |
|
| 21 | + { |
|
| 22 | + return ($this->version == 'v2')? '<div class="g-recaptcha" data-sitekey="'.$this->api_site_key.'"></div>' : ''; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function htmlFormSnippet() |
| 21 | 21 | { |
| 22 | - return ($this->version == 'v2')? '<div class="g-recaptcha" data-sitekey="'.$this->api_site_key.'"></div>' : ''; |
|
| 22 | + return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="'.$this->api_site_key.'"></div>' : ''; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -15,66 +15,66 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class ReCaptchaBuilder { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The Site key |
|
| 20 | - * please visit https://developers.google.com/recaptcha/docs/start |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $api_site_key; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * The Secret key |
|
| 27 | - * please visit https://developers.google.com/recaptcha/docs/start |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $api_secret_key; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * The chosen ReCAPTCHA version |
|
| 34 | - * please visit https://developers.google.com/recaptcha/docs/start |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - protected $version; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Whether is true the ReCAPTCHA is inactive |
|
| 41 | - * @var boolean |
|
| 42 | - */ |
|
| 43 | - protected $skip_by_ip = false; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * The API request URI |
|
| 47 | - */ |
|
| 48 | - protected $api_url = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 49 | - |
|
| 50 | - public function __construct($api_site_key, $api_secret_key, $version = 'v2') |
|
| 51 | - { |
|
| 52 | - $this->api_site_key = $api_site_key; |
|
| 53 | - $this->api_secret_key = $api_secret_key; |
|
| 54 | - $this->version = $version; |
|
| 55 | - $this->skip_by_ip = self::skipByIp(); |
|
| 56 | - } |
|
| 18 | + /** |
|
| 19 | + * The Site key |
|
| 20 | + * please visit https://developers.google.com/recaptcha/docs/start |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $api_site_key; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * The Secret key |
|
| 27 | + * please visit https://developers.google.com/recaptcha/docs/start |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $api_secret_key; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * The chosen ReCAPTCHA version |
|
| 34 | + * please visit https://developers.google.com/recaptcha/docs/start |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + protected $version; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Whether is true the ReCAPTCHA is inactive |
|
| 41 | + * @var boolean |
|
| 42 | + */ |
|
| 43 | + protected $skip_by_ip = false; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * The API request URI |
|
| 47 | + */ |
|
| 48 | + protected $api_url = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 49 | + |
|
| 50 | + public function __construct($api_site_key, $api_secret_key, $version = 'v2') |
|
| 51 | + { |
|
| 52 | + $this->api_site_key = $api_site_key; |
|
| 53 | + $this->api_secret_key = $api_secret_key; |
|
| 54 | + $this->version = $version; |
|
| 55 | + $this->skip_by_ip = self::skipByIp(); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Write script HTML tag in you HTML code |
|
| 60 | - * Insert before </head> tag |
|
| 61 | - * |
|
| 62 | - * @param $formId required if you are using invisible ReCaptcha |
|
| 63 | - */ |
|
| 64 | - public function htmlScriptTagJsApi($formId = '') |
|
| 65 | - { |
|
| 66 | - if($this->skip_by_ip) return ''; |
|
| 67 | - $html = "<script src='https://www.google.com/recaptcha/api.js' async defer></script>"; |
|
| 68 | - if($this->version != 'v2'){ |
|
| 69 | - if(!$formId) throw new Exception("formId required", 1); |
|
| 70 | - $html.= '<script> |
|
| 58 | + /** |
|
| 59 | + * Write script HTML tag in you HTML code |
|
| 60 | + * Insert before </head> tag |
|
| 61 | + * |
|
| 62 | + * @param $formId required if you are using invisible ReCaptcha |
|
| 63 | + */ |
|
| 64 | + public function htmlScriptTagJsApi($formId = '') |
|
| 65 | + { |
|
| 66 | + if($this->skip_by_ip) return ''; |
|
| 67 | + $html = "<script src='https://www.google.com/recaptcha/api.js' async defer></script>"; |
|
| 68 | + if($this->version != 'v2'){ |
|
| 69 | + if(!$formId) throw new Exception("formId required", 1); |
|
| 70 | + $html.= '<script> |
|
| 71 | 71 | function biscolabLaravelReCaptcha(token) { |
| 72 | 72 | document.getElementById("'.$formId.'").submit(); |
| 73 | 73 | } |
| 74 | 74 | </script>'; |
| 75 | - } |
|
| 76 | - return $html; |
|
| 77 | - } |
|
| 75 | + } |
|
| 76 | + return $html; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * Call out to reCAPTCHA and process the response |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function validate($response) |
| 87 | 87 | { |
| 88 | - if($this->skip_by_ip) { |
|
| 89 | - return true; |
|
| 90 | - } |
|
| 88 | + if($this->skip_by_ip) { |
|
| 89 | + return true; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | $params = http_build_query([ |
| 93 | 93 | 'secret' => $this->api_secret_key, |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @return boolean |
| 122 | 122 | */ |
| 123 | 123 | public static function skipByIp(){ |
| 124 | - $skip_ip = (config('recaptcha.skip_ip'))? config('recaptcha.skip_ip') : []; |
|
| 125 | - return (in_array(request()->ip(), $skip_ip)); |
|
| 124 | + $skip_ip = (config('recaptcha.skip_ip'))? config('recaptcha.skip_ip') : []; |
|
| 125 | + return (in_array(request()->ip(), $skip_ip)); |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | \ No newline at end of file |
@@ -49,10 +49,10 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | public function __construct($api_site_key, $api_secret_key, $version = 'v2') |
| 51 | 51 | { |
| 52 | - $this->api_site_key = $api_site_key; |
|
| 53 | - $this->api_secret_key = $api_secret_key; |
|
| 54 | - $this->version = $version; |
|
| 55 | - $this->skip_by_ip = self::skipByIp(); |
|
| 52 | + $this->api_site_key = $api_site_key; |
|
| 53 | + $this->api_secret_key = $api_secret_key; |
|
| 54 | + $this->version = $version; |
|
| 55 | + $this->skip_by_ip = self::skipByIp(); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public function htmlScriptTagJsApi($formId = '') |
| 65 | 65 | { |
| 66 | - if($this->skip_by_ip) return ''; |
|
| 66 | + if ($this->skip_by_ip) return ''; |
|
| 67 | 67 | $html = "<script src='https://www.google.com/recaptcha/api.js' async defer></script>"; |
| 68 | - if($this->version != 'v2'){ |
|
| 69 | - if(!$formId) throw new Exception("formId required", 1); |
|
| 70 | - $html.= '<script> |
|
| 68 | + if ($this->version != 'v2') { |
|
| 69 | + if (!$formId) throw new Exception("formId required", 1); |
|
| 70 | + $html .= '<script> |
|
| 71 | 71 | function biscolabLaravelReCaptcha(token) { |
| 72 | 72 | document.getElementById("'.$formId.'").submit(); |
| 73 | 73 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function validate($response) |
| 87 | 87 | { |
| 88 | - if($this->skip_by_ip) { |
|
| 88 | + if ($this->skip_by_ip) { |
|
| 89 | 89 | return true; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | 'response' => $response, |
| 96 | 96 | ]); |
| 97 | 97 | |
| 98 | - $url = $this->api_url. '?' . $params; |
|
| 98 | + $url = $this->api_url.'?'.$params; |
|
| 99 | 99 | |
| 100 | 100 | if (function_exists('curl_version')) { |
| 101 | 101 | $curl = curl_init($url); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } else { |
| 108 | 108 | $curl_response = file_get_contents($url); |
| 109 | 109 | } |
| 110 | - if (is_null($curl_response) || empty( $curl_response )) { |
|
| 110 | + if (is_null($curl_response) || empty($curl_response)) { |
|
| 111 | 111 | return false; |
| 112 | 112 | } |
| 113 | 113 | $response = json_decode(trim($curl_response), true); |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return boolean |
| 122 | 122 | */ |
| 123 | - public static function skipByIp(){ |
|
| 124 | - $skip_ip = (config('recaptcha.skip_ip'))? config('recaptcha.skip_ip') : []; |
|
| 123 | + public static function skipByIp() { |
|
| 124 | + $skip_ip = (config('recaptcha.skip_ip')) ? config('recaptcha.skip_ip') : []; |
|
| 125 | 125 | return (in_array(request()->ip(), $skip_ip)); |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | \ No newline at end of file |
@@ -63,10 +63,14 @@ |
||
| 63 | 63 | */ |
| 64 | 64 | public function htmlScriptTagJsApi($formId = '') |
| 65 | 65 | { |
| 66 | - if($this->skip_by_ip) return ''; |
|
| 66 | + if($this->skip_by_ip) { |
|
| 67 | + return ''; |
|
| 68 | + } |
|
| 67 | 69 | $html = "<script src='https://www.google.com/recaptcha/api.js' async defer></script>"; |
| 68 | 70 | if($this->version != 'v2'){ |
| 69 | - if(!$formId) throw new Exception("formId required", 1); |
|
| 71 | + if(!$formId) { |
|
| 72 | + throw new Exception("formId required", 1); |
|
| 73 | + } |
|
| 70 | 74 | $html.= '<script> |
| 71 | 75 | function biscolabLaravelReCaptcha(token) { |
| 72 | 76 | document.getElementById("'.$formId.'").submit(); |
@@ -13,20 +13,20 @@ |
||
| 13 | 13 | |
| 14 | 14 | return [ |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * |
|
| 18 | - * The site key |
|
| 19 | - * get site key @ www.google.com/recaptcha/admin |
|
| 20 | - * |
|
| 21 | - */ |
|
| 16 | + /** |
|
| 17 | + * |
|
| 18 | + * The site key |
|
| 19 | + * get site key @ www.google.com/recaptcha/admin |
|
| 20 | + * |
|
| 21 | + */ |
|
| 22 | 22 | 'api_site_key' => '', |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * |
|
| 26 | - * The secret key |
|
| 27 | - * get secret key @ www.google.com/recaptcha/admin |
|
| 28 | - * |
|
| 29 | - */ |
|
| 24 | + /** |
|
| 25 | + * |
|
| 26 | + * The secret key |
|
| 27 | + * get secret key @ www.google.com/recaptcha/admin |
|
| 28 | + * |
|
| 29 | + */ |
|
| 30 | 30 | 'api_secret_key' => '', |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | * get more info @ https://developers.google.com/recaptcha/docs/versions |
| 38 | 38 | * |
| 39 | 39 | */ |
| 40 | - 'version' => 'v2' , |
|
| 40 | + 'version' => 'v2', |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * |