simple_captcha_reloaded 0.1.0.beta1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/config/locales/simple_captcha.en.yml +7 -0
- data/lib/simple_captcha_reloaded/adapters/simple_form.rb +6 -1
- data/lib/simple_captcha_reloaded/config.rb +2 -0
- data/lib/simple_captcha_reloaded/engine.rb +5 -3
- data/lib/simple_captcha_reloaded/error.rb +4 -0
- data/lib/simple_captcha_reloaded/image.rb +23 -17
- data/lib/simple_captcha_reloaded/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a0b34dbfa1c17906e1aaa726c06f77988b2a50c
|
4
|
+
data.tar.gz: 52b25d9225d5243a8fb64f38c16a431cb20869e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b783a5cc40dec2af2d423600b632681a7df1436c71e6ee7beb882f907555a1b2eb5013966f677ea5e6ac7d32c2783d5a0c54d865651e30c3a782387f810ef829
|
7
|
+
data.tar.gz: c05b24ccb8fce886dc2a9f13a9578c064465c3423aeac1f8f4e029614188cd872c9fc92e0dd949ebd64410e2a3628ca3a85ddfca8949e277f1ce5fae4dd02492
|
data/README.md
CHANGED
@@ -40,6 +40,13 @@ gem 'simple_captcha_reloaded'
|
|
40
40
|
and run ``bundle install``.
|
41
41
|
|
42
42
|
|
43
|
+
Install the migration to create the captcha data table:
|
44
|
+
|
45
|
+
```
|
46
|
+
rake simple_captcha_reloaded:install:migrations
|
47
|
+
rake db:migrate
|
48
|
+
```
|
49
|
+
|
43
50
|
### Integration 1: Model based
|
44
51
|
|
45
52
|
Just integrate the module into on of your ActiveModel::Model compliant Models:
|
@@ -5,3 +5,10 @@ en:
|
|
5
5
|
blank: 'Please fill in the words above'
|
6
6
|
wrong: 'The entered text was not correct. Please try again.'
|
7
7
|
refresh_button_html: 'Refresh'
|
8
|
+
de:
|
9
|
+
simple_captcha_reloaded:
|
10
|
+
errors:
|
11
|
+
missing_captcha: 'Captcha nicht gefunden'
|
12
|
+
blank: 'Bitte geben Sie den obigen Text ein'
|
13
|
+
wrong: 'Der eingebene Text war leider nicht richtig. Bitte probieren Sie es erneut.'
|
14
|
+
refresh_button_html: 'Neu laden'
|
@@ -1,5 +1,10 @@
|
|
1
1
|
require 'simple_form/version'
|
2
|
-
|
2
|
+
# to accommodate for the Bootstrap 3 Simple Form config
|
3
|
+
superclass = SimpleForm::Inputs::StringInput
|
4
|
+
if defined?(StringInput)
|
5
|
+
superclass = StringInput
|
6
|
+
end
|
7
|
+
class SimpleCaptchaInput < superclass
|
3
8
|
def input(wrapper_options=nil)
|
4
9
|
set_options
|
5
10
|
@captcha = SimpleCaptchaReloaded.generate_captcha(id: options[:captcha][:id], request: template.request)
|
@@ -3,6 +3,7 @@ class SimpleCaptchaReloaded::Config
|
|
3
3
|
cattr_accessor :image
|
4
4
|
cattr_accessor :characters
|
5
5
|
cattr_accessor :length
|
6
|
+
cattr_accessor :timeout
|
6
7
|
|
7
8
|
def self.image_url(code, request)
|
8
9
|
time = Time.now.to_i
|
@@ -37,5 +38,6 @@ SimpleCaptchaReloaded::Config.tap do |config|
|
|
37
38
|
config.image = SimpleCaptchaReloaded::Image.new
|
38
39
|
config.characters = %w[a b c d e f g h j k m n p q r s t u v w x y z 0 2 3 4 5 6 8 9]
|
39
40
|
config.length = 6
|
41
|
+
config.timeout = 3
|
40
42
|
end
|
41
43
|
|
@@ -4,15 +4,17 @@ module SimpleCaptchaReloaded
|
|
4
4
|
class Engine < ::Rails::Engine
|
5
5
|
isolate_namespace SimpleCaptchaReloaded
|
6
6
|
initializer "simple_captcha.load" do |app|
|
7
|
-
if defined?(SimpleForm)
|
8
|
-
require 'simple_captcha_reloaded/adapters/simple_form'
|
9
|
-
end
|
10
7
|
ActiveSupport.on_load :action_controller do
|
11
8
|
helper SimpleCaptchaReloaded::ViewHelper
|
12
9
|
ActionController::Base.send(:include, SimpleCaptchaReloaded::ControllerHelper)
|
13
10
|
end
|
14
11
|
app.middleware.use SimpleCaptchaReloaded::Middleware
|
15
12
|
end
|
13
|
+
config.after_initialize do
|
14
|
+
if defined?(SimpleForm)
|
15
|
+
require 'simple_captcha_reloaded/adapters/simple_form'
|
16
|
+
end
|
17
|
+
end
|
16
18
|
|
17
19
|
end
|
18
20
|
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'open3'
|
2
|
+
require 'timeout'
|
3
|
+
require 'simple_captcha_reloaded/error'
|
4
|
+
|
2
5
|
module SimpleCaptchaReloaded
|
3
6
|
class Image
|
4
7
|
IMAGE_STYLES = {
|
@@ -25,12 +28,12 @@ module SimpleCaptchaReloaded
|
|
25
28
|
}
|
26
29
|
|
27
30
|
def initialize(implode: :medium,
|
28
|
-
distortion: :
|
29
|
-
image_styles: IMAGE_STYLES,
|
30
|
-
noise:
|
31
|
+
distortion: :medium,
|
32
|
+
image_styles: IMAGE_STYLES.slice('simply_red', 'simply_green', 'simply_blue'),
|
33
|
+
noise: 1,
|
31
34
|
size: '100x28',
|
32
|
-
image_magick_path: ''
|
33
|
-
|
35
|
+
image_magick_path: '')
|
36
|
+
|
34
37
|
@implode = implode
|
35
38
|
@distortion = distortion
|
36
39
|
if !DISTORTIONS.keys.include?(@distortion)
|
@@ -41,13 +44,12 @@ module SimpleCaptchaReloaded
|
|
41
44
|
@noise = noise
|
42
45
|
@size = size
|
43
46
|
@image_magick_path = image_magick_path
|
44
|
-
@tmp_path = tmp_path
|
45
47
|
end
|
46
48
|
|
47
49
|
def generate(text)
|
48
50
|
amplitude, frequency = calculate_distortion
|
49
51
|
|
50
|
-
params = image_params
|
52
|
+
params = image_params.dup
|
51
53
|
params << "-size #{@size}"
|
52
54
|
params << "-wave #{amplitude}x#{frequency}"
|
53
55
|
params << "-gravity Center"
|
@@ -56,7 +58,7 @@ module SimpleCaptchaReloaded
|
|
56
58
|
params << "label:#{text}"
|
57
59
|
params << "-evaluate Uniform-noise #{@noise}"
|
58
60
|
params << "jpeg:-"
|
59
|
-
run("convert", params.join(' '))
|
61
|
+
run("convert", params: params.join(' '))
|
60
62
|
end
|
61
63
|
|
62
64
|
protected
|
@@ -69,22 +71,26 @@ module SimpleCaptchaReloaded
|
|
69
71
|
@distortion_function.call()
|
70
72
|
end
|
71
73
|
|
72
|
-
def run(cmd, params
|
74
|
+
def run(cmd, params: "", count: 0)
|
73
75
|
command = %Q[#{cmd} #{params}].gsub(/\s+/, " ")
|
74
76
|
command = "#{command} 2>&1"
|
75
77
|
unless (image_magick_path = @image_magick_path).blank?
|
76
78
|
command = File.join(image_magick_path, command)
|
77
79
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
unless success
|
85
|
-
raise ::StandardError, "Error while running #{command}\n Exit Code: #{$?}\n stderr:#{error.inspect}\n stdout:#{output.inspect}"
|
80
|
+
output = nil
|
81
|
+
Timeout::timeout(SimpleCaptchaReloaded::Config.timeout) {
|
82
|
+
output = `#{command}`
|
83
|
+
}
|
84
|
+
unless $?.success?
|
85
|
+
raise SimpleCaptchaReloaded::Error, "Error while running #{command}\n Exit Code: #{$?}\n stdout:#{output.inspect}"
|
86
86
|
end
|
87
87
|
output
|
88
|
+
rescue Timeout::Error
|
89
|
+
if count > 3
|
90
|
+
run(cmd, params: params, count: count + 1)
|
91
|
+
else
|
92
|
+
raise SimpleCaptchaReloaded::Error, "Error while running #{command} #{count + 1} times. Timed out after #{SimpleCaptchaReloaded::Config.timeout} seconds."
|
93
|
+
end
|
88
94
|
end
|
89
95
|
end
|
90
96
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_captcha_reloaded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Wienert
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- lib/simple_captcha_reloaded/config.rb
|
204
204
|
- lib/simple_captcha_reloaded/controller_helper.rb
|
205
205
|
- lib/simple_captcha_reloaded/engine.rb
|
206
|
+
- lib/simple_captcha_reloaded/error.rb
|
206
207
|
- lib/simple_captcha_reloaded/image.rb
|
207
208
|
- lib/simple_captcha_reloaded/middleware.rb
|
208
209
|
- lib/simple_captcha_reloaded/model.rb
|
@@ -224,9 +225,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
225
|
version: '0'
|
225
226
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
226
227
|
requirements:
|
227
|
-
- - "
|
228
|
+
- - ">="
|
228
229
|
- !ruby/object:Gem::Version
|
229
|
-
version:
|
230
|
+
version: '0'
|
230
231
|
requirements: []
|
231
232
|
rubyforge_project:
|
232
233
|
rubygems_version: 2.2.2
|