Repository URL to install this package:
| 
      
        
        
        Version: 
        
         
          
          0.2.0  ▾
        
         | 
| 
    
    rack-iamnotarobot
  
    /
        README.md
   | 
|---|
A Rack middleware that provides CAPTCHA verification via Google's reCAPTCHA API. Works with Google's new reCAPTCHA implementation.
First, install the library with:
[sudo] gem install rack-iamnotarobot
You have to require 'rack-iamnotarobot' in your gemfile.
## Gemfile gem 'rack-iamnotarobot', :require => 'rack/iamnotarobot'
Available options for Rack::IAmNotARobot middleware are:
:site_key -- your ReCaptcha API site key (required):secret_key -- your ReCaptcha API secret key (required)Now configure your app to use the middleware. This might be different across each web framework.
## app.rb use Rack::IAmNotARobot, :site_key => 'KEY', :secret_key => 'SECRET' helpers Rack::IAmNotARobot::Helpers
## app/app.rb use Rack::IAmNotARobot, :site_key => 'KEY', :secret_key => 'SECRET' helpers Rack::IAmNotARobot::Helpers
## application.rb: module YourRailsAppName class Application < Rails::Application ... config.gem 'rack-iamnotarobot', :lib => 'rack/recaptcha' config.middleware.use Rack::IAmNotARobot, :site_key => 'KEY', :secret_key => 'SECRET' end end ## application_helper.rb or whatever helper you want it in. module ApplicationHelper include Rack::IAmNotARobot::Helpers end ## application_controller.rb or whatever controller you want it in. class ApplicationController < ActionController::Base ... include Rack::IAmNotARobot::Helpers ... end
The Rack::IAmNotARobot::Helpers module (for Sinatra, Rails, Padrino) adds the following method to your app:
To test whether or not the verification passed, you can use:
human?
The human? helper can also be overloaded during tests. You
can set its response to either true or false by doing the following:
# Have human? return true Rack::IAmNotARobot.test_mode! # Or have it return false Rack::IAmNotARobot.test_mode! :return => false
For additional options and resources checkout the customization page
In Rails, here's how you would use the library.
In your view:
<form> <input name="email"> <script src="https://www.google.com/recaptcha/api.js" async defer></script> <div class="g-recaptcha" data-sitekey="YOUR_RECAPTCHA_SITE_KEY"></div> <button type="submit">Submit</button> </form>
In your controller:
if human? "passed!" else "failed!" end
Based on @achiu's rack-recaptcha.
Copyright (c) 2015 Crush & Lovely, PJ Kelly. See LICENSE for details.