-
Notifications
You must be signed in to change notification settings - Fork 7
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 #19 from chrode/add-captcha
Add new Field type Captcha to use FriendlyCaptcha
- Loading branch information
Showing
11 changed files
with
195 additions
and
4 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,50 @@ | ||
<?php | ||
namespace Slub\SlubForms\Service\Captcha; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class FriendlyCaptcha { | ||
|
||
CONST API_URL = 'https://api.friendlycaptcha.com/api/v1/siteverify'; | ||
|
||
/** | ||
* This class represents the FriendlyCaptcha service for verifing CAPTCHA challenges. | ||
* | ||
* @param string $solution | ||
* @param array $config | ||
* @return bool | ||
*/ | ||
public function verify(string $solution, $config = []) { | ||
|
||
if (!$solution) { | ||
return false; | ||
} | ||
|
||
$options = [ | ||
'headers' => ['Cache-Control' => 'no-cache'], | ||
'allow_redirects' => true, | ||
'form_params' => [ | ||
'secret' => $config['secret'], | ||
'sitekey' => $config['sitekey'], | ||
'solution' => $solution, | ||
], | ||
]; | ||
|
||
$client = new Client(); | ||
$contents = $client->request('POST', self::API_URL, $options); | ||
|
||
if (!$contents) { | ||
return false; | ||
} | ||
|
||
try { | ||
$result = json_decode($contents->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR); | ||
|
||
} catch (\JsonException $e) { | ||
return false; | ||
} | ||
|
||
return (bool)$result->success; | ||
} | ||
|
||
} |
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,42 @@ | ||
<?php | ||
namespace Slub\SlubForms\ViewHelpers\Form; | ||
|
||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | ||
|
||
class ParseConfigurationViewHelper extends AbstractViewHelper { | ||
|
||
|
||
/** | ||
* Register arguments. | ||
* @return void | ||
*/ | ||
public function initializeArguments() | ||
{ | ||
parent::initializeArguments(); | ||
$this->registerArgument('configurationString', 'string', 'Config string', true); | ||
|
||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public static function renderStatic( | ||
array $arguments, | ||
\Closure $renderChildrenClosure, | ||
RenderingContextInterface $renderingContext | ||
) { | ||
|
||
$templateVariableContainer = $renderingContext->getVariableProvider(); | ||
|
||
if ($templateVariableContainer->exists('configuration')) { | ||
$templateVariableContainer->remove('configuration'); | ||
} | ||
$templateVariableContainer->add('configuration', \Slub\SlubForms\Helper\ArrayHelper::configToArray($arguments['configurationString'])); | ||
|
||
return $renderChildrenClosure(); | ||
|
||
} | ||
|
||
|
||
} |
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 |
---|---|---|
|
@@ -11,7 +11,9 @@ plugin.tx_slubforms { | |
skipDefaultArguments = 1 | ||
} | ||
settings { | ||
senderEmailAddress = [email protected] | ||
senderEmailAddress = [email protected] | ||
|
||
overwriteFromEmailAdressToOwner = [email protected] | ||
|
||
// allow sending anonymous mails | ||
#anonymEmails { | ||
|
@@ -21,6 +23,8 @@ plugin.tx_slubforms { | |
|
||
// send email to customer as confirmation | ||
sendConfirmationEmailToCustomer = 1 | ||
|
||
storeSenderIP = 0 | ||
} | ||
} | ||
|
||
|
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,18 @@ | ||
{namespace sf=Slub\SlubForms\ViewHelpers} | ||
<script | ||
type="module" | ||
src="https://cdn.jsdelivr.net/npm/[email protected]/widget.module.min.js" | ||
async | ||
defer | ||
></script> | ||
<script nomodule src="https://cdn.jsdelivr.net/npm/[email protected]/widget.min.js" async defer></script> | ||
|
||
|
||
<div class="field_description"> | ||
<f:form.hidden name="field[{fieldset.uid}][{field.uid}]" class="{field.shortname}" /> | ||
<f:format.raw><sf:form.parseConfiguration configurationString="{field.configuration}"> | ||
<div class="frc-captcha" data-sitekey="{configuration.sitekey}" data-lang="de" data-start="auto" data-solution-field-name="tx_slubforms_sf[field][{fieldset.uid}][{field.uid}]"></div> | ||
</sf:form.parseConfiguration></f:format.raw> | ||
|
||
<label class="error" for="tx_slubforms_sf[field][{fieldset.uid}][{field.uid}]"></label> | ||
</div> |
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