Completed
Push — master ( 7b9b82...f4954a )
by Roberto
07:53 queued 11s
created
src/Facades/ReCaptcha.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -19,14 +19,14 @@
 block discarded – undo
19 19
 class ReCaptcha extends Facade
20 20
 {
21 21
 
22
-	/**
23
-	 * Get the registered name of the component.
24
-	 *
25
-	 * @return string
26
-	 */
27
-	protected static function getFacadeAccessor()
28
-	{
22
+    /**
23
+     * Get the registered name of the component.
24
+     *
25
+     * @return string
26
+     */
27
+    protected static function getFacadeAccessor()
28
+    {
29 29
 
30
-		return 'recaptcha';
31
-	}
30
+        return 'recaptcha';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
src/ReCaptchaBuilderInvisible.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -17,30 +17,30 @@
 block discarded – undo
17 17
 class ReCaptchaBuilderInvisible extends ReCaptchaBuilder
18 18
 {
19 19
 
20
-	/**
21
-	 * ReCaptchaBuilderInvisible constructor.
22
-	 *
23
-	 * @param string $api_site_key
24
-	 * @param string $api_secret_key
25
-	 */
26
-	public function __construct(string $api_site_key, string $api_secret_key)
27
-	{
20
+    /**
21
+     * ReCaptchaBuilderInvisible constructor.
22
+     *
23
+     * @param string $api_site_key
24
+     * @param string $api_secret_key
25
+     */
26
+    public function __construct(string $api_site_key, string $api_secret_key)
27
+    {
28 28
 
29
-		parent::__construct($api_site_key, $api_secret_key, 'invisible');
30
-	}
29
+        parent::__construct($api_site_key, $api_secret_key, 'invisible');
30
+    }
31 31
 
32
-	/**
33
-	 * Write HTML <button> tag in your HTML code
34
-	 * Insert before </form> tag
35
-	 *
36
-	 * @param string $buttonInnerHTML
37
-	 *
38
-	 * @return string
39
-	 */
40
-	public function htmlFormButton($buttonInnerHTML = 'Submit'): string
41
-	{
32
+    /**
33
+     * Write HTML <button> tag in your HTML code
34
+     * Insert before </form> tag
35
+     *
36
+     * @param string $buttonInnerHTML
37
+     *
38
+     * @return string
39
+     */
40
+    public function htmlFormButton($buttonInnerHTML = 'Submit'): string
41
+    {
42 42
 
43
-		return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : '';
44
-	}
43
+        return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : '';
44
+    }
45 45
 
46 46
 }
47 47
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
 	public function htmlFormButton($buttonInnerHTML = 'Submit'): string
41 41
 	{
42 42
 
43
-		return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : '';
43
+		return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="'.$this->api_site_key.'" data-callback="biscolabLaravelReCaptcha">'.$buttonInnerHTML.'</button>' : '';
44 44
 	}
45 45
 
46 46
 }
47 47
\ No newline at end of file
Please login to merge, or discard this patch.
src/Controllers/ReCaptchaController.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,14 +19,14 @@
 block discarded – undo
19 19
 class ReCaptchaController extends Controller
20 20
 {
21 21
 
22
-	/**
23
-	 * @return array
24
-	 */
25
-	public function validateV3(): array
26
-	{
22
+    /**
23
+     * @return array
24
+     */
25
+    public function validateV3(): array
26
+    {
27 27
 
28
-		$token = request()->input(config('recaptcha.default_token_parameter_name', 'token'), '');
28
+        $token = request()->input(config('recaptcha.default_token_parameter_name', 'token'), '');
29 29
 
30
-		return recaptcha()->validate($token);
31
-	}
30
+        return recaptcha()->validate($token);
31
+    }
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
src/helpers.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@  discard block
 block discarded – undo
11 11
 use Biscolab\ReCaptcha\Facades\ReCaptcha;
12 12
 
13 13
 if (!function_exists('recaptcha')) {
14
-	/**
15
-	 * @return Biscolab\ReCaptcha\ReCaptchaBuilder
16
-	 */
17
-	function recaptcha()
18
-	{
19
-
20
-		return app('recaptcha');
21
-	}
14
+    /**
15
+     * @return Biscolab\ReCaptcha\ReCaptchaBuilder
16
+     */
17
+    function recaptcha()
18
+    {
19
+
20
+        return app('recaptcha');
21
+    }
22 22
 }
23 23
 
24 24
 /**
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
  */
31 31
 if (!function_exists('htmlScriptTagJsApi')) {
32 32
 
33
-	/**
34
-	 * @param string $formId
35
-	 *
36
-	 * @return string
37
-	 */
38
-	function htmlScriptTagJsApi($formId = ''): string
39
-	{
33
+    /**
34
+     * @param string $formId
35
+     *
36
+     * @return string
37
+     */
38
+    function htmlScriptTagJsApi($formId = ''): string
39
+    {
40 40
 
41
-		return ReCaptcha::htmlScriptTagJsApi($formId);
42
-	}
41
+        return ReCaptcha::htmlScriptTagJsApi($formId);
42
+    }
43 43
 }
44 44
 
45 45
 /**
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
51 51
  */
52 52
 if (!function_exists('htmlScriptTagJsApiV3')) {
53 53
 
54
-	/**
55
-	 * @param array $config
56
-	 *
57
-	 * @return string
58
-	 */
59
-	function htmlScriptTagJsApiV3($config = []): string
60
-	{
54
+    /**
55
+     * @param array $config
56
+     *
57
+     * @return string
58
+     */
59
+    function htmlScriptTagJsApiV3($config = []): string
60
+    {
61 61
 
62
-		return ReCaptcha::htmlScriptTagJsApiV3($config);
63
-	}
62
+        return ReCaptcha::htmlScriptTagJsApiV3($config);
63
+    }
64 64
 }
65 65
 
66 66
 /**
@@ -74,16 +74,16 @@  discard block
 block discarded – undo
74 74
  */
75 75
 if (!function_exists('htmlFormButton')) {
76 76
 
77
-	/**
78
-	 * @param null|string $buttonInnerHTML
79
-	 *
80
-	 * @return string
81
-	 */
82
-	function htmlFormButton(?string $buttonInnerHTML = 'Submit'): string
83
-	{
77
+    /**
78
+     * @param null|string $buttonInnerHTML
79
+     *
80
+     * @return string
81
+     */
82
+    function htmlFormButton(?string $buttonInnerHTML = 'Submit'): string
83
+    {
84 84
 
85
-		return ReCaptcha::htmlFormButton($buttonInnerHTML);
86
-	}
85
+        return ReCaptcha::htmlFormButton($buttonInnerHTML);
86
+    }
87 87
 }
88 88
 
89 89
 /**
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
  */
96 96
 if (!function_exists('htmlFormSnippet')) {
97 97
 
98
-	/**
99
-	 * @return string
100
-	 */
101
-	function htmlFormSnippet(): string
102
-	{
98
+    /**
99
+     * @return string
100
+     */
101
+    function htmlFormSnippet(): string
102
+    {
103 103
 
104
-		return ReCaptcha::htmlFormSnippet();
105
-	}
104
+        return ReCaptcha::htmlFormSnippet();
105
+    }
106 106
 }
107 107
 
Please login to merge, or discard this patch.
src/ReCaptchaBuilder.php 2 patches
Indentation   +312 added lines, -312 removed lines patch added patch discarded remove patch
@@ -20,221 +20,221 @@  discard block
 block discarded – undo
20 20
 class ReCaptchaBuilder
21 21
 {
22 22
 
23
-	/**
24
-	 * @var string
25
-	 */
26
-	const DEFAULT_API_VERSION = 'v2';
27
-
28
-	/**
29
-	 * @var int
30
-	 */
31
-	const DEFAULT_CURL_TIMEOUT = 10;
32
-
33
-	/**
34
-	 * The Site key
35
-	 * please visit https://developers.google.com/recaptcha/docs/start
36
-	 * @var string
37
-	 */
38
-	protected $api_site_key;
39
-
40
-	/**
41
-	 * The Secret key
42
-	 * please visit https://developers.google.com/recaptcha/docs/start
43
-	 * @var string
44
-	 */
45
-	protected $api_secret_key;
46
-
47
-	/**
48
-	 * The chosen ReCAPTCHA version
49
-	 * please visit https://developers.google.com/recaptcha/docs/start
50
-	 * @var string
51
-	 */
52
-	protected $version;
53
-
54
-	/**
55
-	 * Whether is true the ReCAPTCHA is inactive
56
-	 * @var boolean
57
-	 */
58
-	protected $skip_by_ip = false;
59
-
60
-	/**
61
-	 * The API request URI
62
-	 */
63
-	protected $api_url = 'https://www.google.com/recaptcha/api/siteverify';
64
-
65
-	/**
66
-	 * ReCaptchaBuilder constructor.
67
-	 *
68
-	 * @param string      $api_site_key
69
-	 * @param string      $api_secret_key
70
-	 * @param null|string $version
71
-	 */
72
-	public function __construct(
73
-		string $api_site_key,
74
-		string $api_secret_key,
75
-		?string $version = self::DEFAULT_API_VERSION
76
-	) {
77
-
78
-		$this->setApiSiteKey($api_site_key);
79
-		$this->setApiSecretKey($api_secret_key);
80
-		$this->setVersion($version);
81
-		$this->setSkipByIp($this->skipByIp());
82
-	}
83
-
84
-	/**
85
-	 * @param string $api_site_key
86
-	 *
87
-	 * @return ReCaptchaBuilder
88
-	 */
89
-	public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder
90
-	{
91
-
92
-		$this->api_site_key = $api_site_key;
93
-
94
-		return $this;
95
-	}
96
-
97
-	/**
98
-	 * @param string $api_secret_key
99
-	 *
100
-	 * @return ReCaptchaBuilder
101
-	 */
102
-	public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder
103
-	{
104
-
105
-		$this->api_secret_key = $api_secret_key;
106
-
107
-		return $this;
108
-	}
109
-
110
-	/**
111
-	 * @return int
112
-	 */
113
-	public function getCurlTimeout(): int
114
-	{
115
-
116
-		return config('recaptcha.curl_timeout', self::DEFAULT_CURL_TIMEOUT);
117
-	}
118
-
119
-	/**
120
-	 * @param string $version
121
-	 *
122
-	 * @return ReCaptchaBuilder
123
-	 */
124
-	public function setVersion(string $version): ReCaptchaBuilder
125
-	{
126
-
127
-		$this->version = $version;
128
-
129
-		return $this;
130
-	}
131
-
132
-	/**
133
-	 * @return string
134
-	 */
135
-	public function getVersion(): string
136
-	{
137
-
138
-		return $this->version;
139
-	}
140
-
141
-	/**
142
-	 * @param bool $skip_by_ip
143
-	 *
144
-	 * @return ReCaptchaBuilder
145
-	 */
146
-	public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder
147
-	{
148
-
149
-		$this->skip_by_ip = $skip_by_ip;
150
-
151
-		return $this;
152
-	}
153
-
154
-	/**
155
-	 * @return array|mixed
156
-	 */
157
-	public function getIpWhitelist()
158
-	{
159
-
160
-		$whitelist = config('recaptcha.skip_ip', []);
161
-
162
-		if (!is_array($whitelist)) {
163
-			$whitelist = explode(',', $whitelist);
164
-		}
165
-
166
-		return $whitelist;
167
-	}
168
-
169
-	/**
170
-	 * Checks whether the user IP address is among IPs "to be skipped"
171
-	 *
172
-	 * @return boolean
173
-	 */
174
-	public function skipByIp(): bool
175
-	{
176
-
177
-		return (in_array(request()->ip(), $this->getIpWhitelist()));
178
-	}
179
-
180
-	/**
181
-	 * Write script HTML tag in you HTML code
182
-	 * Insert before </head> tag
183
-	 *
184
-	 * @param string|null $formId
185
-	 * @param array|null  $configuration
186
-	 *
187
-	 * @return string
188
-	 * @throws Exception
189
-	 */
190
-	public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string
191
-	{
192
-
193
-		if ($this->skip_by_ip) {
194
-			return '';
195
-		}
196
-
197
-		switch ($this->version) {
198
-			case 'v3':
199
-				$html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>";
200
-				break;
201
-			default:
202
-				$language = config('recaptcha.default_language', null);
203
-				$query = ($language) ? "?hl=" . $language : "";
204
-				$html = "<script src=\"https://www.google.com/recaptcha/api.js" . $query . "\" async defer></script>";
205
-		}
206
-
207
-		if ($this->version == 'invisible') {
208
-			if (!$formId) {
209
-				throw new Exception("formId required", 1);
210
-			}
211
-			$html .= '<script>
23
+    /**
24
+     * @var string
25
+     */
26
+    const DEFAULT_API_VERSION = 'v2';
27
+
28
+    /**
29
+     * @var int
30
+     */
31
+    const DEFAULT_CURL_TIMEOUT = 10;
32
+
33
+    /**
34
+     * The Site key
35
+     * please visit https://developers.google.com/recaptcha/docs/start
36
+     * @var string
37
+     */
38
+    protected $api_site_key;
39
+
40
+    /**
41
+     * The Secret key
42
+     * please visit https://developers.google.com/recaptcha/docs/start
43
+     * @var string
44
+     */
45
+    protected $api_secret_key;
46
+
47
+    /**
48
+     * The chosen ReCAPTCHA version
49
+     * please visit https://developers.google.com/recaptcha/docs/start
50
+     * @var string
51
+     */
52
+    protected $version;
53
+
54
+    /**
55
+     * Whether is true the ReCAPTCHA is inactive
56
+     * @var boolean
57
+     */
58
+    protected $skip_by_ip = false;
59
+
60
+    /**
61
+     * The API request URI
62
+     */
63
+    protected $api_url = 'https://www.google.com/recaptcha/api/siteverify';
64
+
65
+    /**
66
+     * ReCaptchaBuilder constructor.
67
+     *
68
+     * @param string      $api_site_key
69
+     * @param string      $api_secret_key
70
+     * @param null|string $version
71
+     */
72
+    public function __construct(
73
+        string $api_site_key,
74
+        string $api_secret_key,
75
+        ?string $version = self::DEFAULT_API_VERSION
76
+    ) {
77
+
78
+        $this->setApiSiteKey($api_site_key);
79
+        $this->setApiSecretKey($api_secret_key);
80
+        $this->setVersion($version);
81
+        $this->setSkipByIp($this->skipByIp());
82
+    }
83
+
84
+    /**
85
+     * @param string $api_site_key
86
+     *
87
+     * @return ReCaptchaBuilder
88
+     */
89
+    public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder
90
+    {
91
+
92
+        $this->api_site_key = $api_site_key;
93
+
94
+        return $this;
95
+    }
96
+
97
+    /**
98
+     * @param string $api_secret_key
99
+     *
100
+     * @return ReCaptchaBuilder
101
+     */
102
+    public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder
103
+    {
104
+
105
+        $this->api_secret_key = $api_secret_key;
106
+
107
+        return $this;
108
+    }
109
+
110
+    /**
111
+     * @return int
112
+     */
113
+    public function getCurlTimeout(): int
114
+    {
115
+
116
+        return config('recaptcha.curl_timeout', self::DEFAULT_CURL_TIMEOUT);
117
+    }
118
+
119
+    /**
120
+     * @param string $version
121
+     *
122
+     * @return ReCaptchaBuilder
123
+     */
124
+    public function setVersion(string $version): ReCaptchaBuilder
125
+    {
126
+
127
+        $this->version = $version;
128
+
129
+        return $this;
130
+    }
131
+
132
+    /**
133
+     * @return string
134
+     */
135
+    public function getVersion(): string
136
+    {
137
+
138
+        return $this->version;
139
+    }
140
+
141
+    /**
142
+     * @param bool $skip_by_ip
143
+     *
144
+     * @return ReCaptchaBuilder
145
+     */
146
+    public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder
147
+    {
148
+
149
+        $this->skip_by_ip = $skip_by_ip;
150
+
151
+        return $this;
152
+    }
153
+
154
+    /**
155
+     * @return array|mixed
156
+     */
157
+    public function getIpWhitelist()
158
+    {
159
+
160
+        $whitelist = config('recaptcha.skip_ip', []);
161
+
162
+        if (!is_array($whitelist)) {
163
+            $whitelist = explode(',', $whitelist);
164
+        }
165
+
166
+        return $whitelist;
167
+    }
168
+
169
+    /**
170
+     * Checks whether the user IP address is among IPs "to be skipped"
171
+     *
172
+     * @return boolean
173
+     */
174
+    public function skipByIp(): bool
175
+    {
176
+
177
+        return (in_array(request()->ip(), $this->getIpWhitelist()));
178
+    }
179
+
180
+    /**
181
+     * Write script HTML tag in you HTML code
182
+     * Insert before </head> tag
183
+     *
184
+     * @param string|null $formId
185
+     * @param array|null  $configuration
186
+     *
187
+     * @return string
188
+     * @throws Exception
189
+     */
190
+    public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string
191
+    {
192
+
193
+        if ($this->skip_by_ip) {
194
+            return '';
195
+        }
196
+
197
+        switch ($this->version) {
198
+            case 'v3':
199
+                $html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>";
200
+                break;
201
+            default:
202
+                $language = config('recaptcha.default_language', null);
203
+                $query = ($language) ? "?hl=" . $language : "";
204
+                $html = "<script src=\"https://www.google.com/recaptcha/api.js" . $query . "\" async defer></script>";
205
+        }
206
+
207
+        if ($this->version == 'invisible') {
208
+            if (!$formId) {
209
+                throw new Exception("formId required", 1);
210
+            }
211
+            $html .= '<script>
212 212
 		       function biscolabLaravelReCaptcha(token) {
213 213
 		         document.getElementById("' . $formId . '").submit();
214 214
 		       }
215 215
 		     </script>';
216
-		} elseif ($this->version == 'v3') {
216
+        } elseif ($this->version == 'v3') {
217 217
 
218
-			$action = Arr::get($configuration, 'action', 'homepage');
218
+            $action = Arr::get($configuration, 'action', 'homepage');
219 219
 
220
-			$js_custom_validation = Arr::get($configuration, 'custom_validation', '');
220
+            $js_custom_validation = Arr::get($configuration, 'custom_validation', '');
221 221
 
222
-			// Check if set custom_validation. That function will override default fetch validation function
223
-			if ($js_custom_validation) {
222
+            // Check if set custom_validation. That function will override default fetch validation function
223
+            if ($js_custom_validation) {
224 224
 
225
-				$validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : '';
226
-			} else {
225
+                $validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : '';
226
+            } else {
227 227
 
228
-				$js_then_callback = Arr::get($configuration, 'callback_then', '');
229
-				$js_callback_catch = Arr::get($configuration, 'callback_catch', '');
228
+                $js_then_callback = Arr::get($configuration, 'callback_then', '');
229
+                $js_callback_catch = Arr::get($configuration, 'callback_catch', '');
230 230
 
231
-				$js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : '';
232
-				$js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : '';
231
+                $js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : '';
232
+                $js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : '';
233 233
 
234
-				$validate_function = "
234
+                $validate_function = "
235 235
                 fetch('/" . config('recaptcha.default_validation_route',
236
-						'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name',
237
-						'token') . "=' + token, {
236
+                        'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name',
237
+                        'token') . "=' + token, {
238 238
                     headers: {
239 239
                         \"X-Requested-With\": \"XMLHttpRequest\",
240 240
                         \"X-CSRF-TOKEN\": csrfToken.content
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
                 .catch(function(err) {
247 247
                     {$js_callback_catch}
248 248
                 });";
249
-			}
249
+            }
250 250
 
251
-			$html .= "<script>
251
+            $html .= "<script>
252 252
                     var csrfToken = document.head.querySelector('meta[name=\"csrf-token\"]');
253 253
                   grecaptcha.ready(function() {
254 254
                       grecaptcha.execute('{$this->api_site_key}', {action: '{$action}'}).then(function(token) {
@@ -256,111 +256,111 @@  discard block
 block discarded – undo
256 256
                       });
257 257
                   });
258 258
 		     </script>";
259
-		}
260
-
261
-		return $html;
262
-	}
263
-
264
-	/**
265
-	 * @param array|null $configuration
266
-	 *
267
-	 * @return string
268
-	 */
269
-	public function htmlScriptTagJsApiV3(?array $configuration = []): string
270
-	{
271
-
272
-		return $this->htmlScriptTagJsApi('', $configuration);
273
-	}
274
-
275
-	/**
276
-	 * Call out to reCAPTCHA and process the response
277
-	 *
278
-	 * @param string $response
279
-	 *
280
-	 * @return boolean|array
281
-	 */
282
-	public function validate($response)
283
-	{
284
-
285
-		if ($this->skip_by_ip) {
286
-			if ($this->returnArray()) {
287
-				// Add 'skip_by_ip' field to response
288
-				return [
289
-					'skip_by_ip' => true,
290
-					'score'      => 0.9,
291
-					'success'    => true
292
-				];
293
-			}
294
-
295
-			return true;
296
-		}
297
-
298
-		$params = http_build_query([
299
-			'secret'   => $this->api_secret_key,
300
-			'remoteip' => request()->getClientIp(),
301
-			'response' => $response,
302
-		]);
303
-
304
-		$url = $this->api_url . '?' . $params;
305
-
306
-		if (function_exists('curl_version')) {
307
-
308
-			$curl = curl_init($url);
309
-			curl_setopt($curl, CURLOPT_HEADER, false);
310
-			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
311
-			curl_setopt($curl, CURLOPT_TIMEOUT, $this->getCurlTimeout());
312
-			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
313
-			$curl_response = curl_exec($curl);
314
-		} else {
315
-			$curl_response = file_get_contents($url);
316
-		}
317
-
318
-		if (is_null($curl_response) || empty($curl_response)) {
319
-			if ($this->returnArray()) {
320
-				// Add 'error' field to response
321
-				return [
322
-					'error'   => 'cURL response empty',
323
-					'score'   => 0.1,
324
-					'success' => false
325
-				];
326
-			}
327
-
328
-			return false;
329
-		}
330
-		$response = json_decode(trim($curl_response), true);
331
-
332
-		if ($this->returnArray()) {
333
-			return $response;
334
-		}
335
-
336
-		return $response['success'];
337
-
338
-	}
339
-
340
-	/**
341
-	 * @return string
342
-	 */
343
-	public function getApiSiteKey(): string
344
-	{
345
-
346
-		return $this->api_site_key;
347
-	}
348
-
349
-	/**
350
-	 * @return string
351
-	 */
352
-	public function getApiSecretKey(): string
353
-	{
354
-
355
-		return $this->api_secret_key;
356
-	}
357
-
358
-	/**
359
-	 * @return bool
360
-	 */
361
-	protected function returnArray(): bool
362
-	{
363
-
364
-		return ($this->version == 'v3');
365
-	}
259
+        }
260
+
261
+        return $html;
262
+    }
263
+
264
+    /**
265
+     * @param array|null $configuration
266
+     *
267
+     * @return string
268
+     */
269
+    public function htmlScriptTagJsApiV3(?array $configuration = []): string
270
+    {
271
+
272
+        return $this->htmlScriptTagJsApi('', $configuration);
273
+    }
274
+
275
+    /**
276
+     * Call out to reCAPTCHA and process the response
277
+     *
278
+     * @param string $response
279
+     *
280
+     * @return boolean|array
281
+     */
282
+    public function validate($response)
283
+    {
284
+
285
+        if ($this->skip_by_ip) {
286
+            if ($this->returnArray()) {
287
+                // Add 'skip_by_ip' field to response
288
+                return [
289
+                    'skip_by_ip' => true,
290
+                    'score'      => 0.9,
291
+                    'success'    => true
292
+                ];
293
+            }
294
+
295
+            return true;
296
+        }
297
+
298
+        $params = http_build_query([
299
+            'secret'   => $this->api_secret_key,
300
+            'remoteip' => request()->getClientIp(),
301
+            'response' => $response,
302
+        ]);
303
+
304
+        $url = $this->api_url . '?' . $params;
305
+
306
+        if (function_exists('curl_version')) {
307
+
308
+            $curl = curl_init($url);
309
+            curl_setopt($curl, CURLOPT_HEADER, false);
310
+            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
311
+            curl_setopt($curl, CURLOPT_TIMEOUT, $this->getCurlTimeout());
312
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
313
+            $curl_response = curl_exec($curl);
314
+        } else {
315
+            $curl_response = file_get_contents($url);
316
+        }
317
+
318
+        if (is_null($curl_response) || empty($curl_response)) {
319
+            if ($this->returnArray()) {
320
+                // Add 'error' field to response
321
+                return [
322
+                    'error'   => 'cURL response empty',
323
+                    'score'   => 0.1,
324
+                    'success' => false
325
+                ];
326
+            }
327
+
328
+            return false;
329
+        }
330
+        $response = json_decode(trim($curl_response), true);
331
+
332
+        if ($this->returnArray()) {
333
+            return $response;
334
+        }
335
+
336
+        return $response['success'];
337
+
338
+    }
339
+
340
+    /**
341
+     * @return string
342
+     */
343
+    public function getApiSiteKey(): string
344
+    {
345
+
346
+        return $this->api_site_key;
347
+    }
348
+
349
+    /**
350
+     * @return string
351
+     */
352
+    public function getApiSecretKey(): string
353
+    {
354
+
355
+        return $this->api_secret_key;
356
+    }
357
+
358
+    /**
359
+     * @return bool
360
+     */
361
+    protected function returnArray(): bool
362
+    {
363
+
364
+        return ($this->version == 'v3');
365
+    }
366 366
 }
367 367
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 				break;
201 201
 			default:
202 202
 				$language = config('recaptcha.default_language', null);
203
-				$query = ($language) ? "?hl=" . $language : "";
204
-				$html = "<script src=\"https://www.google.com/recaptcha/api.js" . $query . "\" async defer></script>";
203
+				$query = ($language) ? "?hl=".$language : "";
204
+				$html = "<script src=\"https://www.google.com/recaptcha/api.js".$query."\" async defer></script>";
205 205
 		}
206 206
 
207 207
 		if ($this->version == 'invisible') {
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 			}
211 211
 			$html .= '<script>
212 212
 		       function biscolabLaravelReCaptcha(token) {
213
-		         document.getElementById("' . $formId . '").submit();
213
+		         document.getElementById("' . $formId.'").submit();
214 214
 		       }
215 215
 		     </script>';
216 216
 		} elseif ($this->version == 'v3') {
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
 
234 234
 				$validate_function = "
235 235
                 fetch('/" . config('recaptcha.default_validation_route',
236
-						'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name',
237
-						'token') . "=' + token, {
236
+						'biscolab-recaptcha/validate')."?".config('recaptcha.default_token_parameter_name',
237
+						'token')."=' + token, {
238 238
                     headers: {
239 239
                         \"X-Requested-With\": \"XMLHttpRequest\",
240 240
                         \"X-CSRF-TOKEN\": csrfToken.content
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 			'response' => $response,
302 302
 		]);
