Module: Sinatra::Captcha
- Defined in:
- lib/sinatra/captcha.rb
Constant Summary collapse
- VERSION =
"0.1.0.0"
Instance Method Summary collapse
- #captcha_answer_tag ⇒ Object
- #captcha_image_tag ⇒ Object
- #captcha_pass? ⇒ Boolean
- #captcha_session ⇒ Object
Instance Method Details
#captcha_answer_tag ⇒ Object
17 18 19 |
# File 'lib/sinatra/captcha.rb', line 17 def captcha_answer_tag "<input id=\"captcha-answer\" name=\"captcha_answer\" type=\"text\" size=\"10\"/>" end |
#captcha_image_tag ⇒ Object
21 22 23 24 |
# File 'lib/sinatra/captcha.rb', line 21 def captcha_image_tag "<input name=\"captcha_session\" type=\"hidden\" value=\"#{captcha_session}\"/>\n" + "<img id=\"captcha-image\" src=\"http://captchator.com/captcha/image/#{captcha_session}\"/>" end |
#captcha_pass? ⇒ Boolean
7 8 9 10 11 |
# File 'lib/sinatra/captcha.rb', line 7 def captcha_pass? session = params[:captcha_session].to_i answer = params[:captcha_answer].gsub(/\W/, '') open("http://captchator.com/captcha/check_answer/#{session}/#{answer}").read.to_i.nonzero? rescue false end |
#captcha_session ⇒ Object
13 14 15 |
# File 'lib/sinatra/captcha.rb', line 13 def captcha_session @captcha_session ||= rand(9000) + 1000 end |