fastcaptcha 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -13,14 +13,14 @@ REQUIREMENT:
13
13
  USAGE:
14
14
 
15
15
  >> require 'fastcaptcha'
16
- >> captcha = FastCaptcha.new # defaults to memcached and low complexity captchas.
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/redis2'
23
- >> captcha = FastCaptcha.new(Moneta::Redis2.new, 3) # use redis & level 3 complexity
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 - 10s is an aggressive but reasonable value.
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.0
1
+ 0.2.1
data/lib/fastcaptcha.rb CHANGED
@@ -41,7 +41,8 @@ class FastCaptcha
41
41
  end
42
42
 
43
43
  def cache_connection
44
- Moneta::Memcache.new
44
+ require 'moneta/redis2'
45
+ Moneta::Redis2.new
45
46
  end
46
47
 
47
48
  class Challenge
@@ -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 unless app.respond_to? :captcha_ttl
21
- app.set :captcha_level, 2 unless app.respond_to? :captcha_level
22
- app.set :captcha_width, 200 unless app.respond_to? :captcha_width
23
- app.set :captcha_height, 50 unless app.respond_to? :captcha_height
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
- divid = id + '_div'
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/#{divid}', function() {
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() {
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bharanee Rathna