Skip to content

Commit

Permalink
Made configuration options configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtoobii committed Feb 9, 2023
1 parent 261d24f commit 2ae7e28
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### [0.1.2] 2023-02-09
* Made configuration options configurable

### [0.1.1] 2022-05-12

* Imported translation strings
Expand Down
37 changes: 14 additions & 23 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
Copyright (c) 2022 OETIKER+PARTNER AG
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Copyright (c) 2023 OETIKER+PARTNER AG - www.oetiker.ch

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
All rights reserved.

Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Neither the name of Ed Chipman nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of SilverStripe nor the names of its contributors may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
7 changes: 5 additions & 2 deletions Readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Make sure you met the following requirements beforehand:
- PHP CURL and JSON

```
composer require oposs/silverstripe-hcaptcha dev
composer require oposs/silverstripe-hcaptcha
```

And set hCaptcha as your default spamprotector:
Expand All @@ -34,6 +34,9 @@ Oposs\hCaptcha\Forms\hCaptchaField:
site_key: 'your_site_key'
# Make sure to set the key starting with 0x.. in quotes
secret_key: 'your_secret_key'
# To configure options listed here https://docs.hcaptcha.com/configuration
api_configuration:
recaptchacompat: 'off'

```

Expand All @@ -43,7 +46,7 @@ For more configuration options check comments in [hCaptchaField.php](src/Froms/h

In php:

```injectablephp
```php

use Oposs\hCaptcha\hCaptchaProtector\Forms

Expand Down
16 changes: 15 additions & 1 deletion src/Froms/hCaptchaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ class hCaptchaField extends FormField
*/
private static $submit_remote_ip = false;

/**
* Use this array to configure the options listed here https://docs.hcaptcha.com/configuration
* Technically you can add arbitrary key/value pairs here
*
* @var string[]
*/
private static $api_configuration = [
'recaptchacompat' => 'on',
'render' => 'onload',
];

public function __construct($name, $title = null, $value = null)
{
// Set default title
Expand Down Expand Up @@ -94,12 +105,15 @@ public function Field($properties = [])
{
$siteKey = self::getSiteKey();
$secretKey = self::config()->get('secret_key');
$api_config = self::config()->get('api_configuration');

$url_params = http_build_query($api_config);

if (empty($siteKey) || empty($secretKey)) {
user_error('You must configure hCaptcha $site_key and $secret_key', E_USER_ERROR);
}

Requirements::javascript('https://js.hcaptcha.com/1/api.js');
Requirements::javascript("https://js.hcaptcha.com/1/api.js?{$url_params}");

return parent::Field($properties);
}
Expand Down

0 comments on commit 2ae7e28

Please sign in to comment.