aritcaptcha 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,35 @@
1
+ # Aritcaptcha: A simple numeric captcha for Rails 3
2
+
3
+ Aritcaptcha provides a simple way to display a numeric 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 numeric 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], :format => "image" %> # only the operations of addition and subtraction are displayed
22
+
23
+ ## Contributing to Aritcaptcha
24
+
25
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
26
+ * Check out the [issue tracker](http://github.com/guinascimento/aritcaptcha/issues) to make sure someone already hasn't requested it and/or contributed it
27
+ * Fork the project
28
+ * Start a feature/bugfix branch
29
+ * Commit and push until you are happy with your contribution
30
+ * Make sure to add tests for the feature/bugfix. This is important so I don't break it in a future version unintentionally.
31
+ * 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.
32
+
33
+ ## Copyright
34
+
35
+ Copyright (c) 2011 Guilherme Nascimento. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
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 = "2.0.1"
8
+ s.version = "2.0.2"
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"]
@@ -14,12 +14,12 @@ Gem::Specification.new do |s|
14
14
  s.email = %q{guilherme.ruby@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.markdown"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  "LICENSE",
22
- "README.rdoc",
22
+ "README.markdown",
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "aritcaptcha.gemspec",
@@ -1,3 +1,5 @@
1
+ require "aritcaptcha/calculation"
2
+
1
3
  module Aritcaptcha
2
4
 
3
5
  module AritcaptchaHelper
@@ -29,17 +31,18 @@ module Aritcaptcha
29
31
  session[:equation] = [equation_key, eval(equation)]
30
32
 
31
33
  if options[:html]
32
- options = options[:html].inject([]) { |dump, pair| dump << "#{pair[0]}=\"#{pair[1]}\"" }
33
- options = options.join(" ")
34
+ options_html = options[:html].inject([]) { |dump, pair| dump << "#{pair[0]}=\"#{pair[1]}\"" }
35
+ options_html = options_html.join(" ")
34
36
  end
35
37
 
36
38
  html = ""
37
39
  if options[:format] == "image"
38
40
  session[:image] = equation_key
39
41
  img = generate_image equation_key, equation
40
- html << "<img src=\"/images/aritcaptcha/#{img}\" style='vertical-align:top;' /> <input type=\"text\" name=\"equation\" size=\"3\" style='vertical-align:top;' #{options} />"
42
+
43
+ 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?} />"
41
44
  else
42
- html << "#{equation} = <input type=\"text\" name=\"equation\" style='vertical-align:top;' size=\"3\" #{options} /></div>"
45
+ html << "#{equation} = <input type=\"text\" name=\"equation\" style='vertical-align:top;' size=\"3\" #{options_html unless options_html.nil?} /></div>"
43
46
  end
44
47
 
45
48
  html << "<input type=\"hidden\" name=\"equation_key\" value=\"#{equation_key}\" /> \n"
@@ -47,20 +50,20 @@ module Aritcaptcha
47
50
 
48
51
  def generate_image(equation_key, equation)
49
52
  relative_name = "#{equation_key}.png"
50
- full_path = "#{Rails.root}/public/images/aritcaptcha/#{relative_name}"
53
+ full_path = "#{Rails.root}/public/images/#{relative_name}"
51
54
 
52
55
  unless File.file?(full_path)
53
- image = Magick::Image.new(85, 25)
56
+ image = Magick::Image.new(85, 32)
54
57
  image.format = "PNG"
55
58
  title = Magick::Draw.new
56
59
 
57
- title.annotate(image, 5, 5, 5, 5, equation + " =") do
60
+ title.annotate(image, 5, 5, 12, 7, equation + " =") do
58
61
  self.fill = "#333"
59
62
  self.font = Rails.root + "/fonts/Clarenton LT Bold.ttf"
60
63
  self.font_family = "Clarenton LT Bold"
61
64
  self.font_weight = Magick::BoldWeight
62
65
  self.gravity = Magick::NorthWestGravity
63
- self.pointsize = 20
66
+ self.pointsize = 15
64
67
  end
65
68
  image.write(full_path)
66
69
  end
@@ -5,18 +5,19 @@ module Aritcaptcha
5
5
  SOLV = 1
6
6
 
7
7
  def verify_aritcaptcha(params)
8
- clean session[:image]
9
-
10
8
  if (equation_key = params[:equation_key]) and (equation = params[:equation])
11
- return (session[:equation] and session[:equation][SOLV_KEY] == equation_key.to_i and session[:equation][SOLV] == equation.to_i)
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
12
13
  end
13
14
  end
14
15
 
15
16
  def clean image
16
17
  unless image == nil
17
- relative_name = "#{image}.png"
18
- full_path = "#{Rails.root}/public/images/aritcaptcha/#{relative_name}"
19
- File.delete(full_path)
18
+ relative_name = "#{image}.png"
19
+ full_path = "#{Rails.root}/public/images/#{relative_name}"
20
+ File.delete(full_path)
20
21
  end
21
22
  end
22
23
  end
data/lib/aritcaptcha.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require 'aritcaptcha/aritcaptcha_helper'
2
+ require 'aritcaptcha/aritcaptcha_verify'
2
3
 
3
- ActionView::Base.send(:include, Aritcaptcha::AritcaptchaHelper)
4
+ ActionView::Base.send(:include, Aritcaptcha::AritcaptchaHelper)
5
+ 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: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 1
10
- version: 2.0.1
9
+ - 2
10
+ version: 2.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Guilherme Nascimento
@@ -42,11 +42,11 @@ extensions: []
42
42
 
43
43
  extra_rdoc_files:
44
44
  - LICENSE
45
- - README.rdoc
45
+ - README.markdown
46
46
  files:
47
47
  - .document
48
48
  - LICENSE
49
- - README.rdoc
49
+ - README.markdown
50
50
  - Rakefile
51
51
  - VERSION
52
52
  - aritcaptcha.gemspec
data/README.rdoc DELETED
@@ -1,17 +0,0 @@
1
- = aritcaptcha
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2010 Guilherme Nascimento. See LICENSE for details.