rucaptcha 0.3.1 → 0.3.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/CHANGELOG.md +6 -0
- data/README.md +11 -6
- data/app/controllers/ru_captcha/captcha_controller.rb +0 -1
- data/lib/rucaptcha/captcha.rb +8 -9
- data/lib/rucaptcha/configuration.rb +1 -1
- data/lib/rucaptcha/controller_helpers.rb +1 -1
- data/lib/rucaptcha/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 426e52c0e7d7b9691d077e57707d49893b8b8298
|
4
|
+
data.tar.gz: 1facb980237b56228e4f24758c63ac120b92895a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0365c36e90ed6ec817b2154161cd01d014bf29ab57ef27f54f04b7a9dda0ed0676cb9e4f7d1c452d7fff7ba688a2a8907fb80c32ac9f6c175e3635e05ab3ec69
|
7
|
+
data.tar.gz: d29fde1ca29dc61a041dc54891b0badd73e52add5a7e484dc42b66adc3363b07f06e2026d7d9d851d1b0cd892ab51787d4c83a4160305405fccc7163345d65ff
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Idea by: https://ruby-china.org/topics/20558#reply4
|
|
21
21
|
|
22
22
|
## Requirements
|
23
23
|
|
24
|
-
- ImageMagick
|
24
|
+
- ImageMagick
|
25
25
|
|
26
26
|
#### Ubuntu
|
27
27
|
|
@@ -37,9 +37,14 @@ brew install imagemagick ghostscript
|
|
37
37
|
|
38
38
|
## Example
|
39
39
|
|
40
|
-

|
41
|
+

|
42
|
+

|
43
|
+

|
44
|
+

|
45
|
+

|
46
|
+

|
47
|
+

|
43
48
|
|
44
49
|
## Usage
|
45
50
|
|
@@ -55,8 +60,8 @@ Create `config/initializers/rucaptcha.rb`
|
|
55
60
|
RuCaptcha.configure do
|
56
61
|
# Number of chars, default: 4
|
57
62
|
self.len = 4
|
58
|
-
# Image font size, default:
|
59
|
-
self.font_size =
|
63
|
+
# Image font size, default: 45
|
64
|
+
self.font_size = 45
|
60
65
|
# Cache generated images in file store, this is config files limit, default: 100
|
61
66
|
# set 0 to disable file cache.
|
62
67
|
self.cache_limit = 100
|
data/lib/rucaptcha/captcha.rb
CHANGED
@@ -14,7 +14,7 @@ module RuCaptcha
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def rand_line_top(text_top, font_size)
|
17
|
-
text_top + rand(font_size
|
17
|
+
text_top + rand(font_size * 0.7).to_i
|
18
18
|
end
|
19
19
|
|
20
20
|
# Create Captcha image by code
|
@@ -23,19 +23,17 @@ module RuCaptcha
|
|
23
23
|
all_left = 20
|
24
24
|
font_size = RuCaptcha.config.font_size
|
25
25
|
full_height = font_size
|
26
|
-
full_width =
|
26
|
+
full_width = font_size * chars.size
|
27
27
|
size = "#{full_width}x#{full_height}"
|
28
28
|
half_width = full_width / 2
|
29
29
|
full_height = full_height
|
30
30
|
half_height = full_height / 2
|
31
|
-
text_top =
|
31
|
+
text_top = 0
|
32
32
|
text_left = 0 - (font_size * 0.28).to_i
|
33
33
|
stroke_width = (font_size * 0.08).to_i + 1
|
34
|
-
text_width =
|
34
|
+
text_width = font_size + text_left
|
35
35
|
label = "=#{' ' * (chars.size - 1)}="
|
36
36
|
|
37
|
-
|
38
|
-
|
39
37
|
text_opts = []
|
40
38
|
line_opts = []
|
41
39
|
chars.each_with_index do |char, i|
|
@@ -44,8 +42,9 @@ module RuCaptcha
|
|
44
42
|
line_color = "rgba(#{rgb.join(',')}, 0.6)"
|
45
43
|
text_opts << %(-fill '#{text_color}' -draw 'text #{(text_left + text_width) * i + all_left},#{text_top} "#{char}"')
|
46
44
|
left_y = rand_line_top(text_top, font_size)
|
45
|
+
right_x = half_width + (half_width * 0.3).to_i
|
47
46
|
right_y = rand_line_top(text_top, font_size)
|
48
|
-
line_opts << %(-draw 'stroke #{line_color} line #{rand(10)},#{left_y} #{
|
47
|
+
line_opts << %(-draw 'stroke #{line_color} line #{rand(10)},#{left_y} #{right_x},#{right_y}')
|
49
48
|
end
|
50
49
|
|
51
50
|
command = <<-CODE
|
@@ -57,8 +56,8 @@ module RuCaptcha
|
|
57
56
|
-wave #{rand(2) + 3}x#{rand(2) + 1} \
|
58
57
|
-rotate #{rand(10) - 5} \
|
59
58
|
-gravity NorthWest -sketch 1x10+#{rand(2)} \
|
60
|
-
-fill
|
61
|
-
-implode #{RuCaptcha.config.implode} label:- png:-
|
59
|
+
-fill none \
|
60
|
+
-implode #{RuCaptcha.config.implode} -trim label:- png:-
|
62
61
|
CODE
|
63
62
|
|
64
63
|
command.strip!
|
@@ -16,7 +16,7 @@ module RuCaptcha
|
|
16
16
|
def verify_rucaptcha?(resource = nil)
|
17
17
|
rucaptcha_at = session[:_rucaptcha_at].to_i
|
18
18
|
# Captcha chars in Session expire in 2 minutes
|
19
|
-
if
|
19
|
+
if (Time.now.to_i - rucaptcha_at) > 120
|
20
20
|
return false
|
21
21
|
end
|
22
22
|
|
data/lib/rucaptcha/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rucaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: posix-spawn
|
@@ -113,3 +113,4 @@ specification_version: 4
|
|
113
113
|
summary: This is a Captcha gem for Rails Application. It run ImageMagick command to
|
114
114
|
draw Captcha image.
|
115
115
|
test_files: []
|
116
|
+
has_rdoc:
|