fastcaptcha 0.2.0 → 0.2.1
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 +9 -4
- data/VERSION +1 -1
- data/lib/fastcaptcha.rb +2 -1
- data/lib/sinatra/captcha.rb +17 -8
- metadata +2 -2
data/README
CHANGED
|
@@ -13,14 +13,14 @@ REQUIREMENT:
|
|
|
13
13
|
USAGE:
|
|
14
14
|
|
|
15
15
|
>> require 'fastcaptcha'
|
|
16
|
-
>> captcha = FastCaptcha.new # defaults to
|
|
16
|
+
>> captcha = FastCaptcha.new # defaults to redis for caching and low complexity captchas.
|
|
17
17
|
>> challenge = captcha.generate
|
|
18
18
|
>> puts challenge.key
|
|
19
19
|
>> puts challenge.image # PNG image data
|
|
20
20
|
|
|
21
21
|
>> require 'fastcaptcha'
|
|
22
|
-
>> require 'moneta/
|
|
23
|
-
>> captcha = FastCaptcha.new(Moneta::
|
|
22
|
+
>> require 'moneta/memcache'
|
|
23
|
+
>> captcha = FastCaptcha.new(Moneta::Memcache.new, 3) # use memcached instead & level 3 complexity
|
|
24
24
|
>> challenge = captcha.generate
|
|
25
25
|
>> puts challenge.key
|
|
26
26
|
>> puts challenge.image # PNG image data
|
|
@@ -35,10 +35,15 @@ SINATRA HELPER:
|
|
|
35
35
|
|
|
36
36
|
require 'sinatra/captcha'
|
|
37
37
|
class MyApp < Sinatra::Base
|
|
38
|
-
# ttl of captcha before user has to respond
|
|
38
|
+
# ttl of captcha before user has to respond.
|
|
39
39
|
set :captcha_ttl, 30
|
|
40
|
+
|
|
40
41
|
# complexity 1 is simple, 4 is wicked hard (makes segmentation very difficult).
|
|
41
42
|
set :captcha_level, 2
|
|
43
|
+
|
|
44
|
+
# use memcached instead of redis (default).
|
|
45
|
+
# set :captcha_cache, Moneta::Memcache
|
|
46
|
+
|
|
42
47
|
register Sinatra::Captcha
|
|
43
48
|
end
|
|
44
49
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.1
|
data/lib/fastcaptcha.rb
CHANGED
data/lib/sinatra/captcha.rb
CHANGED
|
@@ -14,15 +14,24 @@ module Sinatra
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
module Captcha
|
|
17
|
+
def self.set_captcha_cache_class app
|
|
18
|
+
unless app.respond_to? :captcha_cache
|
|
19
|
+
require 'moneta/redis2'
|
|
20
|
+
app.set :captcha_cache, Moneta::Redis2
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
17
24
|
def self.registered app
|
|
18
25
|
app.helpers CaptchaHelpers
|
|
19
26
|
|
|
20
|
-
app.set :captcha_ttl, 60
|
|
21
|
-
app.set :captcha_level, 2
|
|
22
|
-
app.set :captcha_width, 200
|
|
23
|
-
app.set :captcha_height, 50
|
|
27
|
+
app.set :captcha_ttl, 60 unless app.respond_to? :captcha_ttl
|
|
28
|
+
app.set :captcha_level, 2 unless app.respond_to? :captcha_level
|
|
29
|
+
app.set :captcha_width, 200 unless app.respond_to? :captcha_width
|
|
30
|
+
app.set :captcha_height, 50 unless app.respond_to? :captcha_height
|
|
24
31
|
app.set :captcha_handler, Image.new(app)
|
|
25
32
|
|
|
33
|
+
set_captcha_cache_class(app)
|
|
34
|
+
|
|
26
35
|
app.get '/captcha/refresh' do
|
|
27
36
|
content_type 'text/plain'
|
|
28
37
|
app.captcha_handler.html('captcha', params['key'])
|
|
@@ -54,7 +63,7 @@ module Sinatra
|
|
|
54
63
|
@width, @height = app.captcha_width, app.captcha_height
|
|
55
64
|
end
|
|
56
65
|
|
|
57
|
-
def html id='captcha', key=nil
|
|
66
|
+
def html id = 'captcha', key = nil
|
|
58
67
|
challenge = @generator.generate @ttl, false
|
|
59
68
|
snippet = <<-HTML
|
|
60
69
|
<div id="#{id}">
|
|
@@ -67,8 +76,8 @@ module Sinatra
|
|
|
67
76
|
HTML
|
|
68
77
|
end
|
|
69
78
|
|
|
70
|
-
def ajax_html id='captcha_ajax'
|
|
71
|
-
|
|
79
|
+
def ajax_html id = 'captcha_ajax'
|
|
80
|
+
div_id = id + '_div'
|
|
72
81
|
snippet = <<-HTML
|
|
73
82
|
<script type="text/javascript">
|
|
74
83
|
$(document).ready(function() {
|
|
@@ -87,7 +96,7 @@ module Sinatra
|
|
|
87
96
|
function load_captcha_#{id}() {
|
|
88
97
|
$('##{id}_r').hide();
|
|
89
98
|
$('##{id}').slideDown(250);
|
|
90
|
-
$('##{id}').load('/captcha/snippet/#{
|
|
99
|
+
$('##{id}').load('/captcha/snippet/#{div_id}', function() {
|
|
91
100
|
$('##{id}').find('input[name="captcha[response]"]').focus();
|
|
92
101
|
});
|
|
93
102
|
$('##{id}').delay(#{@ttl*500}).slideUp(250, function() {
|