Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/candrews/grails-jcaptcha-plugin
https://github.com/candrews/grails-jcaptcha-plugin
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/candrews/grails-jcaptcha-plugin
- Owner: candrews
- License: apache-2.0
- Created: 2013-06-03T17:30:19.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-07-03T17:23:43.000Z (over 9 years ago)
- Last Synced: 2024-10-06T16:56:45.248Z (3 months ago)
- Language: Shell
- Size: 1.17 MB
- Stars: 1
- Watchers: 4
- Forks: 4
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# JCaptcha Plugin
Makes using JCaptcha within a Grails app simple.
[![Build Status](https://api.travis-ci.org/candrews/grails-jcaptcha-plugin.png)](http://travis-ci.org/candrews/grails-jcaptcha-plugin)
## JCaptcha
[JCaptcha](http://jcaptcha.sourceforge.net/) is an open source (LGPL) [captcha](http://en.wikipedia.org/wiki/Captcha) solution.
JCaptcha provides visual and audio challenges and could be extended to provide different kinds of challenges if you desire.h2. Versions
VersionMinimum Grails Version
0.10.6
0.21.0-RC1
0.2.11.2.1## The Plugin
The Grails JCaptcha plugin provides an easy way to define Captchas, display them and verify the response.
## Installation
The plugin is available from the official repository so can be installed by adding
```
plugins { runtime ':jcaptcha:latest' }
```
to your BuildConfig.groovy.## Usage
### Defining Captchas
Captchas are defined in the `grails-app/conf/Config.groovy` file.
```groovy
jcaptchas {
captcha1 = ...
captcha2 = ...
}
```
Each `jcaptcha.*` entry must be an instance of [CaptchaService](http://jcaptcha.sourceforge.net/multiproject/jcaptcha-service/apidocs/com/octo/captcha/service/CaptchaService.html) which is responsible for generating challenges and verifying responses.Some example Captchas ...
```groovy
import java.awt.Font
import java.awt.Colorimport com.octo.captcha.service.multitype.GenericManageableCaptchaService
import com.octo.captcha.engine.GenericCaptchaEngine
import com.octo.captcha.image.gimpy.GimpyFactory
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator
import com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator
import com.octo.captcha.component.image.color.SingleColorGenerator
import com.octo.captcha.component.image.textpaster.NonLinearTextPasterimport com.octo.captcha.service.sound.DefaultManageableSoundCaptchaService
jcaptchas {
imageCaptcha = new GenericManageableCaptchaService(
new GenericCaptchaEngine(
new GimpyFactory(
new RandomWordGenerator(
'abcdefghijklmnopqrstuvwxyz1234567890'
),
new ComposedWordToImage(
new RandomFontGenerator(
20, // min font size
30, // max font size
[new Font('Arial', 0, 10)] as Font[]
),
new GradientBackgroundGenerator(
140, // width
35, // height
new SingleColorGenerator(new Color(0, 60, 0)),
new SingleColorGenerator(new Color(20, 20, 20))
),
new NonLinearTextPaster(
6, // minimal length of text
6, // maximal length of text
new Color(0, 255, 0)
)
)
)
),
180, // minGuarantedStorageDelayInSeconds
180000 // maxCaptchaStoreSize
)soundCaptcha = new DefaultManageableSoundCaptchaService()
}
```
Construction/configuration of captcha services is part of JCaptcha itself so refer to the [JCaptcha documentation](http://forge.octo.com/jcaptcha/confluence) on that.## JCaptcha Controller
The plugin installs a controller called `JCaptchaController` . It's function is to **render** captcha challenges. It currently supports two rendering formats: jpeg and wav.
The controller supports URIs like `jcaptcha/jpeg/` and `jcaptcha/wav/` which will write the binary output to the output stream.
**NOTE:** Make sure that you don't try and render image captchas as sound or vice versa. If you attempt this you will get an IllegalArgumentException.
### JCaptcha Tags
The plugin makes tags available for jpeg and wav challenges.
```
```
You can pass any other attributes that are accepted by the underlying HTML tags to the tags.### JCaptcha Service
The JCaptchaService class is responsible for obtaining the instances of CaptchaService defined in your config. It is also used for verifying responses to challenges.
```groovy
class ExampleController {def jcaptchaService
def index() {
if (jcaptchaService.validateResponse('captchaName', session.id, params.captchaResponse)) {
// User entered response correctly
} else {
// User got it wrong, OR THEY ARE A BOT!
}
}
}
```
Notice that you need to pass `session.id` to `validateResponse`. This is because the captcha service needs to match the response to the challenge to check the answer.
The key between the two is `session.id`.## Example Application
Here is a fully functional [example application](https://github.com/stokito/grails-jcaptcha-demo) that uses the JCaptcha plugin.