kandr-easy_captcha 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b4731d62f91a4a804c690b30a493cf074e34751543049631b5298ef675e1216c
4
+ data.tar.gz: '055049676e7c65dedd644969e72ecf6500cfbc144e2177c8f4725b16d42eb86b'
5
+ SHA512:
6
+ metadata.gz: 4d8f84fa675cde65fd4ec50f213be9f869bf53a21b4c4a809f87d232a42cab9fc1b418e138d5a32d62a69fefbe3b52f53a8a0140b8025106bc23cdee76f0a855
7
+ data.tar.gz: bc33b0c978c9a3ea507c12a6ec1fd86fb96fe9f4f9ee772a41a875075a60740ad81873002956d3beebfabcd96b98b84342af62192f778c2e94ff56d3770d86d4
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Marco Scholl
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,179 @@
1
+ = EasyCAPTCHA
2
+
3
+ A simple captcha implementation for Rails 5+ based on RMagick.
4
+
5
+ This (`kandr-easy_captcha`) is a fork of [EasyCaptcha](https://github.com/phatworx/easy_captcha) (`easy_captcha`) with Rails 5+ support. This fork is maintained by Karl Wilbur/K&R Software (karl@kandrsoftware.com).
6
+
7
+ == Dependencies
8
+
9
+ RMagick should be included in your `Gemfile`
10
+
11
+ ```
12
+ gem 'rmagick'
13
+ ```
14
+
15
+ for Java/JRuby you can use
16
+
17
+ ```ruby
18
+ gem 'rmagick4j'
19
+ ```
20
+
21
+ == Installation
22
+
23
+ add to Gemfile
24
+
25
+ ```ruby
26
+ gem 'kandr-easy_captcha', require: 'easy_captcha'
27
+ ```
28
+
29
+ after running `bundle install`, execute
30
+
31
+ ```bash
32
+ rails g easy_captcha:install
33
+ ```
34
+
35
+ == Configuration
36
+
37
+ You can configure `easy_captcha` in `config/initializers/easy_captcha.rb`, if you want to customize the default configuration
38
+
39
+ ```ruby
40
+ EasyCaptcha.setup do |config|
41
+ # Cache
42
+ # config.cache = true
43
+ # Cache temp dir from Rails.root
44
+ # config.cache_temp_dir = Rails.root.join('tmp', 'captchas')
45
+ # Cache size
46
+ # config.cache_size = 500
47
+ # Cache expire
48
+ # config.cache_expire = 1.day
49
+
50
+ # Chars
51
+ # config.chars = %w(2 3 4 5 6 7 9 A C D E F G H J K L M N P Q R S T U X Y Z)
52
+
53
+ # Length
54
+ # config.length = 6
55
+
56
+ # Image
57
+ # config.image_height = 40
58
+ # config.image_width = 140
59
+
60
+ # eSpeak (default disabled)
61
+ # config.espeak do |espeak|
62
+ # Amplitude, 0 to 200
63
+ # espeak.amplitude = 80..120
64
+
65
+ # Word gap. Pause between words
66
+ # espeak.gap = 80
67
+
68
+ # Pitch adjustment, 0 to 99
69
+ # espeak.pitch = 30..70
70
+
71
+ # Use voice file of this name from espeak-data/voices
72
+ # espeak.voice = nil
73
+ # end
74
+
75
+ # configure generator
76
+ # config.generator :default do |generator|
77
+
78
+ # Font
79
+ # generator.font_size = 24
80
+ # generator.font_fill_color = '#333333'
81
+ # generator.font_stroke_color = '#000000'
82
+ # generator.font_stroke = 0
83
+ # generator.font = File.expand_path('../../resources/afont.ttf', __FILE__)
84
+
85
+
86
+ # Background color
87
+ # generator.image_background_color = "#FFFFFF"
88
+ # Or background image (e.g. transparent png)
89
+ # generator.background_image = File.expand_path('../../resources/captcha_bg.png', __FILE__)
90
+
91
+ # Wave
92
+ # generator.wave = true
93
+ # generator.wave_length = (60..100)
94
+ # generator.wave_amplitude = (3..5)
95
+
96
+ # Sketch
97
+ # generator.sketch = true
98
+ # generator.sketch_radius = 3
99
+ # generator.sketch_sigma = 1
100
+
101
+ # Implode
102
+ # generator.implode = 0.1
103
+
104
+ # Blur
105
+ # generator.blur = true
106
+ # generator.blur_radius = 1
107
+ # generator.blur_sigma = 2
108
+ # end
109
+ end
110
+ ```
111
+
112
+ == Caching
113
+
114
+ It is strongly recommended to enable caching. You can see the three paramters which you have to fill in your config file below.
115
+
116
+ ```ruby
117
+ EasyCaptcha.setup do |config|
118
+ # Cache
119
+ config.cache = true
120
+ # Cache temp dir from Rails.root
121
+ config.cache_temp_dir = Rails.root.join('tmp', 'captchas')
122
+ # Cache expire
123
+ config.cache_expire = 1.day
124
+ # Cache size
125
+ # config.cache_size = 500
126
+ end
127
+ ```
128
+
129
+ == Requirements
130
+
131
+ * RMagick
132
+ * Rails 3 (http://github.com/rails/rails)
133
+
134
+ == Example
135
+
136
+ ```ruby
137
+ <% form_tag '/' do %>
138
+ <% if request.post? %>
139
+ <p><%= valid_captcha?(params[:captcha]) ? 'valid' : 'invalid' %> captcha</p>
140
+ <% end %>
141
+ <p><%= captcha_tag %></p>
142
+ <p><%= text_field_tag :captcha %></p>
143
+ <p><%= submit_tag 'Validate' %></p>
144
+ <% end %>
145
+ ```
146
+
147
+ == Example app
148
+
149
+ You find an example app under: http://github.com/phatworx/easy_captcha_example
150
+
151
+ == History
152
+
153
+ * 0.1 init
154
+ * 0.2 cache support for high frequented sites
155
+ * 0.3 use generators, optimizations, update licence to same of all my plugins
156
+ * 0.4 generator support
157
+ * 0.5 (transparent) background support
158
+ * 0.6 espeak support for barrier-free support
159
+
160
+ == Maintainers
161
+
162
+ * Team Phatworx (http://github.com/phatworx)
163
+ * Marco Scholl (http://github.com/traxanos)
164
+ * Alexander Dreher (http://github.com/alexdreher)
165
+ * Christoph Chilian (http://github.com/cc-web)
166
+
167
+ == Contributing to EasyCaptcha
168
+
169
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
170
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
171
+ * Fork the project
172
+ * Start a feature/bugfix branch
173
+ * Commit and push until you are happy with your contribution
174
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
175
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
176
+
177
+ == Copyright
178
+
179
+ Copyright (c) 2010 Marco Scholl. See LICENSE.txt for further details.
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
4
+
5
+ RSpec.describe EasyCaptcha::Espeak do
6
+ context 'with default values' do
7
+ subject(:captcha) { described_class.new }
8
+
9
+ let(:amplitude_range) { 80..120 }
10
+ let(:pitch_range) { 30..70 }
11
+
12
+ specify(:amplitude) { expect(amplitude_range).to include(captcha.amplitude) }
13
+ specify(:pitch) { expect(pitch_range).to include(captcha.pitch) }
14
+ specify(:gap) { expect(captcha.gap).to eq 80 }
15
+ specify(:voice) { expect(captcha.voice).to be_nil }
16
+ end
17
+
18
+ context 'with config: voices' do
19
+ subject(:captcha) do
20
+ described_class.new do |config|
21
+ config.voice = voices
22
+ end
23
+ end
24
+
25
+ let(:voices) { ['german', 'german+m1'] }
26
+
27
+ specify { expect(voices).to include(captcha.voice) }
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
4
+
5
+ module EasyCaptchaTestApp
6
+ class TestApp < ::Rails::Application
7
+ end
8
+
9
+ TestApp.routes.draw do
10
+ captcha_route
11
+ end
12
+ end
13
+
14
+ RSpec.describe EasyCaptcha::CaptchaController, type: :routing do
15
+ routes { EasyCaptchaTestApp::TestApp.routes }
16
+ let(:routeset) { EasyCaptchaTestApp::TestApp.routes }
17
+ let(:captcha_request) { { get: '/captcha' } }
18
+
19
+ it 'has added a route' do
20
+ expect(routeset.routes.count).to eq 1
21
+ end
22
+
23
+ it 'has added a named route' do
24
+ expect(routeset.named_routes.count).to eq 1
25
+ end
26
+
27
+ it 'has added a named `:captcha` route' do
28
+ expect(routeset.named_routes.first.second.name).to eq 'captcha'
29
+ end
30
+
31
+ it 'makes `/captcha` URL routable' do
32
+ expect(captcha_request).to be_routable
33
+ end
34
+
35
+ it 'has `/captcha` URL handled by `easy_captcha/captcha_controller#captcha`' do
36
+ expect(captcha_request).to route_to(
37
+ controller: 'easy_captcha/captcha',
38
+ action: 'captcha'
39
+ )
40
+ end
41
+ end
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
4
+
5
+ describe EasyCaptcha do
6
+ describe '#setup' do
7
+ described_class.setup do |config|
8
+ # Cache
9
+ config.cache = false
10
+
11
+ # Chars
12
+ config.captcha_character_pool = %w[2 3 4 5 6 7 9 A C D E F G H J K L M N P Q R S T U X Y Z]
13
+
14
+ # Image
15
+ config.captcha_image_height = 40
16
+ config.captcha_image_width = 140
17
+
18
+ # Length
19
+ config.captcha_character_count = 6
20
+
21
+ # configure generator
22
+ config.generator :default do |generator|
23
+ # Blur
24
+ generator.blur = true
25
+ generator.blur_radius = 1
26
+ generator.blur_sigma = 2
27
+
28
+ # Font
29
+ generator.font_size = 24
30
+ generator.font_fill_color = '#333333'
31
+ generator.font_stroke_color = '#000000'
32
+ generator.font_stroke = 0
33
+ generator.font_family = File.expand_path('../resources/afont.ttf', __dir__)
34
+
35
+ # Image background
36
+ generator.image_background_color = '#FFFFFF'
37
+
38
+ # Implode
39
+ generator.implode = 0.1
40
+
41
+ # Sketch
42
+ generator.sketch = true
43
+ generator.sketch_radius = 3
44
+ generator.sketch_sigma = 1
45
+
46
+ # Wave
47
+ generator.wave = true
48
+ generator.wave_length = (60..100)
49
+ generator.wave_amplitude = (3..5)
50
+ end
51
+ end
52
+
53
+ it 'does not cache' do
54
+ expect(described_class).not_to be_cache
55
+ end
56
+
57
+ it 'has default generator' do
58
+ expect(described_class.generator).to be_an(EasyCaptcha::Generator::Default)
59
+ end
60
+
61
+ describe '#depracations' do
62
+ let(:config_methods) do
63
+ %i[
64
+ blur
65
+ blur_radius
66
+ blur_sigma
67
+ font_family
68
+ font_fill_color
69
+ font_size
70
+ font_stroke
71
+ font_stroke_color
72
+ image_background_color
73
+ implode
74
+ sketch
75
+ sketch_radius
76
+ sketch_sigma
77
+ wave
78
+ wave_amplitude
79
+ wave_length
80
+ ]
81
+ end
82
+
83
+ before do
84
+ described_class.setup do |config|
85
+ # Image
86
+ config.captcha_image_height = 40
87
+ config.captcha_image_width = 140
88
+
89
+ # Length
90
+ config.captcha_character_count = 6
91
+
92
+ config.generator :default do |generator|
93
+ # Blur
94
+ generator.blur = true
95
+ generator.blur_radius = 1
96
+ generator.blur_sigma = 2
97
+
98
+ # Font
99
+ generator.font_size = 24
100
+ generator.font_fill_color = '#333333'
101
+ generator.font_stroke_color = '#000000'
102
+ generator.font_stroke = 0
103
+ generator.font_family = File.expand_path('../resources/afont.ttf', __dir__)
104
+
105
+ # Image background
106
+ generator.image_background_color = '#FFFFFF'
107
+
108
+ # Implode
109
+ generator.implode = 0.1
110
+
111
+ # Sketch
112
+ generator.sketch = true
113
+ generator.sketch_radius = 3
114
+ generator.sketch_sigma = 1
115
+
116
+ # Wave
117
+ generator.wave = true
118
+ generator.wave_length = (60..100)
119
+ generator.wave_amplitude = (3..5)
120
+ end
121
+ end
122
+ end
123
+
124
+ it 'returns non-nil for config methods' do
125
+ config_methods.each do |opt|
126
+ expect(described_class.generator.send(opt)).not_to be_nil
127
+ end
128
+ end
129
+
130
+ it 'raises NoMethodError on missing non-depracations' do
131
+ expect { described_class.send(EasyCaptcha::DEPRECATED_METHODS.first) }.not_to raise_error(NoMethodError)
132
+ end
133
+
134
+ it 'does not raise NoMethodError on depracations' do
135
+ expect { described_class.send(:a_missing_method) }.to raise_error(NoMethodError)
136
+ end
137
+
138
+ it 'does not respond_to? depracations' do
139
+ expect(described_class).not_to respond_to(EasyCaptcha::DEPRECATED_METHODS.first)
140
+ end
141
+
142
+ it 'does not respond_to? missing non-depracations' do
143
+ expect(described_class).not_to respond_to(:a_missing_method)
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'simplecov'
8
+ SimpleCov.start 'rails'
9
+ # require 'rails/all'
10
+ require 'action_controller'
11
+ require 'action_dispatch'
12
+ require 'action_view'
13
+ require 'rspec/rails'
14
+ require 'easy_captcha'
15
+
16
+ # Requires supporting files with custom matchers and macros, etc,
17
+ # in ./support/ and its subdirectories.
18
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kandr-easy_captcha
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - Marco Scholl
8
+ - Alexander Dreher
9
+ - Karl Wilbur
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-09-15 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 5.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 5.0.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: rmagick
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 2.13.1
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.13.1
43
+ description: A simple CAPTCHA implementation for Rails 5+ based on RMagick.
44
+ email: karl@kandrsoftware.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files:
48
+ - LICENSE.txt
49
+ - README.md
50
+ files:
51
+ - LICENSE.txt
52
+ - README.md
53
+ - spec/easy_captcha/espeak_spec.rb
54
+ - spec/easy_captcha/routing_spec.rb
55
+ - spec/easy_captcha_spec.rb
56
+ - spec/spec.opts
57
+ - spec/spec_helper.rb
58
+ homepage: http://github.com/K-and-R/easy_captcha
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 2.5.0
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ requirements: []
77
+ rubygems_version: 3.1.4
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: CAPTCHA Plugin for Rails
81
+ test_files:
82
+ - spec/easy_captcha/espeak_spec.rb
83
+ - spec/easy_captcha/routing_spec.rb
84
+ - spec/easy_captcha_spec.rb
85
+ - spec/spec.opts
86
+ - spec/spec_helper.rb