PK Ħa>sx x build.xml
PK Ħa>c)A A commands.py# Here you can create play commands that are specific to the module, and extend existing commands
MODULE = 'recaptcha'
# Commands that are specific to your module
COMMANDS = ['recaptcha:hello']
def execute(**kargs):
command = kargs.get("command")
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")
if command == "recaptcha:hello":
print "~ Hello"
# This will be executed before any command (new, run...)
def before(**kargs):
command = kargs.get("command")
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")
# This will be executed after any command (new, run...)
def after(**kargs):
command = kargs.get("command")
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")
if command == "new":
pass
PK Ħa>s1 commands.pyc
2Mc @ s. d Z d g Z d Z d Z d Z d S( t recaptchas recaptcha:helloc K sV | i d } | i d } | i d } | i d } | d j o d GHn d S( Nt commandt appt argst envs recaptcha:hellos ~ Hello( t get( t kargsR R R R ( ( sE /Users/olivier/play-1.1RC2-276-gac17ec3/modules/recaptcha/commands.pyt execute s
c K s@ | i d } | i d } | i d } | i d } d S( NR R R R ( R ( R R R R R ( ( sE /Users/olivier/play-1.1RC2-276-gac17ec3/modules/recaptcha/commands.pyt before s c K sQ | i d } | i d } | i d } | i d } | d j o n d S( NR R R R t new( R ( R R R R R ( ( sE /Users/olivier/play-1.1RC2-276-gac17ec3/modules/recaptcha/commands.pyt after s
N( t MODULEt COMMANDSR R R
( ( ( sE /Users/olivier/play-1.1RC2-276-gac17ec3/modules/recaptcha/commands.pyt s PK a>;{# # manifestversion=1.03
frameworkVersions=1.1
PK Ħa>AH README.textileh1. Recaptcha module for Play!
Integrate challenge-response "reCaptcha":http://www.google.com/recaptcha tests in 2 minutes.
h2. What is a Captcha?
A Captcha is a type of challenge-response test used in computing to ensure that the response is not generated by a computer. Captcha are typically used to fight spam and validate that a human is using the system.
!http://www.google.com/recaptcha/static/images/smallCaptchaSpaceWithRoughAlpha.png(sample)!
h2. Features
* 2 minutes integration guaranteed
* Industry standard Captcha engine [reCaptcha](http://www.google.com/recaptcha)
* Automatically detects language preference from the "Play Framework":http://www.playframework.org
* Customizable theme, tabindex and language
h2. Prerequisites
The modules requires the recapctha public/private key for your domain.
# Please go to "http://www.google.com/recaptcha":http://www.google.com/recaptcha
# Register and create a site for your domain
# Write down the generated **public** and **private keys**
h2. Installation
# run *'play install recaptcha'* and let Play! install the module for you
# open your application **conf/application.conf** and add
## module.recaptcha=${play.path}/modules/recaptcha-{version}
## ugot.recaptcha.privateKey=YOUR_RECAPTCHA_PRIVATE_KEY
## ugot.recaptcha.publicKey=YOUR_RECAPTCHA_PUBLIC_KEY
Make sure to replace {version} and KEYS with their appropriate values
h2. How to Use
Well it's kind of easy, the module offers two integration points:
# a tag to render the captcha: #{ugot.recaptcha /}
# an annotation to validate the result: @Recaptcha
h4. Generating the captcha
Play being an MVC framework, we need to define an action in the controller and its associated page.
Edit file **app/controller/Application.java** as follows:
bc.
public class Application extends Controller {
public static void index() {
render();
}
}
Create a file `app/view/Application/index.html`
bc.
#{extends 'main.html' /}
#{set title:'Test reCaptcha' /}
#{form @save()} My sample captcha!
#{ugot.recaptcha theme:"red", tabindex:1/}
#{ifError 'recaptcha'}
#{error 'recaptcha'/}
#{/ifError}
#{/form}
h4. Validating the captcha
Edit file *app/controller/Application.java* and add the following:
import ugot.recaptcha.Recaptcha;
public class Application extends Controller {
public static void save(@Recaptcha String recaptcha) {
if(validation.hasErrors()) {
System.out.println("ERRORS found - invalid captcha");
validation.keep();
}
else {
System.out.println("There are no errors, the catcha was validated");
}
// no matter what, redisplay the same page
index();
}
}
h4. Testing the captcha
Start play and launch a browser to "http://localhost:9000/":http://localhost:9000/
Done!
You may find the sample app bundled with the module
h2. Tag parameters
The *ugot.recaptcha* tag takes the following parameters
*theme*: The theme to use. Possible values are:red (default), white, blackglass, clean
*tabindex*: Sets a tabindex for the reCAPTCHA text box. If other elements in the form use a tabindex, this should be set so that navigation is easier for the user
*lang*: A two character country code. By default the module will ask Play to provide the negotiated language. possible values are: en,nl,fr,de,pt,ru,es,tr
See the "reCaptcha documentation":http://code.google.com/apis/recaptcha/docs/customization.html for more details.
h2. Credits
This module is based on the "Recaptcha java library":http://code.google.com/p/recaptcha/downloads/list?q=label:java-Latest.
Author: Olivier Refalo
PK Ħa>O ! app/ugot/recaptcha/Recaptcha.javapackage ugot.recaptcha;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import net.sf.oval.configuration.annotation.Constraint;
/**
* Message key: validation.recaptcha $1: field name
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.PARAMETER })
@Constraint(checkWith = RecaptchaCheck.class)
public @interface Recaptcha {
String message() default RecaptchaCheck.mes;
}PK ͨa>c &