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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f4126818899ea31db41b60c51a036065f0fde3c
4
- data.tar.gz: 479910c2d5ad2b20c5e0f9f3eeb0c3d1a693c0bb
3
+ metadata.gz: 6a0b34dbfa1c17906e1aaa726c06f77988b2a50c
4
+ data.tar.gz: 52b25d9225d5243a8fb64f38c16a431cb20869e5
5
5
  SHA512:
6
- metadata.gz: 9f69f5ad7cf1e8737d8ccdf91e4b1788d00d3235f80882b20a42a58c5cb598247a8691e316f0771a5342047089d215ab3e11a34d2001f3b86cc43ccdfc822b0f
7
- data.tar.gz: 901e27f5873bed57c56ee6d637d49ebb78ece64bed5226ebef34678c4f8b19ca7347f30fb82e4432688459fd99a2c6150b333d14753e562e7cb7277e0de6d553
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
- class SimpleCaptchaInput < SimpleForm::Inputs::StringInput
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
@@ -0,0 +1,4 @@
1
+ module SimpleCaptchaReloaded
2
+ class Error < StandardError
3
+ end
4
+ 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: :random,
29
- image_styles: IMAGE_STYLES,
30
- noise: 0,
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
- tmp_path: nil)
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
- stderr_r, stderr_w = IO.pipe
79
- stdout_r, stdout_w = IO.pipe
80
- success = system(command, out: stdout_w, err: stderr_w)
81
- stdout_w.close; stderr_w.close
82
- output = stdout_r.read
83
- error = stderr_r.read
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
@@ -1,3 +1,3 @@
1
1
  module SimpleCaptchaReloaded
2
- VERSION = "0.1.0.beta1"
2
+ VERSION = "0.1.0"
3
3
  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.beta1
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: 1.3.1
230
+ version: '0'
230
231
  requirements: []
231
232
  rubyforge_project:
232
233
  rubygems_version: 2.2.2