acts_as_textcaptcha 4.1.2 → 4.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG DELETED
@@ -1,16 +0,0 @@
1
- (pending release)
2
- * Added `rake console` for helpful debugging
3
-
4
- 4.1.1 (13 January 2014)
5
- * Dropped gem signing & cert (http://tinyurl.com/p98owwz)
6
- 4.1.0 (2 January 2014)
7
- * Dropping support for Rails 2
8
- * README updated
9
- * CHANGELOG (this file) added
10
-
11
- 4.0.0 (1 January 2014)
12
- * Using a cache store to persist answers between requests
13
- * README updated
14
- * Test coverage improved
15
-
16
- (no change log available for older releases)
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2011 Matthew Hutchinson
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.
@@ -1,203 +0,0 @@
1
- == ActAsTextcaptcha
2
-
3
- {<img src="https://img.shields.io/gem/v/acts_as_textcaptcha.svg?style=flat" alt="Gem Version" align="absmiddle"/>}[http://rubygems.org/gems/acts_as_textcaptcha] {<img src="https://img.shields.io/travis/matthutchinson/acts_as_textcaptcha.svg?style=flat" alt="Travis Build Status" align="absmiddle"/>}[https://travis-ci.org/matthutchinson/acts_as_textcaptcha] {<img src="https://img.shields.io/coveralls/matthutchinson/acts_as_textcaptcha.svg?style=flat" alt="Coverage Status" align="absmiddle" />}[https://coveralls.io/r/matthutchinson/acts_as_textcaptcha] {<img src="https://img.shields.io/codeclimate/github/matthutchinson/acts_as_textcaptcha.svg?style=flat" alt="Code Climate" align="absmiddle"/>}[https://codeclimate.com/github/matthutchinson/acts_as_textcaptcha] {<img src="https://img.shields.io/gemnasium/matthutchinson/acts_as_textcaptcha.svg?style=flat" alt="Gemnasium Dependencies" align="absmiddle"/>}[https://gemnasium.com/matthutchinson/acts_as_textcaptcha]
4
-
5
- ActsAsTextcaptcha provides spam protection for your Rails models using logic questions from the excellent {Text CAPTCHA}[http://textcaptcha.com/] web service (by {Rob Tuley}[http://openknot.com/me/] of {Openknot}[http://openknot.com/]). It is also possible to configure your own text captcha questions (instead, or as a fall back in the event of any remote API issues).
6
-
7
- This gem is actively maintained, has good test coverage and is compatible with Rails >= 3.0.0 (including Rails 4). If you have any issues {please report them here}[https://github.com/matthutchinson/acts_as_textcaptcha/issues/new].
8
-
9
- Logic questions from the web service are aimed at a child's age of 7, so they can be solved easily by even the most cognitively impaired users. As they involve human logic, questions cannot be solved by a robot. There are both advantages and disadvantages for using logic questions over image based captchas, {find out more at Text CAPTCHA}[http://textcaptcha.com/why].
10
-
11
- == Demo
12
-
13
- Try a {working demo here}[http://textcaptcha.heroku.com]!
14
-
15
- == Installing
16
-
17
- *NOTE:* The steps to configure your app changed with the v4.0.* release. If you are having problems please carefully check the steps or {upgrade instructions}[https://github.com/matthutchinson/acts_as_textcaptcha#upgrading-from-3010] below.
18
-
19
- First add the following to your Gemfile, then `bundle install`;
20
-
21
- gem 'acts_as_textcaptcha'
22
-
23
- Next {grab an API key for your website}[http://textcaptcha.com/api], then add the following code to models you would like to protect;
24
-
25
- class Comment < ActiveRecord::Base
26
- # (this is the simplest way to configure the gem, with an API key only)
27
- acts_as_textcaptcha :api_key => 'PASTE_YOUR_TEXTCAPTCHA_API_KEY_HERE'
28
- end
29
-
30
- Next in your controller's *new* action you'll want to generate and assign the logic question for the new record, like so;
31
-
32
- def new
33
- @comment = Comment.new
34
- @comment.textcaptcha
35
- end
36
-
37
- Finally, in your form view add the textcaptcha question and answer fields using the textcaptcha_fields helper. Feel free to arrange the HTML within this block as you like;
38
-
39
- <%= textcaptcha_fields(f) do %>
40
- <div class="field">
41
- <%= f.label :textcaptcha_answer, @comment.textcaptcha_question %><br/>
42
- <%= f.text_field :textcaptcha_answer, :value => '' %>
43
- </div>
44
- <% end %>
45
-
46
- *NOTE:* If you'd rather NOT use this helper and would prefer to write your own form view code, see the html produced from the textcaptcha_fields method in the {source code}[https://github.com/matthutchinson/acts_as_textcaptcha/blob/master/lib/acts_as_textcaptcha/textcaptcha_helper.rb].
47
-
48
- === Upgrading from 3.0.10
49
-
50
- Due to a relatively {large hole}[https://github.com/matthutchinson/acts_as_textcaptcha/issues/15] that could allow bots to by-pass textcaptcha's, it was nessecary to re-engineer the gem for the v4.0.* release. Thanks to {Jeffrey Lim}[https://github.com/jf] for spotting this and raising the issue. Upgrading is straightforward;
51
-
52
- * Rename `spam_question` to `textcaptcha_question`
53
- * Rename `spam_answer` to `textcaptcha_answer`
54
- * Any {strong parameter}[http://weblog.rubyonrails.org/2012/3/21/strong-parameters/] calls should include the `textcaptcha_answer` and `textcaptcha_key` fields;
55
-
56
- params.require(:comment).permit(:textcaptcha_answer, :textcaptcha_key, ... )
57
-
58
-
59
- === Toggling Textcaptcha
60
-
61
- You can toggle textcaptcha on/off for your models by overriding the `perform_textcaptcha?` method. If it returns false, no questions will be fetched from
62
- the web service and textcaptcha validation is disabled.
63
-
64
- This is useful for writing your own custom logic for toggling spam protection on/off e.g. for logged in users. By default the `perform_textcaptcha?` method {checks if the form object is a new (unsaved) record}[https://github.com/matthutchinson/acts_as_textcaptcha/blob/master/lib/acts_as_textcaptcha/textcaptcha.rb#L54].
65
-
66
- So out of the box, spam protection is only enabled for creating new records (not updating). Here is a typical example showing how to overwrite the `perform_textcaptcha?` method, while maintaining the new record check.
67
-
68
- class Comment < ActiveRecord::Base
69
- acts_as_textcaptcha :api_key => 'YOUR_TEXTCAPTCHA_API_KEY'
70
-
71
- def perform_textcaptcha?
72
- super && user.admin?
73
- end
74
- end
75
-
76
- == More configuration options
77
-
78
- You can configure acts_as_textcaptcha with the following options;
79
-
80
- * *api_key* (_required_) - get a free key from http://textcaptcha.com/api
81
- * *questions* (_optional_) - array of question and answer hashes (see below) A random question from this array will be asked if the web service fails OR if no API key has been set. Multiple answers to the same question are comma separated (e.g. 2,two). So do not use commas in your answers!
82
- * *cache_expiry_minutes* (_optional_) - minutes for answers to persist in the cache (default 10 minutes), see {below for details}[https://github.com/matthutchinson/acts_as_textcaptcha#what-does-the-code-do]
83
- * *http_read_timeout* (_optional_) - Net::HTTP option, seconds to wait for one block to be read from the remote API
84
- * *http_open_timeout* (_optional_) - Net::HTTP option, seconds to wait for the connection to open to the remote API
85
-
86
- For example;
87
-
88
- class Comment < ActiveRecord::Base
89
- acts_as_textcaptcha :api_key => 'YOUR_TEXTCAPTCHA_API_KEY',
90
- :http_read_timeout => 60,
91
- :http_read_timeout => 10,
92
- :cache_expiry_minutes => 10,
93
- :questions => [{ 'question' => '1+1', 'answers' => '2,two' },
94
- { 'question' => 'The green hat is what color?', 'answers' => 'green' }]
95
- end
96
-
97
- === YAML config
98
-
99
- The gem can be configured for models individually (as shown above) or with a config/textcaptcha.yml file. The config file must have an api_key defined and optional array of questions. Options definied inline in model classes take preference over the configuration in textcaptcha.yml. The gem comes with a handy rake task to copy over a {textcaptcha.yml}[http://github.com/matthutchinson/acts_as_textcaptcha/raw/master/config/textcaptcha.yml] template to your config directory;
100
-
101
- rake textcaptcha:config
102
-
103
- === Confguring _without_ the TextCAPTCHA web service
104
-
105
- To use only your own logic questions, simply ommit the api_key from the configuration and define at least 1 logic question and answer (see above).
106
-
107
- == Translations
108
-
109
- The gem uses the standard Rails I18n translation approach (with a fall-back to English). Unfortunately at present, the Text CAPTCHA web service only provides logic questions in English.
110
-
111
- en:
112
- activerecord:
113
- errors:
114
- models:
115
- comment:
116
- attributes:
117
- textcaptcha_answer:
118
- incorrect: "is incorrect, try another question instead"
119
- expired: "was not submitted quickly enough, try another question instead"
120
- activemodel:
121
- attributes:
122
- comment:
123
- textcaptcha_answer: "Textcaptcha answer"
124
-
125
- == Without Rails or ActiveRecord
126
-
127
- Although this gem has been built with Rails in mind, is entirely possible to use it without ActiveRecord, or Rails. As an example, take a look at the {Contact}[https://github.com/matthutchinson/acts_as_textcaptcha/blob/master/test/test_models.rb#L44] model used in the test suite {here}[https://github.com/matthutchinson/acts_as_textcaptcha/blob/master/test/test_models.rb#L44].
128
-
129
- Please note that the built-in {TextcaptchaCache}[https://github.com/matthutchinson/acts_as_textcaptcha/blob/master/lib/acts_as_textcaptcha/textcaptcha_cache.rb] class directly wraps the {Rails.cache}[http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html]. An alternative TextcaptchaCache implementation will be nessecary if Rails.cache is not available.
130
-
131
- == Testing and docs
132
-
133
- In development you can run the tests and rdoc tasks like so;
134
-
135
- * rake test (all tests)
136
- * rake test:coverage (all tests with code coverage)
137
- * rake rdoc (generate docs)
138
-
139
- == What does the code do?
140
-
141
- The gem contains two parts, a module for your ActiveRecord models, and a single view helper method. The ActiveRecord module makes use of two futher classes, {TextcaptchaApi}[https://github.com/matthutchinson/acts_as_textcaptcha/blob/master/lib/acts_as_textcaptcha/textcaptcha_api.rb] and {TextcaptchaCache}[https://github.com/matthutchinson/acts_as_textcaptcha/blob/master/lib/acts_as_textcaptcha/textcaptcha_cache.rb].
142
-
143
- A call to @model.textcaptcha in your controller will query the Text CAPTCHA web service. A GET request is made with Net::HTTP and parsed using the default Rails ActiveSupport::XMLMini backend. A textcaptcha_question and a random cache key is assigned to the record. An array of possible answers is stored in the TextcaptchaCache with this random key. The cached answers have (by default) a 10 minute TTL in your cache. If your forms take more than 10 minutes to be completed you can adjust this value setting the `cache_expiry_minutes` option. Internally TextcaptchaCache wraps {Rails.cache}[http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html] and all cache keys are namespaced.
144
-
145
- On saving, validate_textcaptcha is called on @model.validate checking that the @model.textcaptcha_answer matches one of the possible answers (retrieved from the cache). By default, this validation is _only_ carried out on new records, i.e. never on edit, only on create. All attempted answers are case-insensitive and have trailing/leading white-space removed.
146
-
147
- Regardless of a correct, or incorrect answer the possible answers are cleared from the cache and a new random key is generated and assigned. An incorrect answer will cause a new question to be prompted. After one correct answer, the answer and a mutating key are sent on further form requests, and no question is presented in the form.
148
-
149
- If an error or timeout occurs during API fetching, ActsAsTextcaptcha will fall back to choose a random logic question defined in your options (see above). If the web service fails or no API key is specified AND no alternate questions are configured, the @model will not require textcaptcha checking and will pass as valid.
150
-
151
- For more details on the code please check the {documentation}[http://rdoc.info/projects/matthutchinson/acts_as_textcaptcha]. Tests are written with {MiniTest}[https://rubygems.org/gems/minitest]. Pull requests and bug reports are welcome.
152
-
153
- == Requirements
154
-
155
- What do you need?
156
-
157
- * {Rails}[http://github.com/rails/rails] >= 3.0.0 (including Rails 4)
158
- * {Rails.cache}[http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html] - some basic cache configuration is nessecary
159
- * {Ruby}[http://ruby-lang.org/] >= 1.9.2 (also tested with 1.9.3, 2.0.0, 2.1.1) - 1.8.7 support ended at version 4.1.1
160
- * {Text CAPTCHA API key}[http://textcaptcha.com/register] (_optional_, since you can define your own logic questions)
161
- * {MiniTest}[https://rubygems.org/gems/minitest] (_optional_ if you want to run the tests, built into Ruby 1.9)
162
- * {SimpleCov}[https://rubygems.org/gems/simplecov] (_optional_ if you want to run the tests with code coverage reporting)
163
-
164
- *Note*: The built-in {TextcaptchaCache}[https://github.com/matthutchinson/acts_as_textcaptcha/blob/master/lib/acts_as_textcaptcha/textcaptcha_cache.rb] class directly wraps the {Rails.cache}[http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html] object.
165
-
166
- == Rails 2 support
167
-
168
- Support for Rails 2 was dropped with the release of v4.1.0. If you would like to continue to use this gem with an older version of Rails (>= 2.3.8), please lock the version to `4.0.0`. Like so;
169
-
170
- # in your Gemfile
171
- gem 'acts_as_textcaptcha', '=4.0.0'
172
-
173
- # or in environment.rb
174
- config.gem 'acts_as_textcaptcha', :version => '=4.0.0'
175
-
176
- Check out the {README}[https://github.com/matthutchinson/acts_as_textcaptcha/tree/v4.0.0] for this release for more information.
177
-
178
- == Links
179
-
180
- * {Demo}[http://textcaptcha.heroku.com]
181
- * {Travis CI}[http://travis-ci.org/#!/matthutchinson/acts_as_textcaptcha]
182
- * {Test Coverage}[https://coveralls.io/r/matthutchinson/acts_as_textcaptcha]
183
- * {Code Climate}[https://codeclimate.com/github/matthutchinson/acts_as_textcaptcha]
184
- * {RDoc}[http://rdoc.info/projects/matthutchinson/acts_as_textcaptcha]
185
- * {Wiki}[http://wiki.github.com/matthutchinson/acts_as_textcaptcha/]
186
- * {Issues}[http://github.com/matthutchinson/acts_as_textcaptcha/issues]
187
- * {Report a bug}[http://github.com/matthutchinson/acts_as_textcaptcha/issues/new]
188
- * {Gem}[http://rubygems.org/gems/acts_as_textcaptcha]
189
- * {GitHub}[http://github.com/matthutchinson/acts_as_textcaptcha]
190
-
191
- == Who's who?
192
-
193
- * {ActsAsTextcaptcha}[http://github.com/matthutchinson/acts_as_textcaptcha] and {little robot drawing}[http://www.flickr.com/photos/hiddenloop/4541195635/] by {Matthew Hutchinson}[http://matthewhutchinson.net]
194
- * {Text CAPTCHA}[http://textcaptcha.com] API and service by {Rob Tuley}[http://openknot.com/me/] at {Openknot}[http://openknot.com]
195
-
196
- == Usage
197
-
198
- This gem is used in a number of production websites and apps. It was originally extracted from code developed for {Bugle}[http://bugleblogs.com]. If you're happily using acts_as_textcaptcha in production, let me know and I'll add you to this list!
199
-
200
- * {matthewhutchinson.net}[http://matthewhutchinson.net]
201
- * {pmFAQtory.com}[http://pmfaqtory.com]
202
- * {The FAQtory}[http://faqtoryapp.com]
203
- * {DPT Watch, San Francisco}[http://www.dptwatch.com]