mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
implemented reCaptcha
This commit is contained in:
38
src/App/Users/Rules/ReCaptchaRules.php
Normal file
38
src/App/Users/Rules/ReCaptchaRules.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Users\Rules;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class ReCaptchaRules implements Rule
|
||||
{
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$client = new Client();
|
||||
$response = $client->post('https://www.google.com/recaptcha/api/siteverify',
|
||||
[
|
||||
'form_params' => [
|
||||
'secret' => env('RECAPTCHA_CLIENT_SECRET', false),
|
||||
'remoteip' => request()->getClientIp(),
|
||||
'response' => $value
|
||||
]
|
||||
]
|
||||
);
|
||||
$body = json_decode((string)$response->getBody());
|
||||
|
||||
return $body->success;
|
||||
}
|
||||
|
||||
public function message(): string
|
||||
{
|
||||
return 'Are you a robot?';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user