github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

ambethia / recaptcha

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 342
    • 44
  • Source
  • Commits
  • Network (44)
  • Issues (5)
  • Downloads (5)
  • Wiki (2)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (4)
    • c3bc7c49daf68365a0155c10f24eeabcf78b2867
    • example-rails
    • gh-pages
    • master ✓
  • Tags (5)
    • v0.2.3
    • v0.2.2
    • v0.2.1
    • v0.2.0
    • v0.1.0
Sending Request…
Click here to lend your support to: recaptcha and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

ReCaptcha helpers for Rails apps — Read more

  cancel

http://ambethia.com/recaptcha

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Allow to set recaptcha errors on model attributes 
rykov (author)
Tue Jan 26 14:40:44 -0800 2010
ambethia (committer)
Mon Feb 08 19:10:07 -0800 2010
commit  754d42e88b982dc9b8e1f2aae0ad11b2a537f946
tree    395f1a475a7b9b055e41fb4461bb6e76321fbaa7
parent  2a06ed9aa30c51add7f1799633e825014c400c3e
recaptcha /
name age
history
message
file .gitignore Sat Sep 12 16:39:47 -0700 2009 Version bump to 0.2.0 (<3 Jeweler) [ambethia]
file CHANGELOG Mon Sep 14 20:01:40 -0700 2009 Version 0.2.2, Timeout +some documentation love [ambethia]
file LICENSE Sat May 26 02:35:19 -0700 2007 Initial import of ReCAPTCHA plugin [ambethia]
file README.rdoc Mon Feb 08 19:10:07 -0800 2010 Allow to set recaptcha errors on model attributes [rykov]
file Rakefile Wed Oct 14 07:20:51 -0700 2009 Gemcutter [ambethia]
file VERSION Fri Oct 23 13:17:15 -0700 2009 Version bump to 0.2.3 [ambethia]
file init.rb Wed Oct 14 07:13:17 -0700 2009 Requiring 'net/http'. Closes #7 [ambethia]
directory lib/ Tue Jan 26 14:40:44 -0800 2010 Allow to set recaptcha errors on model attributes [rykov]
file recaptcha.gemspec Fri Oct 23 13:17:19 -0700 2009 Regenerated gemspec for version 0.2.3 [ambethia]
directory tasks/ Sat May 26 02:35:19 -0700 2007 Initial import of ReCAPTCHA plugin [ambethia]
directory test/ Mon Sep 14 18:46:13 -0700 2009 Tests for timeout, ad8bbbb0 [ambethia]
README.rdoc

reCAPTCHA

Author:Jason L Perry (ambethia.com)
Copyright:Copyright © 2007 Jason L Perry
License:MIT
Info:ambethia.com/recaptcha
Git:github.com/ambethia/recaptcha/tree/master
Bugs:github.com/ambethia/recaptcha/issues

This plugin adds helpers for the reCAPTCHA API. 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 want to add your public and private API keys in the environment variables RECAPTCHA_PUBLIC_KEY and RECAPTCHA_PRIVATE_KEY, respectively. You could also specify them in config/environment.rb if you are so inclined (see below). Exceptions will be raised if you call these methods and the keys can’t be found.

Rails Installation

reCAPTCHA for Rails can be installed as a gem:

  config.gem "ambethia-recaptcha", :lib => "recaptcha/rails", :source => "http://gems.github.com"

Or, as a standard rails plugin:

  script/plugin install git://github.com/ambethia/recaptcha.git

Merb Installation

reCAPTCHA can also be used in a Merb application when installed as a gem:

  dependency "alm-recaptcha", ">=0.2.2.1", :require_as => "recaptcha/merb"

Initial Merb compatability funded by ALM Labs.

Setting up your API Keys

There are two ways to setup your reCAPTCHA API keys once you obtain a pair. You can pass in your keys as options at runtime, for example:

  recaptcha_tags :public_key => '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'

and later,

  verify_recaptcha :private_key => '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'

Or, preferably, you can keep your keys out of your code base by exporting the environment variables mentioned earlier. You might do this in the .profile/rc, or equivalent for the user running your application:

  export RECAPTCHA_PUBLIC_KEY  = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
  export RECAPTCHA_PRIVATE_KEY = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'

If that’s not your thing, and dropping things into config/environment.rb is, you can just do:

  ENV['RECAPTCHA_PUBLIC_KEY']  = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
  ENV['RECAPTCHA_PRIVATE_KEY'] = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'

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)
:ajax:Render the dynamic AJAX captcha per the API. (default false)
:public_key:Your public API key, takes precedence over the ENV variable (default nil)
:error:Override the error code returned from the reCAPTCHA API (default nil)

You can also override the html attributes for the sizes of the generated textarea and iframe elements, if CSS isn’t your thing. Inspect the source of recaptcha_tags to see these options.

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.

Some of the options available:

:model:Model to set errors
:attribute:Model attribute to receive errors (default :base)
:message:Custom error message
:private_key:Your private API key, takes precedence over the ENV variable (default nil).
:timeout:The number of seconds to wait for reCAPTCHA servers before give up. (default +3+)
  respond_to do |format|
    if verify_recaptcha(:model => @post, :message => "Oh! It's error with reCAPTCHA!") && @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
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server