aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vendor/plugins/recaptcha/LICENSE19
-rw-r--r--vendor/plugins/recaptcha/README5
-rw-r--r--vendor/plugins/recaptcha/Rakefile23
-rw-r--r--vendor/plugins/recaptcha/init.rb3
-rw-r--r--vendor/plugins/recaptcha/install.rb1
-rw-r--r--vendor/plugins/recaptcha/lib/recaptcha.rb69
-rw-r--r--vendor/plugins/recaptcha/tasks/recaptcha_tasks.rake4
-rw-r--r--vendor/plugins/recaptcha/test/recaptcha_test.rb49
-rw-r--r--vendor/plugins/recaptcha/uninstall.rb1
9 files changed, 174 insertions, 0 deletions
diff --git a/vendor/plugins/recaptcha/LICENSE b/vendor/plugins/recaptcha/LICENSE
new file mode 100644
index 000000000..dc9c67e75
--- /dev/null
+++ b/vendor/plugins/recaptcha/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2007 Jason L Perry
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE. \ No newline at end of file
diff --git a/vendor/plugins/recaptcha/README b/vendor/plugins/recaptcha/README
new file mode 100644
index 000000000..8453064c6
--- /dev/null
+++ b/vendor/plugins/recaptcha/README
@@ -0,0 +1,5 @@
+NOTICE
+
+This plugin has moved to http://github.com/ambethia/recaptcha
+
+This subversion repository will no longer be updated, and eventually cease to exist.
diff --git a/vendor/plugins/recaptcha/Rakefile b/vendor/plugins/recaptcha/Rakefile
new file mode 100644
index 000000000..50d21099d
--- /dev/null
+++ b/vendor/plugins/recaptcha/Rakefile
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the recaptcha plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the recaptcha plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'reCAPTCHA'
+ rdoc.template = 'jamis'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
diff --git a/vendor/plugins/recaptcha/init.rb b/vendor/plugins/recaptcha/init.rb
new file mode 100644
index 000000000..28494d250
--- /dev/null
+++ b/vendor/plugins/recaptcha/init.rb
@@ -0,0 +1,3 @@
+require 'recaptcha.rb'
+ActionView::Base.send :include, Ambethia::ReCaptcha::Helper
+ActionController::Base.send :include, Ambethia::ReCaptcha::Controller \ No newline at end of file
diff --git a/vendor/plugins/recaptcha/install.rb b/vendor/plugins/recaptcha/install.rb
new file mode 100644
index 000000000..a63be40f4
--- /dev/null
+++ b/vendor/plugins/recaptcha/install.rb
@@ -0,0 +1 @@
+puts IO.read(File.join(File.dirname(__FILE__), 'README')) \ No newline at end of file
diff --git a/vendor/plugins/recaptcha/lib/recaptcha.rb b/vendor/plugins/recaptcha/lib/recaptcha.rb
new file mode 100644
index 000000000..786555316
--- /dev/null
+++ b/vendor/plugins/recaptcha/lib/recaptcha.rb
@@ -0,0 +1,69 @@
+# ReCAPTCHA
+module Ambethia
+ module ReCaptcha
+ RECAPTCHA_API_SERVER = 'http://api.recaptcha.net';
+ RECAPTCHA_API_SECURE_SERVER = 'https://api-secure.recaptcha.net';
+ RECAPTCHA_VERIFY_SERVER = 'api-verify.recaptcha.net';
+
+ SKIP_VERIFY_ENV = ['test']
+
+ module Helper
+ # Your public API can be specified in the +options+ hash or preferably the environment
+ # variable +RECAPTCHA_PUBLIC_KEY+.
+ def recaptcha_tags(options = {})
+ # Default options
+ key = options[:public_key] ||= ENV['RECAPTCHA_PUBLIC_KEY']
+ error = options[:error] ||= session[:recaptcha_error]
+ uri = options[:ssl] ? RECAPTCHA_API_SECURE_SERVER : RECAPTCHA_API_SERVER
+ xhtml = Builder::XmlMarkup.new :target => out=(''), :indent => 2 # Because I can.
+ if options[:display]
+ xhtml.script(:type => "text/javascript"){ xhtml.text! "var RecaptchaOptions = #{options[:display].to_json};\n"}
+ end
+ xhtml.script(:type => "text/javascript", :src => "#{uri}/challenge?k=#{key}&error=#{error}") {}
+ unless options[:noscript] == false
+ xhtml.noscript do
+ xhtml.iframe(:src => "#{uri}/noscript?k=#{key}",
+ :height => options[:iframe_height] ||= 300,
+ :width => options[:iframe_width] ||= 500,
+ :frameborder => 0) {}; xhtml.br
+ xhtml.textarea(:name => "recaptcha_challenge_field", :rows => 3, :cols => 40) {}
+ xhtml.input :name => "recaptcha_response_field",
+ :type => "hidden", :value => "manual_challenge"
+ end
+ end
+ raise ReCaptchaError, "No public key specified." unless key
+ return out
+ end # recaptcha_tags
+ end # Helpers
+
+ module Controller
+ # Your private API key must be specified in the environment variable +RECAPTCHA_PRIVATE_KEY+
+ def verify_recaptcha(model = nil)
+ return true if SKIP_VERIFY_ENV.include? ENV['RAILS_ENV']
+ raise ReCaptchaError, "No private key specified." unless ENV['RECAPTCHA_PRIVATE_KEY']
+ begin
+ recaptcha = Net::HTTP.post_form URI.parse("http://#{RECAPTCHA_VERIFY_SERVER}/verify"), {
+ :privatekey => ENV['RECAPTCHA_PRIVATE_KEY'],
+ :remoteip => request.remote_ip,
+ :challenge => params[:recaptcha_challenge_field],
+ :response => params[:recaptcha_response_field]
+ }
+ answer, error = recaptcha.body.split.map(&:chomp)
+ unless answer == 'true'
+ session[:recaptcha_error] = error
+ model.errors.add_to_base "Captcha response is incorrect, please try again." if model
+ return false
+ else
+ session[:recaptcha_error] = nil
+ return true
+ end
+ rescue Exception => e
+ raise ReCaptchaError, e
+ end
+ end # verify_recaptcha
+ end # ControllerHelpers
+
+ class ReCaptchaError < StandardError; end
+
+ end # ReCaptcha
+end # Ambethia \ No newline at end of file
diff --git a/vendor/plugins/recaptcha/tasks/recaptcha_tasks.rake b/vendor/plugins/recaptcha/tasks/recaptcha_tasks.rake
new file mode 100644
index 000000000..a0cf1ad13
--- /dev/null
+++ b/vendor/plugins/recaptcha/tasks/recaptcha_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :recaptcha do
+# # Task goes here
+# end \ No newline at end of file
diff --git a/vendor/plugins/recaptcha/test/recaptcha_test.rb b/vendor/plugins/recaptcha/test/recaptcha_test.rb
new file mode 100644
index 000000000..0373d25b1
--- /dev/null
+++ b/vendor/plugins/recaptcha/test/recaptcha_test.rb
@@ -0,0 +1,49 @@
+require 'test/unit'
+require 'builder'
+require File.dirname(__FILE__) + '/../lib/recaptcha'
+
+class ReCaptchaTest < Test::Unit::TestCase
+ include Ambethia::ReCaptcha
+ include Ambethia::ReCaptcha::Helper
+ include Ambethia::ReCaptcha::Controller
+
+ attr_accessor :session
+
+ def setup
+ @session = {}
+ ENV['RECAPTCHA_PUBLIC_KEY'] = '0000000000000000000000000000000000000000'
+ ENV['RECAPTCHA_PRIVATE_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
+ end
+
+ def test_recaptcha_tags
+ # Might as well match something...
+ assert_match /http:\/\/api.recaptcha.net/, recaptcha_tags
+ end
+
+ def test_recaptcha_tags_with_ssl
+ assert_match /https:\/\/api-secure.recaptcha.net/, recaptcha_tags(:ssl => true)
+ end
+
+ def test_recaptcha_tags_without_noscript
+ assert_no_match /noscript/, recaptcha_tags(:noscript => false)
+ end
+
+ def test_should_raise_exception_without_public_key
+ assert_raise ReCaptchaError do
+ ENV['RECAPTCHA_PUBLIC_KEY'] = nil
+ recaptcha_tags
+ end
+ end
+
+ def test_should_raise_exception_without_private_key
+ assert_raise ReCaptchaError do
+ ENV['RECAPTCHA_PRIVATE_KEY'] = nil
+ verify_recaptcha
+ end
+ end
+
+ def test_should_verify_recaptcha
+ # TODO Mock this, or figure something out...
+ end
+
+end
diff --git a/vendor/plugins/recaptcha/uninstall.rb b/vendor/plugins/recaptcha/uninstall.rb
new file mode 100644
index 000000000..973833346
--- /dev/null
+++ b/vendor/plugins/recaptcha/uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here