From f11816e440d76bf16c03820d87226929dfea1316 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Wed, 25 Apr 2018 11:56:55 +0200 Subject: [PATCH] FEATURE: Allow to store `sitekey` and `secret` in Settings.yaml You can predefine the secret and sitekey in Settings.yaml. If no specific values are given in the form the captcha-element will fallback to those values. --- .../FormElements/ReCAPTCHAFormElement.php | 22 +++++++++++++++++++ .../Validation/ReCAPTCHAValidator.php | 11 ++++++++-- Configuration/Settings.yaml | 6 +++++ README.md | 15 +++++++++++++ Resources/Private/Form/ReCAPTCHA.html | 2 +- 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 Classes/Gerdemann/ReCAPTCHA/FormElements/ReCAPTCHAFormElement.php diff --git a/Classes/Gerdemann/ReCAPTCHA/FormElements/ReCAPTCHAFormElement.php b/Classes/Gerdemann/ReCAPTCHA/FormElements/ReCAPTCHAFormElement.php new file mode 100644 index 0000000..6708422 --- /dev/null +++ b/Classes/Gerdemann/ReCAPTCHA/FormElements/ReCAPTCHAFormElement.php @@ -0,0 +1,22 @@ +sitekey; + } +} diff --git a/Classes/Gerdemann/ReCAPTCHA/Validation/ReCAPTCHAValidator.php b/Classes/Gerdemann/ReCAPTCHA/Validation/ReCAPTCHAValidator.php index 5beda02..cd94600 100644 --- a/Classes/Gerdemann/ReCAPTCHA/Validation/ReCAPTCHAValidator.php +++ b/Classes/Gerdemann/ReCAPTCHA/Validation/ReCAPTCHAValidator.php @@ -1,6 +1,7 @@ array('', ' The shared key between your site and reCAPTCHA', 'string', true) + 'secret' => array('', ' The shared key between your site and reCAPTCHA', 'string', false) ); /** @@ -27,7 +34,7 @@ protected function isValid($value) $browser = new Browser(); $browser->setRequestEngine(new CurlEngine()); $arguments = array( - 'secret' => $this->getOptions()['secret'], + 'secret' => $this->getOptions()['secret'] ? $this->getOptions()['secret'] : $this->secret, 'response' => $value ); $response = $browser->request('https://www.google.com/recaptcha/api/siteverify', 'POST', $arguments); diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index d781ccc..4dd611a 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -4,6 +4,7 @@ Neos: default: formElementTypes: 'Gerdemann.ReCAPTCHA:ReCAPTCHA': + implementationClassName: Gerdemann\ReCAPTCHA\FormElements\ReCAPTCHAFormElement superTypes: 'Neos.Form:FormElement': true renderingOptions: @@ -15,3 +16,8 @@ Neos: fusion: autoInclude: Gerdemann.ReCAPTCHA: true + +Gerdemann: + ReCAPTCHA: + sitekey: ~ + secret: ~ diff --git a/README.md b/README.md index 6ba2379..73e8237 100755 --- a/README.md +++ b/README.md @@ -22,6 +22,21 @@ How-To: secret: 'ENTER_HERE_YOUR_SHARED_SECRET ``` +Settings: +----------- + +You can predefine default values for `secret` and `sitekey` in +`Settings.yaml`. If no specific values are given in the form the +captcha-element will fallback to those values. + + ``` + Gerdemann: + ReCAPTCHA: + sitekey: ~ + secret: ~ + ``` + + Hint: ------- diff --git a/Resources/Private/Form/ReCAPTCHA.html b/Resources/Private/Form/ReCAPTCHA.html index 2ea68d3..850720f 100644 --- a/Resources/Private/Form/ReCAPTCHA.html +++ b/Resources/Private/Form/ReCAPTCHA.html @@ -1,5 +1,5 @@