Class: Rad::Captcha
- Inherits:
-
Object
- Object
- Rad::Captcha
- Defined in:
- lib/components/captcha.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#private_key ⇒ Object
Returns the value of attribute private_key.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#verify_url ⇒ Object
Returns the value of attribute verify_url.
Instance Method Summary collapse
Instance Attribute Details
#enabled ⇒ Object
Returns the value of attribute enabled.
2 3 4 |
# File 'lib/components/captcha.rb', line 2 def enabled @enabled end |
#private_key ⇒ Object
Returns the value of attribute private_key.
2 3 4 |
# File 'lib/components/captcha.rb', line 2 def private_key @private_key end |
#public_key ⇒ Object
Returns the value of attribute public_key.
2 3 4 |
# File 'lib/components/captcha.rb', line 2 def public_key @public_key end |
#timeout ⇒ Object
Returns the value of attribute timeout.
2 3 4 |
# File 'lib/components/captcha.rb', line 2 def timeout @timeout end |
#verify_url ⇒ Object
Returns the value of attribute verify_url.
2 3 4 |
# File 'lib/components/captcha.rb', line 2 def verify_url @verify_url end |
Instance Method Details
#enabled? ⇒ Boolean
4 |
# File 'lib/components/captcha.rb', line 4 def enabled?; !!enabled end |
#verify(request, params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/components/captcha.rb', line 6 def verify request, params recaptcha = nil Timeout::timeout(timeout || 3) do recaptcha = Net::HTTP.post_form URI.parse(verify_url), { 'privatekey' => private_key, 'remoteip' => request.ip, 'challenge' => params.recaptcha_challenge_field, 'response' => params.recaptcha_response_field } end result = recaptcha.body.split.map { |s| s.chomp } answer, error = result answer == 'true' end |