Skip to content

gregorymaertens/play-recaptcha

 
 

Repository files navigation

Recaptcha module for Play!

Integrate challenge-response reCaptcha tests in 2 minutes.

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.

sample

Features

  • 2 minutes integration guaranteed
  • Industry standard Captcha engine reCaptcha
  • Automatically detects language preference from the Play Framework
  • Customizable theme, tabindex and language

Prerequisites

The modules requires the recapctha public/private key for your domain.

  1. Please go to http://www.google.com/recaptcha
  2. Register and create a site for your domain
  3. Write down the generated public and private keys

Installation

  1. run ‘play install recaptcha’ and let Play! install the module

  2. open your application conf/dependencies.yml and add

     - play -> recaptcha        
    
  3. open your application conf/application.conf and add (copy paste your keys accordinly)

    ugot.recaptcha.privateKey=YOUR_RECAPTCHA_PRIVATE_KEY ugot.recaptcha.publicKey=YOUR_RECAPTCHA_PUBLIC_KEY

How to Use

Well it's kind of easy, the module offers two integration points:

  1. a tag to render the captcha: #{ugot.recaptcha /}
  2. an annotation to validate the result: @Recaptcha

Generating the captcha

#{extends ‘main.html’ /}
#{set title:‘Test reCaptcha’ /}
#{form `save()} 
    Your form data
    <p>#{ugot.recaptcha theme:"red", tabindex:"2"/}</p>
    #{ifErrors}
      <ul>
        #{errors}
           <li>${error}</li>
        #{/errors}
      </ul>
    #{/ifErrors}
    <p>&lt;input type="submit" value="Register me, I am human" /></p>
  #{/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 captcha) {

  if (validation.hasErrors ()) {
   System.out.println (“ERRORS found - invalid captcha”);
   params.flash ();
   validation.keep ();
  }
  else {
     System.out.println (“There are no errors, the catcha was validated”);
  }

  // no matter what, redisplay the same page
  register ();
 }
}

###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
https: true / false. Optional parameter, default value is false. If true recaptcha is fetched via https, otherwise http (http://code.google.com/apis/recaptcha/docs/tips.html)).

See the reCaptcha documentation for more details.

Credits

This module is based on the Recaptcha java library.
Author: Olivier Refalo

About

Easy integration of http://www.google.com/recaptcha with the playframework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%