zero-captcha 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 658cd74afd71abe91c157709e3e60d704b6b0a82
4
+ data.tar.gz: 86b3dde1bb84720f46d771dd78889975fe51d783
5
+ SHA512:
6
+ metadata.gz: a738d76b1afc84c2dc7d514097cba36b60d5334e456c2c6f77f3fba7260c7a514bffec8083b0de82f4740409809c7434cc742c7b3a90235e55eaf33f35f225bc
7
+ data.tar.gz: 155f6a022d20a148b9630a309f5b84324c21064d7867ceb7dd874fe346b793d08ddbfa8d2744ff7d8524e1940ba9bde08fce06963f36f8613381cdba2adfca1a
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2014 Lu Wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # Zero Captcha
2
+
3
+ **The simplest way to add a zero friction captcha in your Rails forms.**
4
+
5
+ A zero captcha works off the idea that most simple bots do not run a full
6
+ JavaScript interpreter when crawling web forms, so they are unable to fill a
7
+ required field whereas the required field is actually hidden and autopopulated
8
+ by JavaScript in a real browser with a real human. This means having a layer of
9
+ spam protection while maintaining zero friction.
10
+
11
+ This should not be used solely by itself, but can be useful as an extra layer
12
+ of defense alongside honeypot captchas and/or more traditional captchas.
13
+
14
+ ## Requirements
15
+
16
+ Requires jQuery on running on the client side.
17
+
18
+ ## Installation
19
+
20
+ In your Gemfile, simply add
21
+
22
+ gem 'zero-captcha'
23
+
24
+ ## Usage
25
+
26
+ ### form_for
27
+
28
+ Simply specify that the form has a honeypot in the HTML options hash:
29
+
30
+ <% form_for Comment.new, :html => { :zero_captcha => true } do |form| -%>
31
+ ...
32
+ <% end -%>
33
+
34
+ ### form_tag with block
35
+
36
+ Simply specify that the form has a honeypot in the options hash:
37
+
38
+ <% form_tag comments_path, :zero_captcha => true do -%>
39
+ ...
40
+ <% end -%>
41
+
42
+ ### form_tag without block
43
+
44
+ Simply specify that the form has a honeypot in the options hash:
45
+
46
+ <%= form_tag comments_path, :zero_captcha => true -%>
47
+ ...
48
+ </form>
49
+
50
+
51
+ ## Copyright
52
+
53
+ See LICENSE for details.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,23 @@
1
+ require 'zero-captcha/form_tag_helper'
2
+
3
+ module ZeroCaptcha
4
+ module SpamProtection
5
+ def zero_captcha_fields
6
+ { :_zc_field => '5b5cd0da3121fc53b4bc84d0c8af2e81' } # change this in controller by overriding `zero_captcha_fields`
7
+ end
8
+
9
+ def protect_from_spam_with_zero_captcha
10
+ head :ok if zero_captcha_fields.any? { |name, value| params[name] && params[name] != value }
11
+ end
12
+
13
+ def self.included(base) # :nodoc:
14
+ base.send :helper_method, :zero_captcha_fields
15
+
16
+ if base.respond_to? :before_filter
17
+ base.send :prepend_before_filter, :protect_from_spam_with_zero_captcha, :only => [:create, :update]
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ ActionController::Base.send(:include, ZeroCaptcha::SpamProtection) if defined?(ActionController::Base)
@@ -0,0 +1,33 @@
1
+ # Override the form_tag helper to add zero captcha spam protection to forms.
2
+ module ActionView
3
+ module Helpers
4
+ module FormTagHelper
5
+ def form_tag_with_zero_captcha(url_for_options = {}, options = {}, *parameters_for_url, &block)
6
+ zero_captcha = options.delete(:zero_captcha)
7
+ html = form_tag_without_zero_captcha(url_for_options, options, *parameters_for_url, &block)
8
+ if zero_captcha
9
+ captcha = "".respond_to?(:html_safe) ? zero_captcha_html.html_safe : zero_captcha
10
+ if block_given?
11
+ html.insert(html.index('</form>'), captcha)
12
+ else
13
+ html += captcha
14
+ end
15
+ end
16
+ html
17
+ end
18
+ alias_method_chain :form_tag, :zero_captcha
19
+
20
+ private
21
+ def zero_captcha_html
22
+ zero_captcha_fields.collect do |name, value|
23
+ content_tag :div do
24
+ hidden_field_tag(name, 'verify') +
25
+ javascript_tag do
26
+ "jQuery('input[name=#{name}]').val('#{value}')".html_safe
27
+ end
28
+ end
29
+ end.join
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = %q{zero-captcha}
4
+ s.version = "0.0.1"
5
+
6
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
+ s.authors = ['lunaru']
8
+ s.date = %q{2014-10-25}
9
+ s.description = %q{A simple way to add zero friction captchas to Rails forms}
10
+ s.extra_rdoc_files = [
11
+ "LICENSE",
12
+ "README.markdown"
13
+ ]
14
+ s.files = [
15
+ ".document",
16
+ ".gitignore",
17
+ "LICENSE",
18
+ "README.markdown",
19
+ "VERSION",
20
+ "zero-captcha.gemspec",
21
+ "lib/zero-captcha.rb",
22
+ "lib/zero-captcha/form_tag_helper.rb"
23
+ ]
24
+ s.homepage = %q{http://github.com/lunaru/rails-zero-captcha}
25
+ s.rdoc_options = ["--charset=UTF-8"]
26
+ s.require_paths = ["lib"]
27
+ s.rubygems_version = %q{1.3.6}
28
+ s.summary = %q{A simple way to add zero friction captchas to Rails forms}
29
+
30
+ if s.respond_to? :specification_version then
31
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
32
+ s.specification_version = 3
33
+
34
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
35
+ else
36
+ end
37
+ else
38
+ end
39
+ end
40
+
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zero-captcha
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - lunaru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple way to add zero friction captchas to Rails forms
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files:
18
+ - LICENSE
19
+ - README.markdown
20
+ files:
21
+ - .document
22
+ - .gitignore
23
+ - LICENSE
24
+ - README.markdown
25
+ - VERSION
26
+ - zero-captcha.gemspec
27
+ - lib/zero-captcha.rb
28
+ - lib/zero-captcha/form_tag_helper.rb
29
+ homepage: http://github.com/lunaru/rails-zero-captcha
30
+ licenses: []
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options:
34
+ - --charset=UTF-8
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.0.14
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: A simple way to add zero friction captchas to Rails forms
53
+ test_files: []