glebtv-simple_captcha 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 449ca80c41d5dedc86f12d03538f9645a9dd7e45
4
- data.tar.gz: 1a903f97a8f9101aeb807985ba229a252cf9969d
3
+ metadata.gz: 47a8b5c8bb484cd2b5022fb384db818731ab3c93
4
+ data.tar.gz: 101a1df32291dee59eaead58a01f95da12569ac2
5
5
  SHA512:
6
- metadata.gz: bd15460ff8d8ae922861b09fd920cf3fc4d6f8b6dd62ff9a3043085aeb11fae2157ffe89436e6e8ccaff26a1e17193d2cceaa7440a3b37d19c176ea057d946ed
7
- data.tar.gz: 25670d30d876c24d618c04513a1ee6955e4a4338e5c79a89dc7306783517c10e90e0f904b9f533b134a97c20e33ffd0172d159f8893c64cfe4b3ccd2df2a8c86
6
+ metadata.gz: e668d2c8def78e544e9f8513fc8b027f84e3189cb99a409a8202c87696038f0fa856193f18887c6026a60f85e93c077dcf01242109096c6ef215af07279a27f1
7
+ data.tar.gz: a082ea8c8e449b34d729ca537b22161cdb367b46fad9c702e9e675c85a0090501bee291c32e999adb7e4187c12532c8b6e1f937e0bff51c814083ef4cc8d1f79
@@ -10,7 +10,7 @@ module SimpleCaptcha #:nodoc
10
10
  'red' => ['-alpha set', '-fill \#A5A5A5', '-background \#800E19', '-size 245x60', 'xc:\#800E19'],
11
11
  }
12
12
 
13
- DISTORTIONS = ['low', 'medium', 'high']
13
+ DISTORTIONS = ['none', 'low', 'medium', 'high']
14
14
 
15
15
  class << self
16
16
 
@@ -38,6 +38,7 @@ module SimpleCaptcha #:nodoc
38
38
  DISTORTIONS[rand(DISTORTIONS.length)] :
39
39
  DISTORTIONS.include?(key) ? key : 'low'
40
40
  case key.to_s
41
+ when 'none' then return [0, 100]
41
42
  when 'low' then return [0 + rand(2), 80 + rand(20)]
42
43
  when 'medium' then return [2 + rand(2), 50 + rand(20)]
43
44
  when 'high' then return [4 + rand(2), 30 + rand(20)]
@@ -56,6 +57,9 @@ module SimpleCaptcha #:nodoc
56
57
  end
57
58
 
58
59
  private
60
+ def letter_width
61
+ SimpleCaptcha.pointsize * 0.7
62
+ end
59
63
 
60
64
  def generate_simple_captcha_image(simple_captcha_key) #:nodoc
61
65
  amplitude, frequency = ImageHelpers.distortion(SimpleCaptcha.distortion)
@@ -75,17 +79,24 @@ module SimpleCaptcha #:nodoc
75
79
 
76
80
  dst = Tempfile.new(RUBY_VERSION < '1.9' ? 'simple_captcha.png' : ['simple_captcha', '.png'], SimpleCaptcha.tmp_path)
77
81
  dst.binmode
