Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/ntalbott/recaptcha into nta…
Browse files Browse the repository at this point in the history
…lbott/master
  • Loading branch information
Jason L Perry committed Dec 31, 2008
2 parents ecf9a7b + 4bb2a19 commit 3ecb728
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/recaptcha.rb
Expand Up @@ -46,21 +46,24 @@ def recaptcha_tags(options = {})

module Controller
# Your private API key must be specified in the environment variable +RECAPTCHA_PRIVATE_KEY+
def verify_recaptcha(model = nil)
def verify_recaptcha(options = {})
return true if SKIP_VERIFY_ENV.include? ENV['RAILS_ENV']
raise ReCaptchaError, "No private key specified." unless ENV['RECAPTCHA_PRIVATE_KEY']
key = (options[:private_key] || ENV['RECAPTCHA_PRIVATE_KEY'])
raise ReCaptchaError, "No private key specified." unless key
begin
recaptcha = Net::HTTP.post_form URI.parse("http://#{RECAPTCHA_VERIFY_SERVER}/verify"), {
:privatekey => ENV['RECAPTCHA_PRIVATE_KEY'],
:privatekey => key,
:remoteip => request.remote_ip,
:challenge => params[:recaptcha_challenge_field],
:response => params[:recaptcha_response_field]
}
answer, error = recaptcha.body.split.map { |s| s.chomp }
unless answer == 'true'
session[:recaptcha_error] = error
model.valid? if model
model.errors.add_to_base "Captcha response is incorrect, please try again." if model
if model = options[:model]
model.valid?
model.errors.add_to_base "Captcha response is incorrect, please try again."
end
return false
else
session[:recaptcha_error] = nil
Expand Down

0 comments on commit 3ecb728

Please sign in to comment.