aritcaptcha 1.5.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.0
1
+ 1.7.0
data/aritcaptcha.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aritcaptcha}
8
- s.version = "1.5.0"
8
+ s.version = "1.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Guilherme Nascimento"]
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "aritcaptcha.gemspec",
27
27
  "lib/aritcaptcha.rb",
28
28
  "lib/aritcaptcha/aritcaptcha_helper.rb",
29
+ "lib/aritcaptcha/articaptcha_verify.rb",
29
30
  "lib/aritcaptcha/calculation.rb",
30
31
  "spec/aritcaptcha_helper_spec.rb",
31
32
  "spec/aritcaptcha_spec.rb",
@@ -9,18 +9,22 @@ module Aritcaptcha
9
9
  OPERATIONS = [ADD, SUB, DIV, MUL]
10
10
 
11
11
  def aritcaptcha_tag(options={})
12
+ equation_key = Time.now.to_i
12
13
  number1 = options[:one] || 50
13
14
  number2 = options[:two] || 50
14
15
  operation = options[:op] || OPERATIONS[rand(OPERATIONS.size)]
15
16
 
16
17
  equation, result = Aritcaptcha::Calculation.generate_calculation number1, number2, operation
17
-
18
- html_options = options[:html].inject([]){|dump, pair| dump << "#{pair[0]}=\"#{pair[1]}\""}
19
- html_options.join(" ")
20
- puts html_options
21
-
18
+
19
+ session[:equation] = [equation_key, eval(equation)]
20
+
21
+ if options[:html]
22
+ html_options = options[:html].inject([]){|dump, pair| dump << "#{pair[0]}=\"#{pair[1]}\""}
23
+ html_options.join(" ")
24
+ end
22
25
 
23
26
  html = "#{equation} = <input type='text' name='equation' #{html_options} />"
27
+ html << %{<input type="hidden" name="equation_key" value="#{equation_key}" />\n}
24
28
  html
25
29
  end
26
30
  end
@@ -0,0 +1,16 @@
1
+ module Aritcaptcha
2
+
3
+ module AritcaptchaVerify
4
+ SOLV_KEY = 0
5
+ SOLV = 1
6
+
7
+ def verify_articaptcha(params)
8
+ puts params[:equation_key]
9
+ puts params[:equation]
10
+ if (solv_key = params[:equation_key]) and (solv = params[:equation])
11
+ return (session[:equation] and session[:equation][SOLV_KEY] == solv_key.to_i and session[:equation][SOLV] == solv.to_i)
12
+ end
13
+ end
14
+ end
15
+
16
+ end
data/lib/aritcaptcha.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'aritcaptcha/aritcaptcha_helper'
2
2
 
3
3
  ActionView::Base.send(:include, Aritcaptcha::AritcaptchaHelper)
4
- # ActionController::Base.send(:include, Mathcha::MathchaVerify)
4
+ ActionController::Base.send(:include, Aritcaptcha::AritcaptchaVerify)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aritcaptcha
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 5
8
+ - 7
9
9
  - 0
10
- version: 1.5.0
10
+ version: 1.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Guilherme Nascimento
@@ -53,6 +53,7 @@ files:
53
53
  - aritcaptcha.gemspec
54
54
  - lib/aritcaptcha.rb
55
55
  - lib/aritcaptcha/aritcaptcha_helper.rb
56
+ - lib/aritcaptcha/articaptcha_verify.rb
56
57
  - lib/aritcaptcha/calculation.rb
57
58
  - spec/aritcaptcha_helper_spec.rb
58
59
  - spec/aritcaptcha_spec.rb