mirror of
https://github.com/zoe-may/TDoG-Skin.git
synced 2025-01-19 06:57:24 +08:00
37 lines
985 B
PHP
37 lines
985 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Rules;
|
||
|
|
||
|
use Composer\CaBundle\CaBundle;
|
||
|
use Gregwar\Captcha\CaptchaBuilder;
|
||
|
use Illuminate\Contracts\Validation\Rule;
|
||
|
use Illuminate\Support\Facades\Http;
|
||
|
|
||
|
class Captcha implements Rule
|
||
|
{
|
||
|
public function passes($attribute, $value)
|
||
|
{
|
||
|
$secretkey = option('recaptcha_secretkey');
|
||
|
if ($secretkey) {
|
||
|
return Http::asForm()
|
||
|
->withOptions(['verify' => CaBundle::getSystemCaRootBundlePath()])
|
||
|
->post('https://www.recaptcha.net/recaptcha/api/siteverify', [
|
||
|
'secret' => $secretkey,
|
||
|
'response' => $value,
|
||
|
])
|
||
|
->json()['success'];
|
||
|
}
|
||
|
|
||
|
$builder = new CaptchaBuilder(session()->pull('captcha'));
|
||
|
|
||
|
return $builder->testPhrase($value);
|
||
|
}
|
||
|
|
||
|
public function message()
|
||
|
{
|
||
|
return option('recaptcha_secretkey')
|
||
|
? trans('validation.recaptcha')
|
||
|
: trans('validation.captcha');
|
||
|
}
|
||
|
}
|