Skip to content

Instantly share code, notes, and snippets.

@jpoz
Created July 11, 2009 07:34
Show Gist options
  • Save jpoz/145150 to your computer and use it in GitHub Desktop.
Save jpoz/145150 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'sinatra/recaptcha'
configure do
# https://admin.recaptcha.net/accounts/signup/
Sinatra::ReCaptcha.public_key = 'your_public_key'
Sinatra::ReCaptcha.private_key = 'your_private_key'
# to use ssl set Sinatra::ReCaptcha.server = 'https://api-secure.recaptcha.net'
end
get '/' do
haml :recaptcha
end
post '/' do
halt(401, "invalid captcha") unless captcha_correct?
"passed!"
end
__END__
@@ captcha
%h1 Try ReCaptcha
%form{:method=>"post", :action=>"/post"}
= recaptcha
# you can also use recaptcha(:ajax) to use a pure ajax version
%input{:type=>'submit', :value => 'Send'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment