rcarvalho-guardian-forms 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +1 -0
- data/guardian.gemspec +19 -0
- data/lib/guardian/engine.rb +4 -0
- data/lib/guardian/version.rb +3 -0
- data/lib/guardian.rb +20 -0
- data/vendor/assets/.DS_Store +0 -0
- data/vendor/assets/javascripts/jquery.guardian.js +29 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 12f7d334fbea3466a16f9ac71a40ed584598506a
|
4
|
+
data.tar.gz: 6b1ba340c647d221c8959753da05912577857997
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0652572e6d423c2c09021f8abef8ffe7a2a44b579bfbe9af17dcf50fcbd85a731adbe26a65a498ccfc2ff6f51e0263d73448858542b0120d706e56f63904ef5
|
7
|
+
data.tar.gz: 80c6f5adce2c3d7c8d4f73e1d3e93166d23bef4a28abb49b2a247dd093671d4c910374b920cfde6406c3282d3d9b5f4c8ea57b2b2b5e9b965567e75612ed9ae7
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-2.0.0@guardian --create
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Forrest Grant
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
Guardian
|
2
|
+
====================
|
3
|
+
|
4
|
+
Guardian protects web forms from spam. By adding a hidden input field that counts up, guardian will reject submissions with a duration less than any threshold we deem appropriate (defualt is 2 seconds).
|
5
|
+
|
6
|
+
|
7
|
+
## Install
|
8
|
+
### RubyGems.org
|
9
|
+
$ gem install guardian-forms
|
10
|
+
|
11
|
+
### from source
|
12
|
+
$ git clone http://github.com/forrestgrant/guardian
|
13
|
+
$ cd guardian
|
14
|
+
$ rake build
|
15
|
+
$ rake install
|
16
|
+
|
17
|
+
### add to your Gemfile
|
18
|
+
|
19
|
+
gem 'guardian-forms', require: 'guardian'
|
20
|
+
|
21
|
+
Usage
|
22
|
+
==========
|
23
|
+
|
24
|
+
Set a before filter in your controller
|
25
|
+
|
26
|
+
before_filter :guard
|
27
|
+
|
28
|
+
Or
|
29
|
+
|
30
|
+
before_filter { |c| c.guard({:threshold => 5})} # 5 seconds
|
31
|
+
|
32
|
+
Add guardian to `application.js`
|
33
|
+
|
34
|
+
//= require jquery.guardian
|
35
|
+
|
36
|
+
Set Guard specific forms in views
|
37
|
+
|
38
|
+
$('form').guard();
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/guardian.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'guardian/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rcarvalho-guardian-forms"
|
8
|
+
gem.version = Guardian::VERSION
|
9
|
+
gem.authors = ["Forrest Grant"]
|
10
|
+
gem.email = ["forrest@forrestgrant.com"]
|
11
|
+
gem.description = "Protect web forms form spam."
|
12
|
+
gem.summary = "Protect your forms from spam, by adding a duration field, if it takes less than 2 seconds to submit the form, it is likely spam."
|
13
|
+
gem.homepage = "https://github.com/forrestgrant/guardian"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/lib/guardian.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "guardian/version"
|
2
|
+
require 'guardian/engine'
|
3
|
+
ActionController::Base.send(:include, Guardian)
|
4
|
+
|
5
|
+
module Guardian
|
6
|
+
|
7
|
+
def guard(vars = { :threshold => 2})
|
8
|
+
if params[:duration] && params[:duration].to_i < vars[:threshold]
|
9
|
+
logger.info "\n"
|
10
|
+
logger.info "+++++++++++++++++++++++++++++++++++++"
|
11
|
+
logger.info "GUARDIAN IS REJECTION FORM SUBMISSION"
|
12
|
+
logger.info "Page duration: #{params[:duration]}"
|
13
|
+
logger.info "Threhold: #{vars[:threshold]}"
|
14
|
+
logger.info "+++++++++++++++++++++++++++++++++++++"
|
15
|
+
logger.info "\n"
|
16
|
+
redirect_to "/"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
* Guardian - jQuery plugin for protecting forms from spam
|
3
|
+
*
|
4
|
+
* Copyright (c) 2012 Forrest Grant
|
5
|
+
*
|
6
|
+
* Dual licensed under the MIT and GPL licenses:
|
7
|
+
* http://www.opensource.org/licenses/mit-license.php
|
8
|
+
* http://www.gnu.org/licenses/gpl.html
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
|
12
|
+
(function($){
|
13
|
+
$.fn.guard = function(options) {
|
14
|
+
var defaults = {
|
15
|
+
threshold: 2
|
16
|
+
};
|
17
|
+
var options = $.extend(defaults, options);
|
18
|
+
this.each(function() {
|
19
|
+
$(this).append($('<input type="hidden" name="duration" id="guardian-duration" value="0" />'));
|
20
|
+
setInterval((function() {
|
21
|
+
$('input[name=duration]').val(parseInt($('input[name=duration]').val()) + 1);
|
22
|
+
}), 1000);
|
23
|
+
$(this).submit(function(e){
|
24
|
+
if (parseInt($('#guardian-duration').val()) < options.threshold) e.preventDefault();
|
25
|
+
});
|
26
|
+
});
|
27
|
+
return this;
|
28
|
+
};
|
29
|
+
})(jQuery);
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rcarvalho-guardian-forms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Forrest Grant
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Protect web forms form spam.
|
14
|
+
email:
|
15
|
+
- forrest@forrestgrant.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .DS_Store
|
21
|
+
- .gitignore
|
22
|
+
- .rvmrc
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- guardian.gemspec
|
28
|
+
- lib/guardian.rb
|
29
|
+
- lib/guardian/engine.rb
|
30
|
+
- lib/guardian/version.rb
|
31
|
+
- vendor/assets/.DS_Store
|
32
|
+
- vendor/assets/javascripts/jquery.guardian.js
|
33
|
+
homepage: https://github.com/forrestgrant/guardian
|
34
|
+
licenses: []
|
35
|
+
metadata: {}
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 2.2.0
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Protect your forms from spam, by adding a duration field, if it takes less
|
56
|
+
than 2 seconds to submit the form, it is likely spam.
|
57
|
+
test_files: []
|