-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #712 from portabilis/portabilis-patch-2020-06-19
[2.3] Portabilis patch 19/06/2020
- Loading branch information
Showing
22 changed files
with
360 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace App\Rules; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\BadResponseException; | ||
use Illuminate\Contracts\Validation\Rule; | ||
use Throwable; | ||
|
||
class ReCaptchaV3 implements Rule | ||
{ | ||
/** | ||
* Create a new rule instance. | ||
* | ||
* @return boolean | ||
*/ | ||
public function passes($attribute, $value) | ||
{ | ||
if (!$this->checkConfig()) { | ||
return true; | ||
} | ||
|
||
$client = new Client(); | ||
|
||
try { | ||
$response = $client->post('https://www.google.com/recaptcha/api/siteverify', [ | ||
'query' => [ | ||
'secret' => config('legacy.app.recaptcha_v3.private_key'), | ||
'response' => $value, | ||
'remoteip' => request()->ip(), | ||
], | ||
]); | ||
|
||
return $this->getScore($response) >= config('legacy.app.recaptcha_v3.minimum_score'); | ||
} catch (BadResponseException $e) { | ||
return false; | ||
} catch (Throwable $e) { | ||
return true; | ||
} | ||
} | ||
|
||
/** | ||
* Retorna o score do recaptcha | ||
* | ||
* @param $response | ||
* @return float | ||
*/ | ||
private function getScore($response) | ||
{ | ||
return json_decode($response->getBody()->getContents(), true)['score']; | ||
} | ||
|
||
/** | ||
* Get the validation error message. | ||
* | ||
* @return string | ||
*/ | ||
public function message() | ||
{ | ||
return 'A verificação do reCAPTCHA falhou'; | ||
} | ||
|
||
/** | ||
* Verifica se as configurações do recaptcha estão presentes | ||
* | ||
* @return bool | ||
*/ | ||
private function checkConfig() | ||
{ | ||
return config('legacy.app.recaptcha_v3.public_key') && config('legacy.app.recaptcha_v3.private_key'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.