public
Fork of ambethia/recaptcha
Description: ReCaptcha helpers for Rails apps
Homepage: http://ambethia.com/recaptcha
Clone URL: git://github.com/humanzz/recaptcha.git
humanzz (author)
Mon Jul 21 03:47:05 -0700 2008
commit  ea931b56fa74cf070431a58299ca398e4f83cc45
tree    92e73d7cb1b2036671b28cfe07ea84c80e056347
parent  14875c27ddef4e2898becd605e045e6cdc1dc14c
name age message
file .gitignore Loading commit data...
file LICENSE Sat May 26 02:35:19 -0700 2007 Initial import of ReCAPTCHA plugin [ambethia]
file README.rdoc
file Rakefile Thu May 08 18:52:28 -0700 2008 Updating README and tweaking Rdoc tasks [ambethia]
file init.rb Sat May 26 02:35:19 -0700 2007 Initial import of ReCAPTCHA plugin [ambethia]
file install.rb Sat May 26 02:35:19 -0700 2007 Initial import of ReCAPTCHA plugin [ambethia]
directory lib/
directory tasks/ Sat May 26 02:35:19 -0700 2007 Initial import of ReCAPTCHA plugin [ambethia]
directory test/
file uninstall.rb Sat May 26 02:35:19 -0700 2007 Initial import of ReCAPTCHA plugin [ambethia]
README.rdoc

ReCAPTCHA

Author:Jason L Perry (ambethia.com)
Copyright:Copyright © 2007 Jason L Perry
License:MIT
RDOC:ambethia.com/recaptcha/
Git:github.com/ambethia/recaptcha/tree/master
Bugs:ambethia.lighthouseapp.com/projects/11072-recaptcha/overview

This plugin adds helpers for the ReCAPTCHA API (recaptcha.net/). In your views you can use the recaptcha_tags method to embed the needed javascript, and you can validate in your controllers with verify_recaptcha.

You’ll need to get public and private API keys from ReCaptcha. Then, tell them to the library:

  Ambethia::ReCaptcha.public_key = '0123456789ABCDEF'
  Ambethia::ReCaptcha.private_key = '0123456789ABCDEF'

You’ll also need to set Ambethia::ReCaptcha.enabled = true. It’s set to nil by default

You can have multiple recaptcha settings and keys for different environments so in any of your environment files the following to enable recaptcha:

  config.after_initialize do
        Ambethia::ReCaptcha.enabled = true
        Ambethia::ReCaptcha.public_key = '0123456789ABCDEF'
        Ambethia::ReCaptcha.private_key = '0123456789ABCDEF'
  end

recaptcha_tags

Some of the options available:

:ssl:Uses secure http for captcha widget (default false)
:noscript:Include <noscript> content (default true)
:display:Takes a hash containing the theme and tabindex options per the API. (default nil)
:public_key:Your public API key, takes precedence over the ENV variable (default nil).
:error:Override the error in +session[:recaptcha_error]+ (default nil).

verify_recaptcha

This method returns true or false after processing the parameters from the ReCAPTCHA widget. Why isn’t this a model validation? Because that violates MVC. Use can use it like this, or how ever you like. Passing in the ActiveRecord object is optional, if you do—and the captcha fails to verify—an error will be added to the object for you to use.

  respond_to do |format|
    if verify_recaptcha(@post) && @post.save
      # ...
    else
      # ...
    end
  end

TODO

  • Remove Rails/ActionController dependencies
  • Framework agnostic
  • Add some helpers to use in before_filter and what not
  • Better documentation