simple_captcha2 0.4.3 → 0.5.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
- SHA1:
3
- metadata.gz: c89e2fec1c40f57893d53697a221bf6ba4a9c3e6
4
- data.tar.gz: 0d55c4ba052d020f19877571feac77daaf8c9231
2
+ SHA256:
3
+ metadata.gz: 9109eee9cbbef0caa51b63ef969186a2efe0fb479597dc97ffbc118994fc443e
4
+ data.tar.gz: 6c2ed7db47e7f9b5c1ec924e17af38ed44103b6aaeb39ed3a2d0bb0630c88577
5
5
  SHA512:
6
- metadata.gz: 7b6168a217a5d62ede49d7ee0f9e9a5d6b43ad3e6be5cac54024ac760164a6a04f2667cee33f29d2e3a459143b344760c7f95e3e5d077af4b25e662371f807ad
7
- data.tar.gz: a82a14b079d107788853cdc8caabfa94f218f1d84ba2c7daa88280eccb905af70365750f152924690f3f6bf0fd5368a3683d28ac187f8c9b04facda3e361f867
6
+ metadata.gz: 01b783bb207580730aea77ab63ceaa142a77361609a31c14ea728405886f71f766dd4c26f61632eb8e482d993e55ab631fa74e29311db3a8be73421066b149b5
7
+ data.tar.gz: 953cb66bf597f7291ec0c898d85d358f72d7a0c5970db3c5c4d019effbf5d8fc00018bb67314a361a60a36cb5c1b4e1c10d3e6b17f9089905e566d97bdd5ce7d
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- #SimpleCaptcha2
1
+ # SimpleCaptcha2
2
2
 
