Skip to content

Commit

Permalink
updated license, changed namespace to oposs, title fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtoobii committed Feb 25, 2022
1 parent 76d819b commit 30188f8
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.gitignore export-ignore
/img export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### [0.1.0] 2022-02-25

* Initial Release
40 changes: 23 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
MIT License

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:

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
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.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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.
26 changes: 21 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
# hCaptcha spam protection

Protect your forms with hCaptcha
Protect your forms with [hCaptcha](https://www.hcaptcha.com/), a GDPR, CCPA, LGPD, PIPL and more compliant spam prodection
(according their website)

## Installation

As soon this module is published:
Make sure you met the following requirements beforehand:

- SilverStripe 4.x
- SilverStripe Spam Protection 3.x
- PHP CURL and JSON

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

And set hCaptcha as your default spamprotector:

```yaml

SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension:
default_spam_protector: Oposs\hCaptcha\hCaptchaProtector

```

## Configuration
Expand All @@ -16,12 +30,14 @@ In your `app/_config/hcaptcha.yml`

```yaml

Oetiker\hCaptcha\Forms\hCaptchaField:
Oposs\hCaptcha\Forms\hCaptchaField:
site_key: 'your_site_key'
secret_key: 'your_secret_key'

```

For more configuration options check comments in [hCaptchaField.php](src/Froms/hCaptchaField.php)

## Usage

In php:
Expand All @@ -34,7 +50,7 @@ new hCaptchaField('SpamProtection', 'SpamProtection', null);
```

Or if you use Userforms:
Or if you use [Userforms](https://github.com/silverstripe/silverstripe-userforms):

![img.png](img/img.png)

Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "oetiker/silverstripe-hcaptcha",
"name": "oposs/silverstripe-hcaptcha",
"type": "silverstripe-vendormodule",
"description": "Protect your forms with hCaptcha",
"homepage": "https://oetiker.ch",
Expand All @@ -10,21 +10,24 @@
"captcha",
"hcaptcha"
],
"support": {
"issues": "https://github.com/oposs/silverstripe-hcaptcha/issues"
},
"authors": [
{"name": "Tobias Bossert", "email": "[email protected]"}
],
"require": {
"silverstripe/cms": "^4",
"silverstripe/framework": "^4",
"silverstripe/vendor-plugin": "*",
"silverstripe/spamprotection": "~3.0",
"php": "^7.4 || ^8.0",
"ext-curl": "*",
"ext-json": "*"
},
"autoload": {
"psr-4": {
"Oetiker\\hCaptcha\\": "src/",
"Oetiker\\hCaptcha\\Forms\\" : "src/Froms"
"Oposs\\hCaptcha\\": "src/",
"Oposs\\hCaptcha\\Forms\\" : "src/Froms"
}
},
"version": "0.0.1"
}
}
5 changes: 3 additions & 2 deletions lang/de.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
en:
Oetiker\hCaptcha\Forms\hCaptchaField:
EMPTY: "Bitte captcha beantworten. Wenn nicht sichtbar, Javascript von js.hcaptcha.com erlauben"
NOSCRIPT: "Javascript muss aktiv sein um dieses Formular absenden zu kommen"
VALIDATE_ERROR: "Captcha konnte nicht verfiziert werden"
NOSCRIPT: "Javascript muss aktiv sein um dieses Formular absenden zu können"
VALIDATE_ERROR: "Captcha konnte nicht verfiziert werden"
DEFAULT_TITLE: "Spamschutz"
3 changes: 2 additions & 1 deletion lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ en:
Oetiker\hCaptcha\Forms\hCaptchaField:
EMPTY: "Please answer the captcha, if you do not see the captcha please enable JavaScript"
NOSCRIPT: "You must enable JavaScript to submit this form"
VALIDATE_ERROR: "Captcha could not be validated"
VALIDATE_ERROR: "Captcha could not be validated"
DEFAULT_TITLE: "Spam protection"
9 changes: 8 additions & 1 deletion src/Froms/hCaptchaField.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Oetiker\hCaptcha\Forms;
namespace Oposs\hCaptcha\Forms;

use SilverStripe\Control\Controller;
use SilverStripe\Forms\FormField;
Expand Down Expand Up @@ -38,6 +38,13 @@ class hCaptchaField extends FormField
*/
private static $submit_remote_ip = false;

public function __construct($name, $title = null, $value = null)
{
// Set default title
if ($title === null) $title = _t('Oetiker\hCaptcha\Forms\hCaptchaField.DEFAULT_TITLE', 'Spam protection');
parent::__construct($name, $title, $value);
}

/**
* Validates the h-captcha-response
* @inerhitDoc
Expand Down
11 changes: 6 additions & 5 deletions src/hCaptchaProtector.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<?php

namespace Oetiker\hCaptcha;
namespace Oposs\hCaptcha;


use Oetiker\hCaptcha\Forms\hCaptchaField;
use Oposs\hCaptcha\Forms\hCaptchaField;

class hCaptchaProtector implements \SilverStripe\SpamProtection\SpamProtector
{

/**
* @inheritDoc
*/
public function getFormField($name = 'hCaptcha', $title = 'hCaptcha', $value = null)
public function getFormField($name = 'hCaptcha', $title = 'Captcha', $value = null)
{
return new hCaptchaField($name, $title, $value);
return new hCaptchaField($name, $title);

}

/**
* @inheritDoc
*/
public function setFieldMapping($fieldMapping)
{
// TODO: Implement setFieldMapping() method.
//Not used
}
}

0 comments on commit 30188f8

Please sign in to comment.