recaptcha 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,6 +25,14 @@ Or, as a standard rails plugin:
25
25
 
26
26
  script/plugin install git://github.com/ambethia/recaptcha.git
27
27
 
28
+ == Merb Installation
29
+
30
+ reCAPTCHA can also be used in a Merb application when installed as a gem:
31
+
32
+ dependency "alm-recaptcha", ">=0.2.2.1", :require_as => "recaptcha/merb"
33
+
34
+ Initial Merb compatability funded by ALM Labs.
35
+
28
36
  == Setting up your API Keys
29
37
 
30
38
  There are two ways to setup your reCAPTCHA API keys once you {obtain}[http://recaptcha.net/whyrecaptcha.html]
data/Rakefile CHANGED
@@ -6,11 +6,12 @@ begin
6
6
  gem.name = "recaptcha"
7
7
  gem.description = "This plugin adds helpers for the reCAPTCHA API "
8
8
  gem.summary = "Helpers for the reCAPTCHA API"
9
- gem.homepage = "http://github.com/ambethia/recaptcha"
9
+ gem.homepage = "http://ambethia.com/recaptcha"
10
10
  gem.authors = ["Jason L. Perry"]
11
11
  gem.email = "jasper@ambethia.com"
12
12
  gem.files.reject! { |fn| fn.include? ".gitignore" }
13
13
  end
14
+ Jeweler::GemcutterTasks.new
14
15
  rescue LoadError
15
16
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
16
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/init.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # Rails plugin initialization.
2
2
  # You can also install it as a gem:
3
3
  # config.gem "ambethia-recaptcha", :lib => "recaptcha/rails", :source => "http://gems.github.com"
4
+
5
+ require 'net/http'
4
6
  require 'recaptcha/rails'
@@ -6,8 +6,9 @@ module Recaptcha
6
6
  MAJOR = 0
7
7
  MINOR = 2
8
8
  TINY = 2
9
+ PATCH = 1
9
10
 
10
- STRING = [MAJOR, MINOR, TINY].join('.')
11
+ STRING = [MAJOR, MINOR, TINY, PATCH].join('.')
11
12
  end
12
13
 
13
14
 
@@ -5,7 +5,8 @@ module Recaptcha
5
5
  def recaptcha_tags(options = {})
6
6
  # Default options
7
7
  key = options[:public_key] ||= ENV['RECAPTCHA_PUBLIC_KEY']
8
- error = options[:error] ||= session[:recaptcha_error]
8
+ raise RecaptchaError, "No public key specified." unless key
9
+ error = options[:error] ||= (defined? flash ? flash[:recaptcha_error] : "")
9
10
  uri = options[:ssl] ? RECAPTCHA_API_SECURE_SERVER : RECAPTCHA_API_SERVER
10
11
  html = ""
11
12
  if options[:display]
@@ -17,7 +18,7 @@ module Recaptcha
17
18
  html << %{<div id="dynamic_recaptcha"></div>}
18
19
  html << %{<script type="text/javascript" src="#{uri}/js/recaptcha_ajax.js"></script>\n}
19
20
  html << %{<script type="text/javascript">\n}
20
- html << %{ Recaptcha.create('#{key}', document.getElementById('dynamic_recaptcha')#{options[:display] ? '' : ',RecaptchaOptions'});}
21
+ html << %{ Recaptcha.create('#{key}', document.getElementById('dynamic_recaptcha')#{options[:display] ? ',RecaptchaOptions' : ''});}
21
22
  html << %{</script>\n}
22
23
  else
23
24
  html << %{<script type="text/javascript" src="#{uri}/challenge?k=#{key}}
@@ -35,8 +36,7 @@ module Recaptcha
35
36
  html << %{</noscript>\n}
36
37
  end
37
38
  end
38
- raise RecaptchaError, "No public key specified." unless key
39
39
  return html
40
40
  end # recaptcha_tags
41
41
  end # ClientHelper
42
- end # Recaptcha
42
+ end # Recaptcha
@@ -0,0 +1,4 @@
1
+ require 'recaptcha'
2
+
3
+ Merb::GlobalHelpers.send(:include, Recaptcha::ClientHelper)
4
+ Merb::Controller.send(:include, Recaptcha::Verify)
@@ -3,11 +3,16 @@ module Recaptcha
3
3
  # Your private API can be specified in the +options+ hash or preferably
4
4
  # the environment variable +RECAPTCHA_PUBLIC_KEY+.
5
5
  def verify_recaptcha(options = {})
6
- return true if SKIP_VERIFY_ENV.include? ENV['RAILS_ENV']
7
- model = options.is_a?(Hash)? options[:model] : options
8
- private_key = options[:private_key] if options.is_a?(Hash)
9
- private_key ||= ENV['RECAPTCHA_PRIVATE_KEY']
6
+ if !options.is_a? Hash
7
+ options = {:model => options}
8
+ end
9
+
10
+ env = options[:env] || ENV['RAILS_ENV']
11
+ return true if SKIP_VERIFY_ENV.include? env
12
+ model = options[:model]
13
+ private_key = options[:private_key] || ENV['RECAPTCHA_PRIVATE_KEY']
10
14
  raise RecaptchaError, "No private key specified." unless private_key
15
+
11
16
  begin
12
17
  recaptcha = nil
13
18
  Timeout::timeout(options[:timeout] || 3) do
@@ -20,21 +25,21 @@ module Recaptcha
20
25
  end
21
26
  answer, error = recaptcha.body.split.map { |s| s.chomp }
22
27
  unless answer == 'true'
23
- session[:recaptcha_error] = error
28
+ flash[:recaptcha_error] = error
24
29
  if model
25
30
  model.valid?
26
- model.errors.add :base, options[:message] || "Captcha response is incorrect, please try again."
31
+ model.errors.add :base, options[:message] || "Word verification response is incorrect, please try again."
27
32
  end
28
33
  return false
29
34
  else
30
- session[:recaptcha_error] = nil
35
+ flash[:recaptcha_error] = nil
31
36
  return true
32
37
  end
33
38
  rescue Timeout::Error
34
- session[:recaptcha_error] = "recaptcha-not-reachable"
39
+ flash[:recaptcha_error] = "recaptcha-not-reachable"
35
40
  if model
36
41
  model.valid?
37
- model.errors.add :base, options[:message] || "Oops, we failed to validate your Captcha. Please try again."
42
+ model.errors.add :base, options[:message] || "Oops, we failed to validate your word verification response. Please try again."
38
43
  end
39
44
  return false
40
45
  rescue Exception => e
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{recaptcha}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jason L. Perry"]
12
- s.date = %q{2009-10-14}
12
+ s.date = %q{2009-10-23}
13
13
  s.description = %q{This plugin adds helpers for the reCAPTCHA API }
14
14
  s.email = %q{jasper@ambethia.com}
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "init.rb",
26
26
  "lib/recaptcha.rb",
27
27
  "lib/recaptcha/client_helper.rb",
28
+ "lib/recaptcha/merb.rb",
28
29
  "lib/recaptcha/rails.rb",
29
30
  "lib/recaptcha/verify.rb",
30
31
  "recaptcha.gemspec",
@@ -32,7 +33,7 @@ Gem::Specification.new do |s|
32
33
  "test/recaptcha_test.rb",
33
34
  "test/verify_recaptcha_test.rb"
34
35
  ]
35
- s.homepage = %q{http://github.com/ambethia/recaptcha}
36
+ s.homepage = %q{http://ambethia.com/recaptcha}
36
37
  s.rdoc_options = ["--charset=UTF-8"]
37
38
  s.require_paths = ["lib"]
38
39
  s.rubygems_version = %q{1.3.5}
@@ -52,3 +53,4 @@ Gem::Specification.new do |s|
52
53
  else
53
54
  end
54
55
  end
56
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason L. Perry
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-14 00:00:00 -04:00
12
+ date: 2009-10-23 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -31,6 +31,7 @@ files:
31
31
  - init.rb
32
32
  - lib/recaptcha.rb
33
33
  - lib/recaptcha/client_helper.rb
34
+ - lib/recaptcha/merb.rb
34
35
  - lib/recaptcha/rails.rb
35
36
  - lib/recaptcha/verify.rb
36
37
  - recaptcha.gemspec
@@ -38,7 +39,7 @@ files:
38
39
  - test/recaptcha_test.rb
39
40
  - test/verify_recaptcha_test.rb
40
41
  has_rdoc: true
41
- homepage: http://github.com/ambethia/recaptcha
42
+ homepage: http://ambethia.com/recaptcha
42
43
  licenses: []
43
44
 
44
45
  post_install_message: