-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add recaptcha and update page titles
- Loading branch information
Showing
14 changed files
with
114 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
APP_URL=http://127.0.0.1/projects/typeapi/www/public | ||
APP_ENV=dev | ||
APP_DEBUG=on | ||
APP_CONNECTION=mysql://root:test1234@localhost/psx | ||
APP_MAILER=native://default | ||
APP_URL="http://127.0.0.1/projects/typeapi/www/public" | ||
APP_ENV="prod" | ||
APP_DEBUG="off" | ||
APP_CONNECTION="mysql://root:test1234@localhost/psx" | ||
APP_MAILER="native://default" | ||
APP_RECAPTCHA_KEY="" | ||
APP_RECAPTCHA_SECRET="" |
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 |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
}, | ||
"schema": { | ||
"type": "string" | ||
}, | ||
"g-recaptcha-response": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
|
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
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,47 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
use GuzzleHttp\Client; | ||
use PSX\Framework\Config\ConfigInterface; | ||
use PSX\Json; | ||
|
||
class CaptchaVerifier | ||
{ | ||
private Client $httpClient; | ||
private string $secret; | ||
|
||
public function __construct(ConfigInterface $config) | ||
{ | ||
$this->httpClient = new Client(); | ||
$this->secret = $config->get('recaptcha_secret'); | ||
} | ||
|
||
public function verify(?string $recaptchaResponse): bool | ||
{ | ||
if (empty($recaptchaResponse)) { | ||
return false; | ||
} | ||
|
||
$response = $this->httpClient->post('https://www.google.com/recaptcha/api/siteverify', [ | ||
'headers' => [ | ||
'User-Agent' => 'typeapi.org' | ||
], | ||
'form_params' => [ | ||
'secret' => $this->secret, | ||
'response' => $recaptchaResponse, | ||
'remoteip' => $_SERVER['REMOTE_ADDR'] ?? '', | ||
], | ||
'verify' => false | ||
]); | ||
|
||
if ($response->getStatusCode() == 200) { | ||
$data = Json\Parser::decode((string) $response->getBody()); | ||
if (isset($data->success) && $data->success === true) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |