Nuevos cambios hechos de diseño
This commit is contained in:
65
desarrollo2/app/Rules/Recaptcha.php
Normal file
65
desarrollo2/app/Rules/Recaptcha.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class Recaptcha implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$data = array(
|
||||
'secret' => env('RECAPTCHA_SECRET_KEY'),
|
||||
'response' => $value
|
||||
);
|
||||
|
||||
try {
|
||||
$verify = curl_init();
|
||||
curl_setopt(
|
||||
$verify,
|
||||
CURLOPT_URL,
|
||||
"https://www.google.com/recaptcha/api/siteverify"
|
||||
);
|
||||
curl_setopt($verify, CURLOPT_POST, true);
|
||||
curl_setopt(
|
||||
$verify,
|
||||
CURLOPT_POSTFIELDS,
|
||||
http_build_query($data)
|
||||
);
|
||||
curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = curl_exec($verify);
|
||||
|
||||
return json_decode($response)->success;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'reCAPTCHA verification failed.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user