first change
This commit is contained in:
29
app/Rules/Recaptcha.php
Normal file
29
app/Rules/Recaptcha.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class Recaptcha implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
$gResponseToken = (string) $value;
|
||||
|
||||
$response = Http::asForm()->post(
|
||||
'https://www.google.com/recaptcha/api/siteverify',
|
||||
['secret' => setting('recaptcha_secret_key'), 'response' => $gResponseToken]
|
||||
);
|
||||
|
||||
if (!json_decode($response->body(), true)['success']) {
|
||||
$fail('Invalid recaptcha');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user