simple_captcha_reloaded 0.1.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a0b34dbfa1c17906e1aaa726c06f77988b2a50c
4
- data.tar.gz: 52b25d9225d5243a8fb64f38c16a431cb20869e5
3
+ metadata.gz: 0e5f1d37f89ed951fc718c423cd74d9e9b77cbd0
4
+ data.tar.gz: 6d04338634f0bcb29985dbd7b0fc6042402c33c4
5
5
  SHA512:
6
- metadata.gz: b783a5cc40dec2af2d423600b632681a7df1436c71e6ee7beb882f907555a1b2eb5013966f677ea5e6ac7d32c2783d5a0c54d865651e30c3a782387f810ef829
7
- data.tar.gz: c05b24ccb8fce886dc2a9f13a9578c064465c3423aeac1f8f4e029614188cd872c9fc92e0dd949ebd64410e2a3628ca3a85ddfca8949e277f1ce5fae4dd02492
6
+ metadata.gz: f6dc2a2eeea08c9faea959ec80c031af293fb3310cb11dc2d07115e5dc345dace2adfdeedb0f6a8e43fe8f7cb6a0c81a5da772b0ec0e6d3e1284aa3576f47180
7
+ data.tar.gz: d8b180bd8ae8cd9b24028de3af4f95ae2ef1a05fe1d39c46e70fc855c34f0cf97500bc4d8bb7300b59ed9d12fd854e84f69795cd8513dffbb75e0120a8e65c6a
data/README.md CHANGED
@@ -3,19 +3,21 @@
3
3
  [![Build Status](https://travis-ci.org/zealot128/simple_captcha_reloaded.svg?branch=master)](https://travis-ci.org/zealot128/simple_captcha_reloaded)
4
4
  [![Gem Version](https://badge.fury.io/rb/simple_captcha_reloaded.svg)](http://badge.fury.io/rb/simple_captcha_reloaded)
5
5
 
6
- This is a rewrite of the popular Simple-Captcha Gem. Similarily to Simple-Captcha, it provides an easy way to integrate a Captcha into a Rails appliaction. In comparison to the older Gem(s), I decided to drop support for ancient versions of Rails + Formtastic + Mongoid, but also add specs and support for SimpleForm.
6
+ This is a rewrite of the popular Simple-Captcha Gem(s). Similarly to Simple-Captcha, it provides an easy way to integrate a Captcha into a Rails application. In comparison to the older Gem(s), I decided to drop support for ancient versions of Rails + Formtastic + Mongoid, but instead add specs, code restructuring and support for SimpleForm, with the goal, to make it even easier to use.
7
7
 
8
8
  ## Features
9
9
 
10
- * Works with Rails 4.1+, Ruby 2.0+ (keyword arguments)
10
+ * Works with Rails 4.1, 4.2, Ruby 2.0+ (keyword arguments)
11
11
  * Integrated into Model validation flow
12
- * Optional controller integration for custom flow
13
- * Uses a database table to track random captchas
14
- * Uses imagemagick to generate the captcha and stream it to the client, without file access
12
+ * controller integration for custom flow
13
+ * Optional SimpleForm integration (v.3.0 and 3.1)
14
+ * Optional Formtastic integration (v.2.3 and 3.1)
15
+ * Uses a database table to track random captchas (pg, myqsl, sqlite tested)
16
+ * Uses Imagemagick to generate the Captcha and stream it to the client, without file access
15
17
 
16
18
  ## Prerequisites
17
19
 
18
- This needs Rails (4.1+), ActiveRecord with a database (all should be fine) and imagemagick.
20
+ This needs Rails (4.1+), ActiveRecord with a database (all should be fine) and Imagemagick installed on the server.
19
21
 
20
22
  Mac:
21
23
 
@@ -57,7 +59,7 @@ class Message < ActiveRecord::Base
57
59
  end
58
60
  ```
59
61
 
60
- this adds 2 new methods: ``valid_with_captcha?`` and ``save_with_captcha`` to the model. Use it like this in controller:
62
+ this adds 2 new methods: ``valid_with_captcha?`` and ``save_with_captcha`` to the model, as well as 2 virtual attributes captcha and captcha_key. Use it like this in controller:
61
63
 
62
64
  ```ruby
63
65
  class MessagesController < ApplicationController
@@ -76,9 +78,9 @@ class MessagesController < ApplicationController
76
78
  end
77
79
  ```
78
80
 
79
- Make sure to whiteliste the attributes ``captcha`` and ``captcha_key`` with Strong Parameters.
81
+ Make sure to whitelist the attributes ``captcha`` and ``captcha_key`` with Strong Parameters.
80
82
 
81
- To show the captcha, you can use the SimpleForm helper:
83
+ To show the captcha, you can use the SimpleForm or Formtastic helper or roll a total custom field:
82
84
 
83
85
  ### Simple Form
84
86
 
@@ -90,9 +92,22 @@ The Gem provides a custom input for SimpleForm:
90
92
  = f.submit
91
93
  ```
92
94
 
95
+ To use it, just require it manually anywhere in your code (config/application.rb or a initializer file):
96
+
97
+ ```ruby
98
+ require 'simple_captcha_reloaded/adapters/simple_form'
99
+ ```
100
+
101
+
93
102
  ### Formtastic
94
103
 
95
- PLANNED
104
+ The Formtastic adapter works exactly like the simple form one.
105
+
106
+ *You can't include both at the same time, as both have the same naming schema and will load each other's adapter*
107
+
108
+ ```ruby
109
+ require 'simple_captcha_reloaded/adapters/formtastic'
110
+ ```
96
111
 
97
112
  ### Manual by using default Rails view helper
98
113
 
@@ -133,7 +148,7 @@ Adjust it to your needs:
133
148
 
134
149
  ### Manual Validation
135
150
 
136
- Now you can call a method in your controller to check if the captcha is valid:
151
+ Now you can call a method in your controller to check if the Captcha is valid:
137
152
 
138
153
  ```ruby
139
154
  def submit
@@ -147,6 +162,8 @@ end
147
162
 
148
163
  ## Customizing
149
164
 
165
+ Translations: Just have a look at config/locales/simple_captcha.en.yml with defaults for German and English. Just overwrite the keys in your own translation file.
166
+
150
167
  ### Captcha Options
151
168
 
152
169
  ```ruby
@@ -199,3 +216,11 @@ The Gem uses **Appraisal**, to create various configuration Gem sets. For each G
199
216
 
200
217
  If you need to add new controller methods to the dummy app, have a look at ``spec/template.rb``
201
218
 
219
+
220
+ ## Acknowledgment
221
+
222
+ This rewrite was heavy inspired by the previous SimpleCaptcha Gems (licensed under MIT) by various authors:
223
+
224
+ * Sur Max
225
+ * Igor Galeta
226
+ * Azdaroth
@@ -0,0 +1,42 @@
1
+ class SimpleCaptchaInput < Formtastic::Inputs::StringInput
2
+ def to_html
3
+ set_options!
4
+ captcha = SimpleCaptchaReloaded.generate_captcha(id: options[:captcha][:id], request: template.request)
5
+ input_wrapping do
6
+ label_html <<
7
+ image_tag(captcha) <<
8
+ captcha_key(captcha) <<
9
+ builder.text_field(method, input_html_options) <<
10
+ refresh_button(captcha)
11
+ end
12
+ end
13
+
14
+ def set_options!
15
+ default_options = {
16
+ refresh_button: true,
17
+ id: 'simple_captcha_wrapper'
18
+ }
19
+ options[:wrapper_html] ||= {}
20
+ options[:captcha] ||= {}
21
+ options[:captcha].reverse_merge!(default_options)
22
+ options[:wrapper_html][:id] ||= options[:captcha][:id]
23
+ end
24
+
25
+ def image_tag(captcha)
26
+ template.content_tag(:img, nil, src: captcha[:captcha_url], alt: 'Captcha', class: 'simple-captcha-image')
27
+ end
28
+
29
+ def captcha_key(captcha)
30
+ builder.hidden_field :captcha_key, value: captcha[:captcha_id]
31
+ end
32
+
33
+ def refresh_button(captcha)
34
+ template.content_tag :div, class: 'simple-captcha-reload' do
35
+ template.link_to captcha[:refresh_url], class: options[:captcha][:refresh_button_class], data: {remote: true} do
36
+ I18n.t('simple_captcha_reloaded.refresh_button_html')
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+ end
@@ -4,7 +4,7 @@ superclass = SimpleForm::Inputs::StringInput
4
4
  if defined?(StringInput)
5
5
  superclass = StringInput
6
6
  end
7
- class SimpleCaptchaInput < superclass
7
+ class SimpleForm::Inputs::SimpleCaptchaInput < superclass
8
8
  def input(wrapper_options=nil)
9
9
  set_options
10
10
  @captcha = SimpleCaptchaReloaded.generate_captcha(id: options[:captcha][:id], request: template.request)
@@ -5,8 +5,10 @@ module SimpleCaptchaReloaded
5
5
  isolate_namespace SimpleCaptchaReloaded
6
6
  initializer "simple_captcha.load" do |app|
7
7
  ActiveSupport.on_load :action_controller do
8
- helper SimpleCaptchaReloaded::ViewHelper
9
- ActionController::Base.send(:include, SimpleCaptchaReloaded::ControllerHelper)
8
+ if defined?(helper)
9
+ helper SimpleCaptchaReloaded::ViewHelper
10
+ ActionController::Base.send(:include, SimpleCaptchaReloaded::ControllerHelper)
11
+ end
10
12
  end
11
13
  app.middleware.use SimpleCaptchaReloaded::Middleware
12
14
  end
@@ -14,7 +16,9 @@ module SimpleCaptchaReloaded
14
16
  if defined?(SimpleForm)
15
17
  require 'simple_captcha_reloaded/adapters/simple_form'
16
18
  end
19
+ if defined?(Formtastic)
20
+ require 'simple_captcha_reloaded/adapters/formtastic'
21
+ end
17
22
  end
18
-
19
23
  end
20
24
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCaptchaReloaded
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Wienert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.1'
27
27
  - !ruby/object:Gem::Dependency
@@ -199,6 +199,7 @@ files:
199
199
  - config/routes.rb
200
200
  - db/migrate/20141129170641_create_simple_captcha_reloaded_simple_captcha_reloaded_data.rb
201
201
  - lib/simple_captcha_reloaded.rb
202
+ - lib/simple_captcha_reloaded/adapters/formtastic.rb
202
203
  - lib/simple_captcha_reloaded/adapters/simple_form.rb
203
204
  - lib/simple_captcha_reloaded/config.rb
204
205
  - lib/simple_captcha_reloaded/controller_helper.rb
@@ -230,9 +231,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
231
  version: '0'
231
232
  requirements: []
232
233
  rubyforge_project:
233
- rubygems_version: 2.2.2
234
+ rubygems_version: 2.6.13
234
235
  signing_key:
235
236
  specification_version: 4
236
237
  summary: Captcha library which uses imagemagick to create captchas
237
238
  test_files: []
238
- has_rdoc: