Module: ReCaptcha::AppHelper

Defined in:
lib/recaptcha.rb

Overview

This module provides a simple helper for use in your controller to determine whether the ReCaptcha challenge was completed successfully. Simply include this module in your controller class

Constant Summary collapse

DEFAULT_CAPTCHA_FAILURE_MESSAGE =
'Captcha failed.'

Instance Method Summary collapse

Instance Method Details

#validate_recap(p, errors, options = {:msg => DEFAULT_CAPTCHA_FAILURE_MESSAGE}) ⇒ Object

Validate recaptcha from passed in params. Sets errors into the errors hash.

p

request parameters. Requires :recaptcha_challenge_field and :recaptcha_response_field

errors

errors hash-like thing. Usually ActiveRecord::Base.errors

options

Options hash. currently only uses :rcc_pub and :rcc_priv options for passing in ReCaptcha keys.



78
79
80
81
82
83
84
85
86
# File 'lib/recaptcha.rb', line 78

def validate_recap(p, errors, options = {:msg => DEFAULT_CAPTCHA_FAILURE_MESSAGE})
  unless options.has_key?(:msg)
    options[:msg] = DEFAULT_CAPTCHA_FAILURE_MESSAGE
  end
  rcc=ReCaptcha::Client.new(options[:rcc_pub] || RCC_PUB, options[:rcc_priv] || RCC_PRIV)
  res = rcc.validate(request.remote_ip, p[:recaptcha_challenge_field], p[:recaptcha_response_field], errors, options[:msg])
  session[:rcc_err]=rcc.last_error
  res
end