mathcha 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +13 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/install.rb +1 -0
- data/lib/mathcha.rb +25 -0
- data/lib/mathcha/mathcha_helper.rb +68 -0
- data/lib/mathcha/mathcha_verify.rb +16 -0
- data/mathcha.gemspec +54 -0
- data/pkg/mathcha-0.0.0.gem +0 -0
- data/rails/init.rb +1 -0
- data/tasks/mathcha_tasks.rake +4 -0
- data/test/mathcha_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +70 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
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.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gemspec|
|
8
|
+
gemspec.name = 'mathcha'
|
9
|
+
gemspec.summary = "Quick little arithmetic plain-text captcha"
|
10
|
+
gemspec.description = "Quick little arithmetic plain-text captcha"
|
11
|
+
gemspec.email = "coryjwilkerson@gmail.com"
|
12
|
+
gemspec.homepage = "http://github.com/technicalpickles/the-perfect-gem"
|
13
|
+
gemspec.authors = ["Cory Wilkerson"]
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
desc 'Default: run unit tests.'
|
21
|
+
task :default => :test
|
22
|
+
|
23
|
+
desc 'Test the mathcha plugin.'
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Generate documentation for the mathcha plugin.'
|
32
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = 'Mathcha'
|
35
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
36
|
+
rdoc.rdoc_files.include('README')
|
37
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
38
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/mathcha.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'mathcha/mathcha_helper'
|
2
|
+
require 'mathcha/mathcha_verify'
|
3
|
+
|
4
|
+
ActionView::Base.send(:include, Mathcha::MathchaHelper)
|
5
|
+
ActionController::Base.send(:include, Mathcha::MathchaVerify)
|
6
|
+
|
7
|
+
module Recaptcha
|
8
|
+
module VERSION #:nodoc:
|
9
|
+
MAJOR = 0
|
10
|
+
MINOR = 2
|
11
|
+
TINY = 2
|
12
|
+
|
13
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
RECAPTCHA_API_SERVER = 'http://api.recaptcha.net';
|
18
|
+
RECAPTCHA_API_SECURE_SERVER = 'https://api-secure.recaptcha.net';
|
19
|
+
RECAPTCHA_VERIFY_SERVER = 'api-verify.recaptcha.net';
|
20
|
+
|
21
|
+
SKIP_VERIFY_ENV = ['test', 'cucumber']
|
22
|
+
|
23
|
+
class RecaptchaError < StandardError
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Mathcha
|
2
|
+
|
3
|
+
# Helper included in ActionView::Base. Use mathcha_tag in your views to
|
4
|
+
# generate a quick and - at this point - incredibly simple - arithmetic
|
5
|
+
# problem for your end user to validate.
|
6
|
+
#
|
7
|
+
# === Coming soon:
|
8
|
+
#
|
9
|
+
# * Support for floats and precision.
|
10
|
+
# * Multiple active mathchas per session.
|
11
|
+
# * Override default session key.
|
12
|
+
# * Suppport for negative values if users so wish.
|
13
|
+
#
|
14
|
+
module MathchaHelper
|
15
|
+
# For some reason I thought this may make the code look
|
16
|
+
# a little cleaner in the switch. Work with me.
|
17
|
+
ADD = '+'
|
18
|
+
SUB = '-'
|
19
|
+
DIV = '/'
|
20
|
+
|
21
|
+
SOLV_OPS = [ADD, SUB, DIV]
|
22
|
+
|
23
|
+
# Use mathcha_tag to generate a simple mathcha - dead simple math problems.
|
24
|
+
# How crazy you get with your seeds is solely at your discretion - cater to
|
25
|
+
# you audience.
|
26
|
+
#
|
27
|
+
# * All solutions are positive integers.
|
28
|
+
# * All problems generated by mathcha present positive integers to the end-user.
|
29
|
+
#
|
30
|
+
# Other bits:
|
31
|
+
#
|
32
|
+
# * Pass html options as such {:html => {:class => 'foo'}}
|
33
|
+
# * The default session key for this thing is :solv, I'd suggest you leave it be.
|
34
|
+
# * Only one mathcha can exist at a time, for now.
|
35
|
+
def mathcha_tag(options={})
|
36
|
+
options.reverse_merge!({:seed_one => 80, :seed_two => 10})
|
37
|
+
|
38
|
+
solv_key = Time.now.to_i
|
39
|
+
solv_prob = generate_solv(SOLV_OPS[rand(SOLV_OPS.size)], options[:seed_one].to_i, options[:seed_two].to_i)
|
40
|
+
|
41
|
+
session[:solv] = [solv_key, eval(solv_prob)]
|
42
|
+
|
43
|
+
html = ''
|
44
|
+
html << %{#{solv_prob} = <input type="text" name="solv" />\n}
|
45
|
+
html << %{<input type="hidden" name="solv_key" value="#{solv_key}" />\n}
|
46
|
+
html
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def generate_solv(op, seed1, seed2)
|
51
|
+
op1 = rand(seed1)
|
52
|
+
op2 = rand(seed2)
|
53
|
+
|
54
|
+
sol = eval(eq = "#{op1.to_f} #{op} #{op2.to_f}")
|
55
|
+
|
56
|
+
case
|
57
|
+
when op == DIV
|
58
|
+
generate_solv(op, seed1, seed2) if (sol % 2 != 0) or (sol < 0)
|
59
|
+
when op == SUB
|
60
|
+
generate_solv(op, seed1, seed2) if sol < 0
|
61
|
+
end
|
62
|
+
|
63
|
+
return eq
|
64
|
+
end
|
65
|
+
|
66
|
+
private :generate_solv
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Mathcha
|
2
|
+
module MathchaVerify
|
3
|
+
SOLV_KEY = 0
|
4
|
+
SOLV = 1
|
5
|
+
|
6
|
+
# This method is used in conjunction with MatchaHelper#matcha_tag. Verifies
|
7
|
+
# the current session's last generated mathcha. Returns true if we verify
|
8
|
+
# and false if otherwise.
|
9
|
+
def verify_mathcha(params)
|
10
|
+
if (solv_key = params[:solv_key]) and (solv = params[:solv])
|
11
|
+
return (session[:solv] and session[:solv][SOLV_KEY] == solv_key.to_i and session[:solv][SOLV] == solv.to_i)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/mathcha.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mathcha}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Cory Wilkerson"]
|
12
|
+
s.date = %q{2009-10-16}
|
13
|
+
s.description = %q{Quick little arithmetic plain-text captcha}
|
14
|
+
s.email = %q{coryjwilkerson@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"install.rb",
|
24
|
+
"lib/mathcha.rb",
|
25
|
+
"lib/mathcha/mathcha_helper.rb",
|
26
|
+
"lib/mathcha/mathcha_verify.rb",
|
27
|
+
"mathcha.gemspec",
|
28
|
+
"pkg/mathcha-0.0.0.gem",
|
29
|
+
"rails/init.rb",
|
30
|
+
"tasks/mathcha_tasks.rake",
|
31
|
+
"test/mathcha_test.rb",
|
32
|
+
"test/test_helper.rb",
|
33
|
+
"uninstall.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/technicalpickles/the-perfect-gem}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Quick little arithmetic plain-text captcha}
|
40
|
+
s.test_files = [
|
41
|
+
"test/mathcha_test.rb",
|
42
|
+
"test/test_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
else
|
51
|
+
end
|
52
|
+
else
|
53
|
+
end
|
54
|
+
end
|
Binary file
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'mathcha'
|
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mathcha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cory Wilkerson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-16 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Quick little arithmetic plain-text captcha
|
17
|
+
email: coryjwilkerson@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- install.rb
|
30
|
+
- lib/mathcha.rb
|
31
|
+
- lib/mathcha/mathcha_helper.rb
|
32
|
+
- lib/mathcha/mathcha_verify.rb
|
33
|
+
- mathcha.gemspec
|
34
|
+
- pkg/mathcha-0.0.0.gem
|
35
|
+
- rails/init.rb
|
36
|
+
- tasks/mathcha_tasks.rake
|
37
|
+
- test/mathcha_test.rb
|
38
|
+
- test/test_helper.rb
|
39
|
+
- uninstall.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/technicalpickles/the-perfect-gem
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Quick little arithmetic plain-text captcha
|
68
|
+
test_files:
|
69
|
+
- test/mathcha_test.rb
|
70
|
+
- test/test_helper.rb
|