@@ -110,14 +110,27 @@ public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder {
110
110
return $ this ;
111
111
}
112
112
113
+ /**
114
+ * @return array|mixed
115
+ */
116
+ protected function getIpWhitelist () {
117
+ $ whitelist = config ('recaptcha.skip_ip ' , []);
118
+
119
+ if (!is_array ($ whitelist )) {
120
+ $ whitelist = explode (', ' , $ whitelist );
121
+ }
122
+
123
+ return $ whitelist ;
124
+ }
125
+
113
126
/**
114
127
* Checks whether the user IP address is among IPs "to be skipped"
115
128
*
116
129
* @return boolean
117
130
*/
118
131
public function skipByIp (): bool {
119
132
120
- return (in_array (request ()->ip (), config ( ' recaptcha.skip_ip ' , [] )));
133
+ return (in_array (request ()->ip (), $ this -> getIpWhitelist ( )));
121
134
}
122
135
123
136
/**
@@ -221,6 +234,15 @@ public function htmlScriptTagJsApiV3(?array $configuration = []): string {
221
234
public function validate ($ response ) {
222
235
223
236
if ($ this ->skip_by_ip ) {
237
+ if ($ this ->returnArray ()) {
238
+ // Add 'skip_by_ip' field to response
239
+ return [
240
+ 'skip_by_ip ' => true ,
241
+ 'score ' => 0.9 ,
242
+ 'success ' => true
243
+ ];
244
+ }
245
+
224
246
return true ;
225
247
}
226
248
@@ -243,16 +265,34 @@ public function validate($response) {
243
265
else {
244
266
$ curl_response = file_get_contents ($ url );
245
267
}
268
+
246
269
if (is_null ($ curl_response ) || empty ($ curl_response )) {
270
+ if ($ this ->returnArray ()) {
271
+ // Add 'error' field to response
272
+ return [
273
+ 'error ' => 'cURL response empty ' ,
274
+ 'score ' => 0.1 ,
275
+ 'success ' => false
276
+ ];
277
+ }
278
+
247
279
return false ;
248
280
}
249
281
$ response = json_decode (trim ($ curl_response ), true );
250
282
251
- if ($ this ->version == ' v3 ' ) {
283
+ if ($ this ->returnArray () ) {
252
284
return $ response ;
253
285
}
254
286
255
287
return $ response ['success ' ];
256
288
257
289
}
290
+
291
+ /**
292
+ * @return bool
293
+ */
294
+ protected function returnArray (): bool {
295
+
296
+ return ($ this ->version == 'v3 ' );
297
+ }
258
298
}
0 commit comments