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
-
#validate_recap(p, errors, options = {:msg => DEFAULT_CAPTCHA_FAILURE_MESSAGE}) ⇒ Object
Validate recaptcha from passed in params.
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, = {:msg => DEFAULT_CAPTCHA_FAILURE_MESSAGE}) unless .has_key?(:msg) [:msg] = DEFAULT_CAPTCHA_FAILURE_MESSAGE end rcc=ReCaptcha::Client.new([:rcc_pub] || RCC_PUB, [:rcc_priv] || RCC_PRIV) res = rcc.validate(request.remote_ip, p[:recaptcha_challenge_field], p[:recaptcha_response_field], errors, [:msg]) session[:rcc_err]=rcc.last_error res end |