@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 | /** |