303 303
 
304
-		$url = $this->api_url . '?' . $params;
304
+		$url = $this->api_url.'?'.$params;
305 305
 
306 306
 		if (function_exists('curl_version')) {
307 307
 
Please login to merge, or discard this patch.
config/recaptcha.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -13,70 +13,70 @@
 block discarded – undo
13 13
  */
14 14
 return [
15 15
 
16
-	/**
17
-	 *
18
-	 * The site key
19
-	 * get site key @ www.google.com/recaptcha/admin
20
-	 *
21
-	 */
22
-	'api_site_key'                 => env('RECAPTCHA_SITE_KEY', ''),
16
+    /**
17
+     *
18
+     * The site key
19
+     * get site key @ www.google.com/recaptcha/admin
20
+     *
21
+     */
22
+    'api_site_key'                 => env('RECAPTCHA_SITE_KEY', ''),
23 23
 
24
-	/**
25
-	 *
26
-	 * The secret key
27
-	 * get secret key @ www.google.com/recaptcha/admin
28
-	 *
29
-	 */
30
-	'api_secret_key'               => env('RECAPTCHA_SECRET_KEY', ''),
24
+    /**
25
+     *
26
+     * The secret key
27
+     * get secret key @ www.google.com/recaptcha/admin
28
+     *
29
+     */
30
+    'api_secret_key'               => env('RECAPTCHA_SECRET_KEY', ''),
31 31
 
32
-	/**
33
-	 *
34
-	 * ReCATCHA version
35
-	 * Supported: "v2", "invisible", "v3",
36
-	 *
37
-	 * get more info @ https://developers.google.com/recaptcha/docs/versions
38
-	 *
39
-	 */
40
-	'version'                      => env('RECAPTCHA_DEFAULT_VERSION', 'v2'),
32
+    /**
33
+     *
34
+     * ReCATCHA version
35
+     * Supported: "v2", "invisible", "v3",
36
+     *
37
+     * get more info @ https://developers.google.com/recaptcha/docs/versions
38
+     *
39
+     */
40
+    'version'                      => env('RECAPTCHA_DEFAULT_VERSION', 'v2'),
41 41
 
42
-	/**
43
-	 *
44
-	 * The curl timout in seconds to validate a recaptcha token
45
-	 * @since v3.5.0
46
-	 *
47
-	 */
48
-	'curl_timeout'                 => env('RECAPTCHA_CURL_TIMEOUT', 10),
42
+    /**
43
+     *
44
+     * The curl timout in seconds to validate a recaptcha token
45
+     * @since v3.5.0
46
+     *
47
+     */
48
+    'curl_timeout'                 => env('RECAPTCHA_CURL_TIMEOUT', 10),
49 49
 
50
-	/**
51
-	 *
52
-	 * IP addresses for which validation will be skipped
53
-	 *
54
-	 */
55
-	'skip_ip'                      => [],
50
+    /**
51
+     *
52
+     * IP addresses for which validation will be skipped
53
+     *
54
+     */
55
+    'skip_ip'                      => [],
56 56
 
57
-	/**
58
-	 *
59
-	 * Default route called to check the Google reCAPTCHA token
60
-	 * @since v3.2.0
61
-	 *
62
-	 */
63
-	'default_validation_route'     => env('RECAPTCHA_DEFAULT_VALIDATION_ROUTE', 'biscolab-recaptcha/validate'),
57
+    /**
58
+     *
59
+     * Default route called to check the Google reCAPTCHA token
60
+     * @since v3.2.0
61
+     *
62
+     */
63
+    'default_validation_route'     => env('RECAPTCHA_DEFAULT_VALIDATION_ROUTE', 'biscolab-recaptcha/validate'),
64 64
 
65
-	/**
66
-	 *
67
-	 * The name of the parameter used to send Google reCAPTCHA token to verify route
68
-	 * @since v3.2.0
69
-	 *
70
-	 */
71
-	'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token'),
65
+    /**
66
+     *
67
+     * The name of the parameter used to send Google reCAPTCHA token to verify route
68
+     * @since v3.2.0
69
+     *
70
+     */
71
+    'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token'),
72 72
 
73
-	/**
74
-	 *
75
-	 * The default Google reCAPTCHA language code
76
-	 * It has no effect with v3
77
-	 * @see   https://developers.google.com/recaptcha/docs/language
78
-	 * @since v3.6.0
79
-	 *
80
-	 */
81
-	'default_language'             => env('RECAPTCHA_DEFAULT_LANGUAGE', null)
73
+    /**
74
+     *
75
+     * The default Google reCAPTCHA language code
76
+     * It has no effect with v3
77
+     * @see   https://developers.google.com/recaptcha/docs/language
78
+     * @since v3.6.0
79
+     *
80
+     */
81
+    'default_language'             => env('RECAPTCHA_DEFAULT_LANGUAGE', null)
82 82
 ];
Please login to merge, or discard this patch.