merb_bot_test 0.1.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.
- data/History.txt +6 -0
- data/Manifest.txt +7 -0
- data/README.txt +62 -0
- data/Rakefile +17 -0
- data/bin/merb_bot_test +0 -0
- data/lib/merb_bot_test.rb +55 -0
- data/test/test_merb_bot_test.rb +0 -0
- metadata +70 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= merb_bot_test
|
2
|
+
|
3
|
+
http://rubyforge.org/projects/sintaxi/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Stops spam with a math test
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
stops spam by adding a simple math questions to a form
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
#init.rb
|
16
|
+
|
17
|
+
Merb::BootLoader.before_app_loads do
|
18
|
+
require "merb_bot_test"
|
19
|
+
end
|
20
|
+
|
21
|
+
#in your model
|
22
|
+
|
23
|
+
merb_bot_test
|
24
|
+
|
25
|
+
#in your form (this eg uses @article model)
|
26
|
+
|
27
|
+
<%= text_control :response, :label => "whats #{@article.n1} + #{@article.n2} ?" %>
|
28
|
+
<%= hidden_control :answer_key, :value => @article.key %>
|
29
|
+
|
30
|
+
|
31
|
+
== REQUIREMENTS:
|
32
|
+
|
33
|
+
* none
|
34
|
+
|
35
|
+
== INSTALL:
|
36
|
+
|
37
|
+
* sudo gem install merb_bot_test
|
38
|
+
|
39
|
+
== LICENSE:
|
40
|
+
|
41
|
+
(The MIT License)
|
42
|
+
|
43
|
+
Copyright (c) Brock Whitten 2008
|
44
|
+
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
+
a copy of this software and associated documentation files (the
|
47
|
+
'Software'), to deal in the Software without restriction, including
|
48
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
+
permit persons to whom the Software is furnished to do so, subject to
|
51
|
+
the following conditions:
|
52
|
+
|
53
|
+
The above copyright notice and this permission notice shall be
|
54
|
+
included in all copies or substantial portions of the Software.
|
55
|
+
|
56
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/merb_bot_test.rb'
|
6
|
+
|
7
|
+
Hoe.new('merb_bot_test', MerbBotTest::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'sintaxi'
|
9
|
+
p.author = 'Brock Whitten'
|
10
|
+
p.email = 'brock@sintaxi.com'
|
11
|
+
p.summary = 'stops spam with math question'
|
12
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
# vim: syntax=Ruby
|
data/bin/merb_bot_test
ADDED
File without changes
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class MerbBotTest
|
2
|
+
VERSION = '0.1.0'
|
3
|
+
end
|
4
|
+
|
5
|
+
module Sintaxi
|
6
|
+
module MerbBotTest
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.extend ActMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ActMethods
|
13
|
+
def merb_bot_test(unique_key)
|
14
|
+
unless included_modules.include? InstanceMethods
|
15
|
+
include InstanceMethods
|
16
|
+
class_inheritable_accessor :site_key
|
17
|
+
attr_accessor :response, :answer_key
|
18
|
+
end
|
19
|
+
self.site_key ||= unique_key ||= 45287
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module InstanceMethods
|
24
|
+
|
25
|
+
def n1
|
26
|
+
@n1 ||= rand(20)
|
27
|
+
end
|
28
|
+
|
29
|
+
def n2
|
30
|
+
@n2 ||= rand(9)
|
31
|
+
end
|
32
|
+
|
33
|
+
def key
|
34
|
+
encrypt_number(n1 + n2)
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
def validate
|
39
|
+
errors.add("Failed bot test.", "Are you sure you are human?") if spam?
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def spam?
|
44
|
+
encrypt_number(self.response.to_i) != self.answer_key
|
45
|
+
end
|
46
|
+
|
47
|
+
def encrypt_number number
|
48
|
+
((number + site_key) * 7).to_s(5)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
ActiveRecord::Base.send :include, Sintaxi::MerbBotTest if defined?(ActiveRecord::Base)
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb_bot_test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brock Whitten
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-04-03 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.1
|
23
|
+
version:
|
24
|
+
description: "== DESCRIPTION: Stops spam with a math test == FEATURES/PROBLEMS: stops spam by adding a simple math questions to a form"
|
25
|
+
email: brock@sintaxi.com
|
26
|
+
executables:
|
27
|
+
- merb_bot_test
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.txt
|
38
|
+
- Rakefile
|
39
|
+
- bin/merb_bot_test
|
40
|
+
- lib/merb_bot_test.rb
|
41
|
+
- test/test_merb_bot_test.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage:
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README.txt
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project: sintaxi
|
65
|
+
rubygems_version: 1.0.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: stops spam with math question
|
69
|
+
test_files:
|
70
|
+
- test/test_merb_bot_test.rb
|