78
- text.split(//).each_with_index do |letter, index|
79
- i = -(2 * psz) + (index * 0.7 * psz) + rand(-3..3)
80
- params << "-draw \"translate #{i},#{rand(-3..3)} skewX #{rand(-15..15)} gravity center text 0,0 '#{letter}'\" "
82
+
83
+ letters = text.split(//)
84
+ text_width = letters.size * letter_width
85
+
86
+ letters.each_with_index do |letter, index|
87
+ translate = SimpleCaptcha.distortion == 'none' ? '' : "translate #{rand(-3..3)},#{rand(-3..3)} skewX #{rand(-15..15)}"
88
+ offset = index * letter_width - ( text_width - letter_width ) / 2
89
+ params << "-draw \"#{translate} gravity center text #{offset},0 '#{letter}'\" "
81
90
  end
82
91
 
83
- params << "-wave #{amplitude}x#{frequency}"
92
+ unless SimpleCaptcha.distortion == 'none'
93
+ params << "-wave #{amplitude}x#{frequency}"
84
94
 
85
- unless params.join(' ').index('-size').nil?
86
- size = params.join(' ').match '-size (\d+)x(\d+)'
87
- (1..SimpleCaptcha.wave_count).each do |i|
88
- params << "-draw \"polyline #{rand(size[1].to_i)},#{rand(size[2].to_i)} #{rand(size[1].to_i)},#{rand(size[2].to_i)}\""
95
+ unless params.join(' ').index('-size').nil?
96
+ size = params.join(' ').match '-size (\d+)x(\d+)'
97
+ (1..SimpleCaptcha.wave_count).each do |i|
98
+ params << "-draw \"polyline #{rand(size[1].to_i)},#{rand(size[2].to_i)} #{rand(size[1].to_i)},#{rand(size[2].to_i)}\""
99
+ end
89
100
  end
90
101
  end
91
102
 
@@ -54,6 +54,8 @@ module SimpleCaptcha #:nodoc
54
54
  end
55
55
 
56
56
  def is_captcha_valid?
57
+ return true if captcha.present? && Rails.env.test?
58
+
57
59
  v = SimpleCaptcha::Utils::simple_captcha_value(captcha_key)
58
60
  if captcha && !v.nil? && captcha.upcase.delete(" ") == v.upcase
59
61
  SimpleCaptcha::Utils::simple_captcha_passed!(captcha_key)
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module SimpleCaptcha
4
- VERSION = "0.6.1".freeze
4
+ VERSION = "0.6.2".freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glebtv-simple_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GlebTv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-10 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -31,27 +31,27 @@ extensions: []
31
31
  extra_rdoc_files:
32
32
  - README.rdoc
33
33
  files:
34
- - lib/simple_captcha.rb
35
- - lib/generators/simple_captcha_generator.rb
34
+ - README.rdoc
35
+ - Rakefile
36
36
  - lib/generators/USAGE
37
+ - lib/generators/simple_captcha_generator.rb
37
38
  - lib/generators/templates/migration.rb
38
39
  - lib/generators/templates/partial.erb
39
- - lib/simple_captcha/version.rb
40
+ - lib/glebtv-simple_captcha.rb
41
+ - lib/simple_captcha.rb
42
+ - lib/simple_captcha/controller.rb
40
43
  - lib/simple_captcha/engine.rb
41
- - lib/simple_captcha/utils.rb
42
- - lib/simple_captcha/storage/active_record.rb
43
- - lib/simple_captcha/storage/mongoid.rb
44
+ - lib/simple_captcha/hooks/form_builder.rb
45
+ - lib/simple_captcha/hooks/formtastic.rb
46
+ - lib/simple_captcha/hooks/simple_form.rb
44
47
  - lib/simple_captcha/image.rb
45
- - lib/simple_captcha/view.rb
46
48
  - lib/simple_captcha/middleware.rb
47
49
  - lib/simple_captcha/model_helpers.rb
48
- - lib/simple_captcha/controller.rb
49
- - lib/simple_captcha/hooks/simple_form.rb
50
- - lib/simple_captcha/hooks/form_builder.rb
51
- - lib/simple_captcha/hooks/formtastic.rb
52
- - lib/glebtv-simple_captcha.rb
53
- - Rakefile
54
- - README.rdoc
50
+ - lib/simple_captcha/storage/active_record.rb
51
+ - lib/simple_captcha/storage/mongoid.rb
52
+ - lib/simple_captcha/utils.rb
53
+ - lib/simple_captcha/version.rb
54
+ - lib/simple_captcha/view.rb
55
55
  homepage: http://github.com/glebtv/simple-captcha
56
56
  licenses: []
57
57
  metadata: {}
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  version: '0'
72
72
  requirements: []
73
73
  rubyforge_project:
74
- rubygems_version: 2.1.10
74
+ rubygems_version: 2.2.1
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: A fork of a fork of a fork of simple_captcha.