Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'Firesphere/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Oct 4, 2016
2 parents d328ba4 + e7f3cb8 commit 65aeba6
Show file tree
Hide file tree
Showing 13 changed files with 550 additions and 610 deletions.
21 changes: 12 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details

language: php
php:
- 5.3

env:
- DB=MYSQL CORE_RELEASE=3.1
- DB=PGSQL CORE_RELEASE=master

matrix:
include:
- php: 5.3
env: DB=MYSQL CORE_RELEASE=3.1
- php: 5.4
env: DB=MYSQL CORE_RELEASE=master
env: DB=MYSQL CORE_RELEASE=3.2
- php: 5.5
env: DB=MYSQL CORE_RELEASE=3.3
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3.1 SECUREASSETS=1
- php: 5.6
env: DB=PGSQL CORE_RELEASE=3.3

before_script:
- pear -q install --onlyreqdeps pear/PHP_CodeSniffer
Expand All @@ -21,5 +25,4 @@ before_script:
- cd ~/builds/ss

script:
- phpunit recaptcha/tests/
- phpcs --encoding=utf-8 --tab-width=4 --standard=framework/tests/phpcs -np recaptcha
- phpunit recaptcha/tests/
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@
# 0.4 (2010-05-14)
- Using curl for HTTP communication
- Fixed timeout problems
- Added basic unit tests
- Added basic unit tests

# 0.5 (2016-10-10)
- Use YML configuration (e.g. `Recaptcha.api_verify_server`) instead of `$js_options` class static
- Removed `$useSSL` option (now always on SSL)
- Removed `$valid_languages`, use `hl` parameter in the options (see https://developers.google.com/recaptcha/docs/display)
- Removed `$useAjaxAPI` (Recaptcha v2 works differently now)
- `<noscript>` fallback requires additional configuration now (https://developers.google.com/recaptcha/docs/faq)
91 changes: 30 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Recaptcha FormField Module
# reCAPTCHA FormField Module

[![Build Status](https://secure.travis-ci.org/chillu/silverstripe-recaptcha.png)](http://travis-ci.org/chillu/silverstripe-recaptcha)

## Introduction

Provides a FormField which allows form to validate for non-bot submissions
by giving them a challenge to decrypt an image.
using Google's reCAPTCHA service

## Maintainer Contact

Expand All @@ -23,27 +23,44 @@ by giving them a challenge to decrypt an image.
* Copy the `recaptcha` directory into your main SilverStripe webroot
* Run ?flush=1

This should go in your `mysite/_config.php`. You can get an free API key at [http://www.google.com/recaptcha](https://www.google.com/recaptcha/admin/create)
This should go in your `mysite/_config/recaptha.yml`. You can get an free API key at [https://www.google.com/recaptcha](https://www.google.com/recaptcha/admin/create)

RecaptchaField::$public_api_key = '<publickey>';
RecaptchaField::$private_api_key = '<privatekey>';
```
RecaptchaField:
public_api_key: "your-site-key"
private_api_key: "your-secret-key"
```

If using on a site requiring a proxy server for outgoing traffic then you can set these additional
options in your `mysite/_config.php`.
If using on a site requiring a proxy server for outgoing traffic then you can set these additional
options in your `mysite/_config/recaptcha.yml` by adding.
```
proxy_server: "proxy_address"
proxy_auth: "username:password"
```

RecaptchaField::$proxy_server = "<proxy address>";
RecaptchaField::$proxy_auth = "<proxy_username>:<proxy_password>";
To use the noscript fallback method, add the key `noscript_enabled: true` to your yml.

To change the language, add it to an array of options to your yml
```
options:
hl: NL
theme: dark
type: audio
size: compact
```

See https://developers.google.com/recaptcha/docs/display#render_param for all available parameters

## Usage

### As a Standalone Field

If you want to use Recaptcha field by itself, you can simply just include it as a field in your form.
If you want to use reCAPTCHA field by itself, you can simply just include it as a field in your form.

$recaptchaField = new RecaptchaField('MyCaptcha');
$recaptchaField->jsOptions = array('theme' => 'clean'); // optional
$recaptchaField->options = array('theme' => 'light'); // optional

See [Recaptcha API docs](https://developers.google.com/recaptcha/intro) for more configuration options.
See [reCAPTCHA docs](https://developers.google.com/recaptcha/docs/display#render_param) for more configuration options.

### Integration with spamprotection module

Expand All @@ -60,60 +77,12 @@ Configuration example in `mysite/_config/spamprotection.yml`

Then once you have setup this config you will need to include the spam protector field as per the instructions on the [spamprotection](https://github.com/silverstripe/silverstripe-spamprotection) page.


## Custom Theming

The standard themes may be too limiting for your needs.

Adding the following configuration to your _config.php file, will automatically set the field
to use a customisable template:

```php
RecaptchaField::$js_options = array(
'theme' => 'custom',
'custom_theme_widget' => 'recaptcha_widget'
);
```

You can edit the design template by creating your own `[themedir]/templates/CustomRecaptchaField.ss` file.

## Known issues:

### Problems with page doctype XHTML

ReCAPTCHA current does not work if the page doctype is XHTML. The API returns
reCAPTCHA current does not work if the page doctype is XHTML. The API returns
Javascript which uses "document.write", which is not supported in XHTML.
A work-around is to always use the no-script version of the module (modify the
relevant lines in RecaptchaField.php), or to switch your webpage's doctype to
HTML 4. See: http://www.w3schools.com/tags/tag_DOCTYPE.asp

### Problems with IE9
There is an issue that with certain site configurations, forms just won't submit in IE9.
Several threads are pointing to that IE9 and reCaptcha just won't work together, and this thread suggests to force Internet Explorer in IE8 mode:
http://answers.microsoft.com/en-us/ie/forum/ie9-windows_7/ie9-is-not-capturing-recaptcha-form-fields/6479d1f0-6f67-e011-8dfc-68b599b31bf5?msgId=44883943-036d-e011-8dfc-68b599b31bf5&page=1

What can be done to circumvent this (but isn't optimal, as many sites look much better in IE9/10 than in IE8), is to force all `UserDefineForms` pages to be rendered in IE8 mode like described below (off course that can be extended to include other page types as well).
Though it's not optimal at all, it can be a good trade-off, considering that users are at least able to submit forms.

```php
/*
* Forcing the browser to render in IE8 mode for UserDefineForms
* This is due to problems with IE9 and reCaptcha
*/
public function ForceIE8(){
$class = $this->ClassName;
if ($class == 'UserDefinedForm') {
return true;
}
}
```
...and adding this as first in the head tag

```html
<% if ForceIE8 %>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" >
<% end_if %>
```



1 change: 0 additions & 1 deletion _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
/**
* @package recaptcha
*/
?>
5 changes: 5 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RecaptchaField:
recaptcha_noscript_url: 'https://www.google.com/recaptcha/api/fallback?k=%s'
recaptcha_js_url: 'https://www.google.com/recaptcha/api.js'
api_verify_server: 'https://www.google.com/recaptcha/api/siteverify'
httpclient_class: 'RecaptchaField_HTTPClient'
Loading

0 comments on commit 65aeba6

Please sign in to comment.