-
Notifications
You must be signed in to change notification settings - Fork 33
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 #12 from KonstantinCodes/feature/refactor
Refactor & use Translation for Message
- Loading branch information
Showing
9 changed files
with
283 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/* | ||
* @copyright 2018 Konstantin Scheumann. All rights reserved | ||
* @author Konstantin Scheumann | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace MauticPlugin\MauticRecaptchaBundle\Service; | ||
|
||
use GuzzleHttp\Client as GuzzleClient; | ||
use Mautic\CoreBundle\EventListener\CommonSubscriber; | ||
use Mautic\PluginBundle\Helper\IntegrationHelper; | ||
use MauticPlugin\MauticRecaptchaBundle\Integration\RecaptchaIntegration; | ||
|
||
class RecaptchaClient extends CommonSubscriber | ||
{ | ||
const VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $siteKey; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $secretKey; | ||
|
||
/** | ||
* FormSubscriber constructor. | ||
* | ||
* @param IntegrationHelper $integrationHelper | ||
*/ | ||
public function __construct(IntegrationHelper $integrationHelper) | ||
{ | ||
$integrationObject = $integrationHelper->getIntegrationObject(RecaptchaIntegration::INTEGRATION_NAME); | ||
|
||
$keys = $integrationObject->getKeys(); | ||
$this->siteKey = $keys['site_key']; | ||
$this->secretKey = $keys['secret_key']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return []; | ||
} | ||
|
||
|
||
/** | ||
* @param string $response | ||
* @return bool | ||
*/ | ||
public function verify($response) | ||
{ | ||
$client = new GuzzleClient(['timeout' => 10]); | ||
$response = $client->post( | ||
self::VERIFY_URL, | ||
[ | ||
'form_params' => [ | ||
'secret' => $this->secretKey, | ||
'response' => $response, | ||
], | ||
] | ||
); | ||
|
||
$response = json_decode($response->getBody(), true); | ||
if (array_key_exists('success', $response) && $response['success'] === true) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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.