glebtv-simple_captcha 0.6.1 → 0.6.2
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.
- checksums.yaml +4 -4
- data/lib/simple_captcha/image.rb +20 -9
- data/lib/simple_captcha/model_helpers.rb +2 -0
- data/lib/simple_captcha/version.rb +1 -1
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47a8b5c8bb484cd2b5022fb384db818731ab3c93
|
4
|
+
data.tar.gz: 101a1df32291dee59eaead58a01f95da12569ac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e668d2c8def78e544e9f8513fc8b027f84e3189cb99a409a8202c87696038f0fa856193f18887c6026a60f85e93c077dcf01242109096c6ef215af07279a27f1
|
7
|
+
data.tar.gz: a082ea8c8e449b34d729ca537b22161cdb367b46fad9c702e9e675c85a0090501bee291c32e999adb7e4187c12532c8b6e1f937e0bff51c814083ef4cc8d1f79
|
data/lib/simple_captcha/image.rb
CHANGED
@@ -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
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
92
|
+
unless SimpleCaptcha.distortion == 'none'
|
93
|
+
params << "-wave #{amplitude}x#{frequency}"
|
84
94
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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)
|
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.
|
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-
|
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
|
-
-
|
35
|
-
-
|
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
|
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/
|
42
|
-
- lib/simple_captcha/
|
43
|
-
- lib/simple_captcha/
|
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/
|
49
|
-
- lib/simple_captcha/
|
50
|
-
- lib/simple_captcha/
|
51
|
-
- lib/simple_captcha/
|
52
|
-
- lib/
|
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
|
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.
|