3
3
  [![Build Status](https://travis-ci.org/pludoni/simple-captcha.png?branch=master)](https://travis-ci.org/pludoni/simple-captcha)
4
4
  [![Gem Version](https://badge.fury.io/rb/simple_captcha2.svg)](https://badge.fury.io/rb/simple_captcha2)
@@ -7,7 +7,7 @@ SimpleCaptcha(2) is the simplest and a robust captcha plugin. Its implementation
7
7
  SimpleCaptcha2 is available to be used with Rails 3 + 4.
8
8
  This is a fork of the popular Rubygem ``simple_captcha`` which got abandoned.
9
9
 
10
- ##Features
10
+ ## Features
11
11
 
12
12
  * Zero FileSystem usage (secret code moved to db-store and image storage removed).
13
13
  * Provides various image styles.
@@ -17,20 +17,28 @@ This is a fork of the popular Rubygem ``simple_captcha`` which got abandoned.
17
17
  * Flexible DOM and CSS handling(There is a separate view partial for rendering SimpleCaptcha DOM elements).
18
18
  * Automated removal of 1 hour old unmatched simple_captcha data.
19
19
 
20
- ##Requirements
20
+ ## Requirements
21
21
 
22
22
  * Ruby >= 1.9.3
23
23
  * Rails >= 3.2
24
24
  * ImageMagick should be installed on your machine to use this plugin.
25
25
  visit http://www.imagemagick.org/script/index.php for more details.
26
26
 
27
- You might need to install Ghostscript on a Mac-System:
27
+
28
+
29
+ ## Installation
30
+
31
+ You might need to install Ghostscript on a Mac-System or a Debian-System:
28
32
 
29
33
  ```
30
34
  brew install ghostscript
31
35
  ```
32
36
 
33
- ##Installation
37
+ ```
38
+ apt-get install ghostscript
39
+ ```
40
+
41
+ The default font, that imagemagick uses is Arial. Make sure that font is available (``apt install ttf-mscorefonts-installer``) or change the font in the SimpleCaptcha config.
34
42
 
35
43
  Put this into your Gemfile
36
44
 
@@ -114,7 +122,7 @@ Must add them:
114
122
  :captcha, :captcha_key
115
123
  ```
116
124
 
117
- ####Form-Builder helper
125
+ #### Form-Builder helper
118
126
 
119
127
  ```erb
120
128
  <%= form_for @user do |form| -%>
@@ -124,7 +132,7 @@ Must add them:
124
132
  <% end -%>
125
133
  ```
126
134
 
127
- ####Validating with captcha
135
+ #### Validating with captcha
128
136
 
129
137
  NOTE: @user.valid? will still work as it should, it will not validate the captcha code.
130
138
 
@@ -132,7 +140,7 @@ NOTE: @user.valid? will still work as it should, it will not validate the captch
132
140
  @user.valid_with_captcha?
133
141
  ```
134
142
 
135
- ####Saving with captcha
143
+ #### Saving with captcha
136
144
 
137
145
  NOTE: @user.save will still work as it should, it will not validate the captcha code.
138
146
 
@@ -140,7 +148,7 @@ NOTE: @user.save will still work as it should, it will not validate the captcha
140
148
  @user.save_with_captcha
141
149
  ```
142
150
 
143
- ###Formtastic integration
151
+ ### Formtastic integration
144
152
 
145
153
  SimpleCaptcha detects if you are using Formtastic:
146
154
 
@@ -164,16 +172,27 @@ assert_equal 1, SimpleCaptcha::SimpleCaptchaData.count
164
172
  fill_in 'captcha', with: SimpleCaptcha::SimpleCaptchaData.first.value
165
173
  ```
166
174
 
167
- ##Options & Examples
175
+ ## ORM support
176
+
177
+ simple-captcha2 supports 3 type of ORM: ActiveRecord, Sequel and Mongoid.
178
+
179
+ Selection of ORM is base on loaded classes. If `ActiveRecord` is loaded then it will be used for the simple captcha data model.
180
+ If `ActiveRecord` is undefined, `Sequel` presence is tested. If `Sequel` is defined it will used for the simple captcha data model.
181
+ If not, `Mongoid` is used.
182
+
183
+ For instance if your application is using Sequel as an ORM just make sure you require `sequel-rails` gem before `simple-captcha2`
184
+ in your Gemfile and respective model will be selected automatically.
185
+
186
+ ## Options & Examples
168
187
 
169
- ###View Options
188
+ ### View Options
170
189
 
171
190
  * ``:label`` - provides the custom text b/w the image and the text field, the default is "type the code from the image"
172
191
  * ``:object`` - the name of the object of the model class, to implement the model based captcha.
173
192
  * ``:code_type`` - return numeric only if set to 'numeric'
174
193
  * ``:multiple`` - allow to use the same captcha in multiple forms in one page. True for the first appaerance and false for the rest.
175
194
 
176
- ###Global options
195
+ ### Global options
177
196
 
178
197
  * ``:image_style`` - provides the specific image style for the captcha image.
179
198
  There are eight different styles available with the plugin as...
@@ -270,8 +289,8 @@ You can change the CSS of the SimpleCaptcha DOM elements as per your need in thi
270
289
 
271
290
  ``app/views/simple_captcha/_simple_captcha.erb``
272
291
 
273
- ###View's Examples
274
- ####Controller Based Example
292
+ ### View's Examples
293
+ #### Controller Based Example
275
294
 
276
295
  ```erb
277
296
  <%= show_simple_captcha %>
@@ -279,19 +298,19 @@ You can change the CSS of the SimpleCaptcha DOM elements as per your need in thi
279
298
  <%= show_simple_captcha(:label => "human authentication") %>
280
299
  ```
281
300
 
282
- ####Model Based Example
301
+ #### Model Based Example
283
302
 
284
303
  ```erb
285
304
  <%= show_simple_captcha(:object => 'user', :label => "human authentication") %>
286
305
  ```
287
306
 
288
- ####Model Options
307
+ #### Model Options
289
308
 
290
309
  * ``:message`` - provides the custom message on failure of captcha authentication the default is "Secret Code did not match with the Image"
291
310
 
292
311
  * ``:add_to_base`` - if set to true, appends the error message to the base.
293
312
 
294
- #####Model's Example
313
+ ##### Model's Example
295
314
 
296
315
  ```ruby
297
316
  class User < ActiveRecord::Base
@@ -304,7 +323,7 @@ end
304
323
  ```
305
324
 
306
325
 
307
- ##I18n
326
+ ## I18n
308
327
 
309
328
  ```yaml
310
329
  en:
@@ -317,7 +336,7 @@ en:
317
336
  user: "The secret Image and code were different"
318
337
  ```
319
338
 
320
- ##Contributing
339
+ ## Contributing
321
340
 
322
341
  For testing, generate a temporary Rails dummy app inside test:
323
342
 
@@ -333,7 +352,7 @@ Please add test cases when adding new functionality. I started with some basic e
333
352
 
334
353
  The tests will be run on [Travis-CI](https://travis-ci.org/pludoni/simple-captcha).
335
354
 
336
- ##Who's who?
355
+ ## Who's who?
337
356
 
338
357
  Enjoy the simplest captcha implementation.
339
358
 
data/Rakefile CHANGED
@@ -24,8 +24,14 @@ namespace :dummy do
24
24
  task :setup do
25
25
  require 'rails'
26
26
  require 'simple_captcha'
27
- require File.expand_path('../test/lib/generators/simple_captcha/dummy/dummy_generator', __FILE__)
28
- SimpleCaptcha::DummyGenerator.start %w(--quiet)
27
+ if ENV["SEQUEL"].nil?
28
+ require File.expand_path('../test/lib/generators/simple_captcha/dummy/dummy_generator', __FILE__)
29
+ generator_class = SimpleCaptcha::DummyGenerator
30
+ else
31
+ require File.expand_path('../test/lib/generators/simple_captcha/dummy/dummy_generator_sequel', __FILE__)
32
+ generator_class = SimpleCaptcha::DummyGeneratorSequel
33
+ end
34
+ generator_class.start %w(--quiet)
29
35
  end
30
36
 
31
37
  desc 'destroy dummy Rails app under test/dummy'
@@ -17,6 +17,13 @@ class SimpleCaptchaGenerator < Rails::Generators::Base
17
17
  end
18
18
 
19
19
  def create_captcha_migration
20
- migration_template "migration.rb", File.join('db/migrate', "create_simple_captcha_data.rb")
20
+ migration_template migration_file, File.join('db/migrate', "create_simple_captcha_data.rb")
21
+ end
22
+
23
+ private
24
+
25
+ def migration_file
26
+ return "migration_sequel.rb" if defined?(Sequel)
27
+ Rails::VERSION::MAJOR > 4 ? "migration5.rb" : "migration.rb"
21
28
  end
22
29
  end
@@ -0,0 +1,15 @@
1
+ class CreateSimpleCaptchaData < ActiveRecord::Migration[4.2]
2
+ def self.up
3
+ create_table :simple_captcha_data do |t|
4
+ t.string :key, :limit => 40
5
+ t.string :value, :limit => 6
6
+ t.timestamps
7
+ end
8
+
9
+ add_index :simple_captcha_data, :key, :name => "idx_key"
10
+ end
11
+
12
+ def self.down
13
+ drop_table :simple_captcha_data
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_table :simple_captcha_data do
4
+ primary_key :id
5
+ String :key, size: 40
6
+ String :value, size: 6
7
+ DateTime :created_at
8
+ DateTime :updated_at
9
+
10
+ index :key, name: "idx_key"
11
+ end
12
+ end
13
+
14
+ down do
15
+ drop_table :simple_captcha_data
16
+ end
17
+ end
@@ -18,6 +18,8 @@ module SimpleCaptcha
18
18
 
19
19
  if defined?(ActiveRecord)
20
20
  autoload :SimpleCaptchaData, 'simple_captcha/simple_captcha_data'
21
+ elsif defined?(Sequel)
22
+ autoload :SimpleCaptchaData, 'simple_captcha/simple_captcha_data_sequel'
21
23
  else
22
24
  autoload :SimpleCaptchaData, 'simple_captcha/simple_captcha_data_mongoid.rb'
23
25
  end
@@ -74,10 +74,10 @@ module SimpleCaptcha #:nodoc
74
74
  params << "-gravity Center"
75
75
  params << "-pointsize 22"
76
76
  params << "-implode #{ImageHelpers.implode}"
77
- params << "label:#{text}"
78
77
  unless SimpleCaptcha.font.empty?
79
78
  params << "-font #{SimpleCaptcha.font}"
80
79
  end
80
+ params << "label:#{text}"
81
81
  if SimpleCaptcha.noise and SimpleCaptcha.noise > 0
82
82
  params << "-evaluate Uniform-noise #{SimpleCaptcha.noise}"
83
83
  end
@@ -26,6 +26,8 @@ module SimpleCaptcha
26
26
  def clear_old_data(time = 1.hour.ago)
27
27
  return unless Time === time
28
28
  where(["#{connection.quote_column_name(:updated_at)} < ?", time]).delete_all
29
+ rescue ActiveRecord::Deadlocked => err
30
+ Rails.logger.error "#{err.class} #{err.message}"
29
31
  end
30
32
  end
31
33
  end
@@ -0,0 +1,22 @@
1
+ module SimpleCaptcha
2
+ class SimpleCaptchaData < Sequel::Model
3
+ plugin :update_or_create
4
+ plugin :timestamps, update_on_create: true
5
+
6
+ class << self
7
+ def get_data(key)
8
+ find_or_new(key: key)
9
+ end
10
+
11
+ def remove_data(key)
12
+ where(key: key).delete
13
+ clear_old_data(1.hour.ago)
14
+ end
15
+
16
+ def clear_old_data(time = 1.hour.ago)
17
+ return unless Time === time
18
+ where {updated_at < time}.delete
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleCaptcha
2
- VERSION = "0.4.3".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_captcha2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavlo Galeta
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-02-20 00:00:00.000000000 Z
14
+ date: 2019-12-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -96,6 +96,8 @@ files:
96
96
  - lib/generators/USAGE
97
97
  - lib/generators/simple_captcha_generator.rb
98
98
  - lib/generators/templates/migration.rb
99
+ - lib/generators/templates/migration5.rb
100
+ - lib/generators/templates/migration_sequel.rb
99
101
  - lib/generators/templates/partial.erb
100
102
  - lib/generators/templates/partial.haml
101
103
  - lib/simple_captcha.rb
@@ -108,6 +110,7 @@ files:
108
110
  - lib/simple_captcha/model_helpers.rb
109
111
  - lib/simple_captcha/simple_captcha_data.rb
110
112
  - lib/simple_captcha/simple_captcha_data_mongoid.rb
113
+ - lib/simple_captcha/simple_captcha_data_sequel.rb
111
114
  - lib/simple_captcha/utils.rb
112
115
  - lib/simple_captcha/version.rb
113
116
  - lib/simple_captcha/view.rb
@@ -130,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
133
  - !ruby/object:Gem::Version
131
134
  version: '0'
132
135
  requirements: []
133
- rubyforge_project:
134
- rubygems_version: 2.5.1
136
+ rubygems_version: 3.0.6
135
137
  signing_key:
136
138
  specification_version: 4
137
139
  summary: SimpleCaptcha is the simplest and a robust captcha plugin.