47 lines
965 B
PHP
47 lines
965 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Rules;
|
||
|
|
|
||
|
|
use Illuminate\Contracts\Validation\Rule;
|
||
|
|
use ReCaptcha\ReCaptcha;
|
||
|
|
|
||
|
|
class ReCaptchaRule implements Rule
|
||
|
|
{
|
||
|
|
|
||
|
|
public function __construct()
|
||
|
|
{}
|
||
|
|
|
||
|
|
public function passes($attribute, $value)
|
||
|
|
{
|
||
|
|
// if (empty($value)) {
|
||
|
|
// $this->error_msg = ':attribute field is required.';
|
||
|
|
|
||
|
|
// return false;
|
||
|
|
// }
|
||
|
|
|
||
|
|
$recaptcha = new ReCaptcha('6LelUOQZAAAAAHBAEnflw1XLOvCgaAeKQb4TilEb');
|
||
|
|
$resp = $recaptcha->verify($value, $_SERVER['REMOTE_ADDR']);
|
||
|
|
//dd($resp);
|
||
|
|
// if (!$resp->isSuccess()) {
|
||
|
|
// $this->error_msg = 'ReCaptcha field is required.';
|
||
|
|
|
||
|
|
// return false;
|
||
|
|
// }
|
||
|
|
|
||
|
|
// if ($resp->getScore() < 0.5) {
|
||
|
|
// $this->error_msg = 'Failed to validate captcha.';
|
||
|
|
|
||
|
|
// return false;
|
||
|
|
// }
|
||
|
|
|
||
|
|
|
||
|
|
return $resp;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public function message()
|
||
|
|
{
|
||
|
|
return "smth went wrong";
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|