rucaptcha 0.4.4 → 0.4.5
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 +4 -0
- data/README.md +11 -7
- data/lib/rucaptcha/cache.rb +1 -3
- data/lib/rucaptcha/captcha.rb +8 -13
- data/lib/rucaptcha/controller_helpers.rb +1 -1
- data/lib/rucaptcha/version.rb +1 -1
- data/lib/rucaptcha/view_helpers.rb +6 -6
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d19351a61db05ab5f038cca14190d70473117a8
|
4
|
+
data.tar.gz: 17f368f3e963f2bc89597ea6489c61eb1013be94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c92ef1378ecfba89ec2aca42e88336690cc23a8e24dde0e0dfeadfe9e9f60e9fd389f3921c3167f3f014b5dbbce9a0e1058a6d39c582ea36a2fc8b37767f1b9
|
7
|
+
data.tar.gz: b4f5acca22355975f074cc20d0ec6822c4960b8103993b9524e79ae2c4e696c83b34e755189d803a2ab6b91a0384e9840b234ae7f454a5b32223ca998afcb6cf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,16 +2,24 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/rucaptcha)
|
4
4
|
[](https://travis-ci.org/huacnlee/rucaptcha)
|
5
|
+
[](https://codeclimate.com/github/huacnlee/rucaptcha)
|
5
6
|
|
6
|
-
This is a Captcha gem for Rails Applications. It runs an ImageMagick command to draw Captcha image - so it has NO performance issues or memory leak issues.
|
7
|
+
This is a Captcha gem for Rails Applications. It runs an ImageMagick command to draw Captcha image - so it has NO performance issues or memory leak issues. **There is NO: RMagick**
|
7
8
|
|
8
|
-
|
9
|
+
## Example
|
10
|
+
|
11
|
+

|
12
|
+

|
13
|
+

|
14
|
+

|
15
|
+

|
16
|
+

|
17
|
+

|
9
18
|
|
10
19
|
Idea by: https://ruby-china.org/topics/20558#reply4
|
11
20
|
|
12
21
|
[中文介绍和使用说明](https://ruby-china.org/topics/27832)
|
13
22
|
|
14
|
-
|
15
23
|
## Feature
|
16
24
|
|
17
25
|
- Only need `ImageMagick`, No `RMagick`, No `mini_magick`;
|
@@ -35,10 +43,6 @@ sudo apt-get install imagemagick
|
|
35
43
|
brew install imagemagick ghostscript
|
36
44
|
```
|
37
45
|
|
38
|
-
## Example
|
39
|
-
|
40
|
-
       
|
41
|
-
|
42
46
|
## Usage
|
43
47
|
|
44
48
|
Put rucaptcha in your `Gemfile`:
|
data/lib/rucaptcha/cache.rb
CHANGED
@@ -33,9 +33,7 @@ module RuCaptcha
|
|
33
33
|
return @cache if defined?(@cache)
|
34
34
|
|
35
35
|
cache_path = Rails.root.join('tmp', 'cache', 'rucaptcha')
|
36
|
-
|
37
|
-
FileUtils.mkdir_p(cache_path)
|
38
|
-
end
|
36
|
+
FileUtils.mkdir_p(cache_path) unless File.exist? cache_path
|
39
37
|
@cache = ActiveSupport::Cache::FileStore.new(cache_path)
|
40
38
|
@cache.clear
|
41
39
|
@cache
|
data/lib/rucaptcha/captcha.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'open3'
|
2
2
|
|
3
3
|
module RuCaptcha
|
4
4
|
class Captcha
|
@@ -37,16 +37,13 @@ module RuCaptcha
|
|
37
37
|
full_width = font_size * chars.size
|
38
38
|
size = "#{full_width}x#{full_height}"
|
39
39
|
half_width = full_width / 2
|
40
|
-
full_height = full_height
|
41
|
-
half_height = full_height / 2
|
42
40
|
text_top = 0
|
43
41
|
text_left = 0 - (font_size * 0.28).to_i
|
44
|
-
stroke_width
|
42
|
+
stroke_width = (font_size * 0.05).to_i + 1
|
45
43
|
text_width = font_size + text_left
|
46
|
-
|
44
|
+
text_opts = []
|
45
|
+
line_opts = []
|
47
46
|
|
48
|
-
text_opts = []
|
49
|
-
line_opts = []
|
50
47
|
chars.each_with_index do |char, i|
|
51
48
|
rgb = random_color
|
52
49
|
text_color = "rgba(#{rgb.join(',')}, 1)"
|
@@ -76,15 +73,13 @@ module RuCaptcha
|
|
76
73
|
command = "convert -size #{size} xc:White -gravity Center -weight 12 -pointsize 20 -annotate 0 \"#{code}\" -trim #{png_file_path}"
|
77
74
|
require 'open3'
|
78
75
|
_stdout_str, stderr_str = Open3.capture3(command)
|
79
|
-
raise "RuCaptcha: #{stderr_str.strip}" if stderr_str
|
76
|
+
raise "RuCaptcha: #{stderr_str.strip}" if stderr_str.present?
|
80
77
|
png_file_path
|
81
78
|
else
|
82
79
|
command.strip!
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
raise "RuCaptcha: #{err.strip}" if err != nil && err.length > 0
|
87
|
-
stdout.read
|
80
|
+
out, err, st = Open3.capture3(command)
|
81
|
+
raise "RuCaptcha: #{err.strip}" if err.present?
|
82
|
+
out
|
88
83
|
end
|
89
84
|
end
|
90
85
|
end
|
data/lib/rucaptcha/version.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module RuCaptcha
|
2
2
|
module ViewHelpers
|
3
3
|
def rucaptcha_input_tag(opts = {})
|
4
|
-
opts[:name]
|
5
|
-
opts[:type]
|
6
|
-
opts[:autocorrect]
|
4
|
+
opts[:name] = '_rucaptcha'
|
5
|
+
opts[:type] = 'text'
|
6
|
+
opts[:autocorrect] = 'off'
|
7
7
|
opts[:autocapitalize] = 'off'
|
8
|
-
opts[:pattern]
|
9
|
-
opts[:maxlength]
|
10
|
-
opts[:autocomplete]
|
8
|
+
opts[:pattern] = '[0-9a-z]*'
|
9
|
+
opts[:maxlength] = RuCaptcha.config.len
|
10
|
+
opts[:autocomplete] = 'off'
|
11
11
|
tag(:input, opts)
|
12
12
|
end
|
13
13
|
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rucaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: posix-spawn
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.3.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|