sinatra-captcha 0.1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +33 -0
- data/lib/sinatra/captcha.rb +28 -0
- metadata +54 -0
data/README.markdown
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
* Quick, simple, easy captcha for Sinatra apps
|
2
|
+
|
3
|
+
<pre><code>
|
4
|
+
require 'rubygems'
|
5
|
+
require 'sinatra'
|
6
|
+
require 'sinatra/captcha'
|
7
|
+
|
8
|
+
get '/' do
|
9
|
+
erb :captcha
|
10
|
+
end
|
11
|
+
|
12
|
+
post '/' do
|
13
|
+
if captcha_pass?
|
14
|
+
halt 401, "invalid captcha"
|
15
|
+
else
|
16
|
+
"passed!"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
__END__
|
21
|
+
|
22
|
+
@@ captcha
|
23
|
+
|
24
|
+
<h1>Catcha Example</h1>
|
25
|
+
<form method="post" action="/">
|
26
|
+
<p><%= captcha_image_tag %></p>
|
27
|
+
<p><%= captcha_answer_tag %></div>
|
28
|
+
<div><input type="submit" value="Submit" /></div>
|
29
|
+
</form>
|
30
|
+
</code></pre>
|
31
|
+
|
32
|
+
Thank you to ERR THE BLOG for inspiration:
|
33
|
+
http://errtheblog.com/posts/43-captchator-on-rails
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
module Captcha
|
5
|
+
VERSION = "0.1.0.0"
|
6
|
+
|
7
|
+
def captcha_pass?
|
8
|
+
session = params[:captcha_session].to_i
|
9
|
+
answer = params[:captcha_answer].gsub(/\W/, '')
|
10
|
+
open("http://captchator.com/captcha/check_answer/#{session}/#{answer}").read.to_i.nonzero? rescue false
|
11
|
+
end
|
12
|
+
|
13
|
+
def captcha_session
|
14
|
+
@captcha_session ||= rand(9000) + 1000
|
15
|
+
end
|
16
|
+
|
17
|
+
def captcha_answer_tag
|
18
|
+
"<input id=\"captcha-answer\" name=\"captcha_answer\" type=\"text\" size=\"10\"/>"
|
19
|
+
end
|
20
|
+
|
21
|
+
def captcha_image_tag
|
22
|
+
"<input name=\"captcha_session\" type=\"hidden\" value=\"#{captcha_session}\"/>\n" +
|
23
|
+
"<img id=\"captcha-image\" src=\"http://captchator.com/captcha/image/#{captcha_session}\"/>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
helpers Captcha
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-captcha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blake Mizerany
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-29 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Simple, easy captcha for Sinatra
|
17
|
+
email: sinatrarb@googlegroups.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.markdown
|
26
|
+
- lib/sinatra/captcha.rb
|
27
|
+
has_rdoc: false
|
28
|
+
homepage: http://www.sinatrarb.com
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: "0"
|
39
|
+
version:
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project: sinatra-captcha
|
49
|
+
rubygems_version: 1.3.1
|
50
|
+
signing_key:
|
51
|
+
specification_version: 2
|
52
|
+
summary: Simple, easy captcha for Sinatra
|
53
|
+
test_files: []
|
54
|
+
|