winton-captcha 1.2.0 → 1.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.
@@ -7,12 +7,11 @@ Goals
7
7
  -----
8
8
 
9
9
  * Batch generate captchas
10
- * Use ciphered filenames (no need to store filename/captcha code pairs)
11
- * Captchas refresh automatically
10
+ * Use ciphered filenames (no need to store filename/captcha pairs)
12
11
  * Easy configuration
13
- ** Number of captchas
14
- ** Period for captcha refresh
15
- ** Colors, wave, implode
12
+ * Number of captchas
13
+ * Period for captcha refresh
14
+ * Colors, wave, implode
16
15
  * Handle lots of users
17
16
 
18
17
  Install
@@ -42,13 +41,7 @@ Captcha::Config.new(
42
41
 
43
42
  See <code>lib/captcha/config.rb</code> for more options.
44
43
 
45
- ### Add public/images/captchas/* to your .gitignore file
46
-
47
- <pre>
48
- public/images/captchas/*
49
- </pre>
50
-
51
- ### Add acts\_as\_captcha to application_controller.rb
44
+ ### application_controller.rb
52
45
 
53
46
  <pre>
54
47
  class ApplicationController < ActionController::Base
@@ -58,7 +51,7 @@ end
58
51
 
59
52
  You may now use the <code>reset_captcha</code> method in any controller.
60
53
 
61
- ### Add acts\_as\_captcha to your model
54
+ ### user.rb
62
55
 
63
56
  <pre>
64
57
  class User < ActiveRecord::Base
@@ -66,9 +59,9 @@ class User < ActiveRecord::Base
66
59
  end
67
60
  </pre>
68
61
 
69
- No parameters behaves like <code>:field => true</code>, a default error is added to the "captcha" field.
62
+ With no parameters, a default error is added to the "captcha" field (<code>:field => true</code>).
70
63
 
71
- Use <code>:base => true</code> to activate a default error for base.
64
+ Specify <code>:base => true</code> to use a default error for base.
72
65
 
73
66
  ### In your view
74
67
 
@@ -84,4 +77,13 @@ user = User.new
84
77
  user.known_captcha = session[:captcha]
85
78
  user.captcha = params[:captcha]
86
79
  user.save
87
- </pre>
80
+ reset_captcha
81
+ </pre>
82
+
83
+ ### crontab
84
+
85
+ <pre>
86
+ 0 0 * * * cd /path/to/rails/app && /usr/bin/rake RAILS_ENV=production captcha:generate
87
+ </pre>
88
+
89
+ Your config file sets the captcha refresh period. The rake task just checks if its time to repopulate, and does so if necessary.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'captcha'
3
- s.version = '1.2.0'
3
+ s.version = '1.2.1'
4
4
  s.date = '2009-03-27'
5
5
 
6
6
  s.summary = "A Google-style captcha for enterprise Rails apps"
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  spec/lib/captcha_spec.rb
31
31
  spec/spec.opts
32
32
  spec/spec_helper.rb
33
+ tasks/captcha.rake
33
34
  ]
34
35
  # = MANIFEST =
35
36
  end
data/init.rb CHANGED
@@ -4,5 +4,4 @@ if defined?(RAILS_ROOT) && File.exists?("#{RAILS_ROOT}/lib/captcha_config.rb")
4
4
  end
5
5
 
6
6
  ActionController::Base.send :include, Captcha::Action
7
- ActiveRecord::Base.send :include, Captcha::Model
8
- Captcha::Generator.new
7
+ ActiveRecord::Base.send :include, Captcha::Model
@@ -10,8 +10,6 @@ module Captcha
10
10
  end
11
11
  ONE_DAY = 24 * 60 * 60
12
12
 
13
- @@exists = {}
14
- @@exists_since = Time.now
15
13
  @@options = {
16
14
  :password => 'captcha',
17
15
  :colors => {
@@ -66,14 +64,7 @@ module Captcha
66
64
  end
67
65
 
68
66
  def self.exists?(code)
69
- if Time.now - @@exists_since > 60 * 60
70
- @@exists = {}
71
- @@exists_since = Time.now
72
- end
73
- unless @@exists[code]
74
- @@exists[code] = File.exists?("#{@@options[:destination]}/#{code}.jpg")
75
- end
76
- @@exists[code]
67
+ File.exists?("#{@@options[:destination]}/#{code}.jpg")
77
68
  end
78
69
 
79
70
  def self.options
@@ -82,7 +73,7 @@ module Captcha
82
73
 
83
74
  def self.last_modified
84
75
  file = self.captchas.first
85
- if file
76
+ if file && File.exists?(file)
86
77
  File.mtime(file)
87
78
  else
88
79
  nil
@@ -8,10 +8,10 @@ module Captcha
8
8
  return unless Config.options
9
9
  return if Config.last_modified && Config.last_modified > Time.now - Config.options[:generate_every]
10
10
  path = Config.options[:destination]
11
- if File.exists?(path)
12
- FileUtils.rm_rf Config.options[:destination]
11
+ Config.captchas.each do |captcha|
12
+ FileUtils.rm_f captcha
13
13
  end
14
- FileUtils.mkdir_p Config.options[:destination]
14
+ FileUtils.mkdir_p path
15
15
  (1..Config.options[:count]).each do |x|
16
16
  image = Image.new Config.options
17
17
  path = "#{Config.options[:destination]}/#{Cipher.encrypt(image.code)}.jpg"
@@ -23,6 +23,12 @@ describe :captcha do
23
23
  @generator.generate
24
24
  codes.should_not == Captcha::Config.codes
25
25
  end
26
+ it "should not regenerate before the files are older than the generate_every option" do
27
+ codes = Captcha::Config.codes
28
+ sleep 1
29
+ @generator.generate
30
+ codes.should == Captcha::Config.codes
31
+ end
26
32
  it "should not allow more than the captcha limit to exist" do
27
33
  sleep @delay
28
34
  @generator.generate
@@ -0,0 +1,6 @@
1
+ namespace :captcha do
2
+ desc 'Generate a batch of captchas'
3
+ task :generate => :environment do
4
+ Captcha::Generator.new
5
+ end
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winton-captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
@@ -38,6 +38,7 @@ files:
38
38
  - spec/lib/captcha_spec.rb
39
39
  - spec/spec.opts
40
40
  - spec/spec_helper.rb
41
+ - tasks/captcha.rake
41
42
  has_rdoc: false
42
43
  homepage: http://github.com/winton/captcha
43
44
  post_install_message: