aritcaptcha-keeguon 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTQ0ZWZiMWIzMTBhMDNkNTJiZDYwOTIxOGQxNGNlYWZjNDFlMTNkZA==
5
+ data.tar.gz: !binary |-
6
+ ZmJhOGRkMDE1MzY0ZTdjY2NhNjVlNmZmNTRjYzQ1ZjcyZTI3ZTY0Yw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NzQ4NGM3ODc4ZjMwYjgzNjUyMWZlNTJkZThlNTA5ZDY3NjI2NDgwNGUyYTM5
10
+ MTI0M2NhYWYyZjE2ZWVmNmYzYjMyZGJhMzA5YTBiOTgxMzc5YjIwODk2ZGU3
11
+ OTE4ODMwY2E5NjRjMmE2Mzc0Nzk1Y2RlYjVmNjA1NzJjYThiMTI=
12
+ data.tar.gz: !binary |-
13
+ N2UwOWFjNmJkYmI3NzkzZmQ2MmE3NmU0YTM5MWU5Y2FiOTdhNGEyNTM0N2I5
14
+ YzEwZDE4NjE4Y2Y5OWE1ZjRlYzdmMzYxYjE0MDRjMzg3NTIxNmZlZmE3ODg4
15
+ Y2E2NjMxOTkyOGE4ODBmYjM2YWMxNmEzOTdkMWMwYTUyMzkxNjk=
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Guilherme Nascimento
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.
@@ -0,0 +1,41 @@
1
+ # Aritcaptcha: A simple arithmetic captcha for Rails 3
2
+
3
+ Aritcaptcha provides a simple way to display a arithmetic captcha inside a page.
4
+
5
+ ## Usage
6
+
7
+ Use RubyGems to install:
8
+
9
+ $ gem install aritcaptcha
10
+
11
+ After the installation you can generate a simple arithmetic captcha inside a page:
12
+
13
+ <%= raw aritcaptcha_tag %>
14
+
15
+ If you want to use a numeric captcha that renders an image:
16
+
17
+ <%= raw aritcaptcha_tag :format => "image" %>
18
+
19
+ If you want to restrict the arithmetic operations:
20
+
21
+ <%= raw aritcaptcha_tag :operations => [:add, :sub] %> # only the operations of addition and subtraction are displayed
22
+
23
+ To validate the answer entered by the user, put this verification inside an action:
24
+
25
+ <% if verify_aritcaptcha(params) %>
26
+ # correct answer
27
+ <% end >
28
+
29
+ ## Contributing to Aritcaptcha
30
+
31
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
32
+ * Check out the [issue tracker](http://github.com/guinascimento/aritcaptcha/issues) to make sure someone already hasn't requested it and/or contributed it
33
+ * Fork the project
34
+ * Start a feature/bugfix branch
35
+ * Commit and push until you are happy with your contribution
36
+ * Make sure to add tests for the feature/bugfix. This is important so I don't break it in a future version unintentionally.
37
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate it to its own commit so I can cherry-pick around it.
38
+
39
+ ## Copyright
40
+
41
+ Copyright (c) 2011 Guilherme Nascimento. See LICENSE for details.
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "aritcaptcha"
8
+ gem.summary = %Q{Arithmetic Captcha}
9
+ gem.description = %Q{Arithmetic Captcha}
10
+ gem.email = "guilherme.ruby@gmail.com"
11
+ gem.homepage = "http://github.com/guinascimento/aritcaptcha"
12
+ gem.authors = ["Guilherme Nascimento"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "aritcaptcha #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.6
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
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{aritcaptcha-keeguon}
8
+ s.version = "2.0.6"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Guilherme Nascimento", "Felix Bellanger"]
12
+ s.date = %q{2011-05-25}
13
+ s.description = %q{Arithmetic Captcha}
14
+ s.email = %q{guilherme.ruby@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE",
22
+ "README.markdown",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "aritcaptcha.gemspec",
26
+ "lib/aritcaptcha.rb",
27
+ "lib/aritcaptcha/aritcaptcha_helper.rb",
28
+ "lib/aritcaptcha/aritcaptcha_verify.rb",
29
+ "lib/aritcaptcha/calculation.rb",
30
+ "spec/aritcaptcha_spec.rb",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb",
33
+ "tags"
34
+ ]
35
+ s.homepage = %q{http://github.com/guinascimento/aritcaptcha}
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{Arithmetic Captcha}
39
+ s.test_files = [
40
+ "spec/aritcaptcha_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
50
+ else
51
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
55
+ end
56
+ end
57
+
@@ -0,0 +1,5 @@
1
+ require 'aritcaptcha/aritcaptcha_helper'
2
+ require 'aritcaptcha/aritcaptcha_verify'
3
+
4
+ ActionView::Base.send(:include, Aritcaptcha::AritcaptchaHelper)
5
+ ActionController::Base.send(:include, Aritcaptcha::AritcaptchaVerify)
@@ -0,0 +1,76 @@
1
+ require 'RMagick'
2
+ include Magick
3
+ require "aritcaptcha/calculation"
4
+
5
+ module Aritcaptcha
6
+
7
+ module AritcaptchaHelper
8
+ ADD = '+'
9
+ SUB = '-'
10
+ DIV = '/'
11
+ MUL = '*'
12
+
13
+ OPERATIONS = [ADD, SUB, DIV, MUL]
14
+
15
+ def aritcaptcha_tag(options={})
16
+ equation_key = Time.now.to_i
17
+
18
+ default_operations = {:add => "+", :sub => "-", :mul => "*", :div => "/"}
19
+
20
+ operator = nil
21
+ if options[:operations] == nil
22
+ operator = default_operations.to_a[rand(default_operations.size)][1]
23
+ else
24
+ non_default_operations = {}
25
+ options[:operations].each do |op|
26
+ non_default_operations[op] = default_operations[op]
27
+ end
28
+ operator = non_default_operations.to_a[rand(non_default_operations.size)][1]
29
+ end
30
+
31
+ equation, result = Aritcaptcha::Calculation.generate_calculation 50, 50, operator
32
+
33
+ session[:equation] = [equation_key, eval(equation)]
34
+
35
+ if options[:html]
36
+ options_html = options[:html].inject([]) { |dump, pair| dump << "#{pair[0]}=\"#{pair[1]}\"" }
37
+ options_html = options_html.join(" ")
38
+ end
39
+
40
+ html = ""
41
+ if options[:format] == "image"
42
+ session[:image] = equation_key
43
+ img = generate_image equation_key, equation
44
+
45
+ html << "<img src=\"/images/#{img}\" style='vertical-align:top;' /> <input type=\"text\" name=\"equation\" size=\"3\" style='vertical-align:top;' #{options_html unless options_html.nil?} />"
46
+ else
47
+ html << "#{equation} = <input type=\"text\" name=\"equation\" style='vertical-align:top;' size=\"3\" #{options_html unless options_html.nil?} /></div>"
48
+ end
49
+
50
+ html << "<input type=\"hidden\" name=\"equation_key\" value=\"#{equation_key}\" /> \n"
51
+ end
52
+
53
+ def generate_image(equation_key, equation)
54
+ relative_name = "equacao-#{equation_key}.png"
55
+ full_path = "#{Rails.root}/public/images/#{relative_name}"
56
+
57
+ unless File.file?(full_path)
58
+ image = Magick::Image.new(85, 32)
59
+ image.format = "PNG"
60
+ title = Magick::Draw.new
61
+
62
+ title.annotate(image, 5, 5, 12, 7, equation + " =") do
63
+ self.fill = "#333"
64
+ self.font = "#{Rails.root}/fonts/Clarenton LT Bold.ttf"
65
+ self.font_family = "Clarenton LT Bold"
66
+ self.font_weight = Magick::BoldWeight
67
+ self.gravity = Magick::NorthWestGravity
68
+ self.pointsize = 15
69
+ end
70
+ image.write(full_path)
71
+ end
72
+ relative_name
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,25 @@
1
+ module Aritcaptcha
2
+
3
+ module AritcaptchaVerify
4
+ SOLV_KEY = 0
5
+ SOLV = 1
6
+
7
+ def verify_aritcaptcha(params)
8
+ if (equation_key = params[:equation_key]) and (equation = params[:equation])
9
+ if session[:equation] and session[:equation][SOLV_KEY] == equation_key.to_i and session[:equation][SOLV] == equation.to_i
10
+ clean session[:image]
11
+ return true
12
+ end
13
+ end
14
+ end
15
+
16
+ def clean image
17
+ unless image == nil
18
+ relative_name = "equacao-#{image}.png"
19
+ full_path = "#{Rails.root}/public/images/#{relative_name}"
20
+ File.delete(full_path)
21
+ end
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,28 @@
1
+ module Aritcaptcha
2
+
3
+ class Calculation
4
+
5
+ def self.generate_calculation number1, number2, operator, &block
6
+ # Division by zero
7
+ return [nil, nil] if operator == "/" and number1.zero? or number2.zero?
8
+
9
+ number1 = rand(number1)
10
+ number2 = rand(number2)
11
+
12
+ equation = "#{number1} #{operator} #{number2}"
13
+ result = eval("#{number1.to_f} #{operator} #{number2.to_f}")
14
+
15
+ if result.infinite?
16
+ # over and over again untill !infnite
17
+ number1 = rand(number1)
18
+ number2 = rand(number2)
19
+ result = eval("#{number1.to_f} #{operator} #{number2.to_f}")
20
+ end
21
+
22
+ result = (result == result.floor) ? result.to_i : result
23
+ [equation, result]
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Aritcaptcha" do
4
+ it "should return the correct sum of its arguments" do
5
+ Aritcaptcha::Calculation.generate_calculation(10, 10, "+").should have(2).items
6
+ end
7
+
8
+ it "should return the subtraction of its arguments" do
9
+ Aritcaptcha::Calculation.generate_calculation(20, 10, "-").should have(2).items
10
+ end
11
+
12
+ it "should return the division of its arguments" do
13
+ Aritcaptcha::Calculation.generate_calculation(10, 2, "/").should have(2).items
14
+ end
15
+
16
+ it "should return the multiplication of its arguments" do
17
+ Aritcaptcha::Calculation.generate_calculation(10, 10, "*").should have(2).items
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'aritcaptcha/calculation'
data/tags ADDED
File without changes
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aritcaptcha-keeguon
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Guilherme Nascimento
8
+ - Felix Bellanger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-05-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.2.9
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.2.9
28
+ description: Arithmetic Captcha
29
+ email: guilherme.ruby@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ - README.markdown
35
+ files:
36
+ - .document
37
+ - LICENSE
38
+ - README.markdown
39
+ - Rakefile
40
+ - VERSION
41
+ - aritcaptcha.gemspec
42
+ - lib/aritcaptcha.rb
43
+ - lib/aritcaptcha/aritcaptcha_helper.rb
44
+ - lib/aritcaptcha/aritcaptcha_verify.rb
45
+ - lib/aritcaptcha/calculation.rb
46
+ - spec/aritcaptcha_spec.rb
47
+ - spec/spec.opts
48
+ - spec/spec_helper.rb
49
+ - tags
50
+ homepage: http://github.com/guinascimento/aritcaptcha
51
+ licenses: []
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.1.11
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Arithmetic Captcha
73
+ test_files:
74
+ - spec/aritcaptcha_spec.rb
75
+ - spec/spec_helper.rb