Module: QuickCaptcha::CaptchaUtils
- Included in:
- ControllerValidation, ViewHelpers
- Defined in:
- lib/quick_captcha/captcha_utils.rb
Class Method Summary collapse
- .simple_captcha_matches?(captcha, key) ⇒ Boolean
- .simple_captcha_passed!(key) ⇒ Object
- .simple_captcha_value(key) ⇒ Object
Instance Method Summary collapse
- #generate_simple_captcha_key ⇒ Object
- #simple_captcha_key ⇒ Object
- #simple_captcha_matches?(captcha) ⇒ Boolean
- #simple_captcha_passed! ⇒ Object
- #simple_captcha_value ⇒ Object
Class Method Details
.simple_captcha_matches?(captcha, key) ⇒ Boolean
12 13 14 |
# File 'lib/quick_captcha/captcha_utils.rb', line 12 def self.simple_captcha_matches?(captcha, key) captcha && captcha.delete(" ").upcase == simple_captcha_value(key) end |
.simple_captcha_passed!(key) ⇒ Object
16 17 18 |
# File 'lib/quick_captcha/captcha_utils.rb', line 16 def self.simple_captcha_passed!(key) SimpleCaptchaData.remove_data(key) end |
.simple_captcha_value(key) ⇒ Object
8 9 10 |
# File 'lib/quick_captcha/captcha_utils.rb', line 8 def self.simple_captcha_value(key) SimpleCaptchaData.get_data(key).value rescue nil end |
Instance Method Details
#generate_simple_captcha_key ⇒ Object
38 39 40 41 42 43 |
# File 'lib/quick_captcha/captcha_utils.rb', line 38 def generate_simple_captcha_key session_id = session[:id] || request.respond_to?(:session_options) ? request.[:id] : session.session_id Digest::SHA1.hexdigest(Time.now.to_s + session_id.to_s) end |
#simple_captcha_key ⇒ Object
34 35 36 |
# File 'lib/quick_captcha/captcha_utils.rb', line 34 def simple_captcha_key session[:simple_captcha] ||= generate_simple_captcha_key end |
#simple_captcha_matches?(captcha) ⇒ Boolean
24 25 26 |
# File 'lib/quick_captcha/captcha_utils.rb', line 24 def simple_captcha_matches?(captcha) QuickCaptcha::CaptchaUtils.simple_captcha_matches?(captcha, simple_captcha_key) end |
#simple_captcha_passed! ⇒ Object
28 29 30 31 32 |
# File 'lib/quick_captcha/captcha_utils.rb', line 28 def simple_captcha_passed! QuickCaptcha::CaptchaUtils.simple_captcha_passed!(simple_captcha_key).tap do session[:simple_captcha] = nil end end |
#simple_captcha_value ⇒ Object
20 21 22 |
# File 'lib/quick_captcha/captcha_utils.rb', line 20 def simple_captcha_value QuickCaptcha::CaptchaUtils.simple_captcha_value(simple_captcha_key) end |