Module: Sinatra::Captcha

Defined in:
lib/sinatra/captcha.rb

Constant Summary collapse

VERSION =
"0.1.0.0"

Instance Method Summary collapse

Instance Method Details

#captcha_answer_tagObject


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_tagObject


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

Returns:

  • (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_sessionObject


13
14
15
# File 'lib/sinatra/captcha.rb', line 13

def captcha_session
  @captcha_session ||= rand(9000) + 1000
end