antage-merb-recaptcha 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +45 -0
- data/Rakefile +18 -3
- data/lib/merb-recaptcha.rb +3 -2
- data/lib/merb-recaptcha/constants.rb +7 -0
- data/lib/merb-recaptcha/controller_mixin.rb +8 -2
- data/lib/merb-recaptcha/exceptions.rb +21 -1
- data/lib/merb-recaptcha/view_helpers.rb +47 -6
- data/merb-recaptcha.gemspec +13 -7
- data/spec/recaptcha_valid_spec.rb +19 -3
- data/spec/spec_helper.rb +2 -0
- metadata +51 -41
- data/README.textile +0 -45
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= merb-recaptcha
|
2
|
+
|
3
|
+
== About
|
4
|
+
|
5
|
+
Merb-recaptcha is plugin for Merb web-framework. It provides view and controller helpers for Recaptcha service.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Install gem from github.com:
|
10
|
+
gem install antage-merb-recaptcha --source=http://gems.github.com
|
11
|
+
|
12
|
+
Add following line in <tt>config/dependencies.rb</tt> of your web application:
|
13
|
+
dependency "antage-merb-recaptcha", "~> 1.0.0", :require_as => "merb-recaptcha"
|
14
|
+
|
15
|
+
Sign up at Recaptcha and get public and private keys. Add keys in <tt>config/init.rb</tt>:
|
16
|
+
Merb::BootLoader.after_app_loads do
|
17
|
+
Merb::Plugins.config[:merb_recaptcha][:public_key] = "... here your public key ..."
|
18
|
+
Merb::Plugins.config[:merb_recaptcha][:private_key] = "... here your private key ..."
|
19
|
+
end
|
20
|
+
|
21
|
+
== Usage
|
22
|
+
|
23
|
+
Just add helper in your form:
|
24
|
+
<%= form_for @users, :action => resource(:users), :method => :post do %>
|
25
|
+
.....
|
26
|
+
<%= recaptcha_tags %>
|
27
|
+
<%= submit "Send" %>
|
28
|
+
<% end %>
|
29
|
+
|
30
|
+
And then check captcha in controller:
|
31
|
+
class Users < Application
|
32
|
+
......
|
33
|
+
def create(user)
|
34
|
+
@user = User.new(user)
|
35
|
+
if (captcha_correct = recaptcha_valid?) && @user.save
|
36
|
+
redirect resource(@user)
|
37
|
+
else
|
38
|
+
unless captcha_correct
|
39
|
+
@user.valid?
|
40
|
+
@user.errors.add(:general, "Captcha code is incorrect")
|
41
|
+
end
|
42
|
+
render :new
|
43
|
+
end
|
44
|
+
......
|
45
|
+
end
|
data/Rakefile
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake/gempackagetask'
|
3
|
+
require 'rake/rdoctask'
|
3
4
|
require 'rake/clean'
|
4
5
|
|
6
|
+
require 'yard'
|
7
|
+
require 'yard/rake/yardoc_task'
|
8
|
+
|
5
9
|
require 'spec/rake/spectask'
|
6
10
|
|
7
11
|
require 'merb-core'
|
8
12
|
require 'merb-core/tasks/merb'
|
9
13
|
|
10
14
|
GEM_NAME = "merb-recaptcha"
|
11
|
-
GEM_VERSION = "1.0.
|
15
|
+
GEM_VERSION = "1.0.1"
|
12
16
|
AUTHOR = "Anton Ageev"
|
13
17
|
EMAIL = "antage@gmail.com"
|
14
18
|
HOMEPAGE = "http://github.com/antage/merb-recaptcha/"
|
@@ -20,19 +24,21 @@ spec = Gem::Specification.new do |s|
|
|
20
24
|
s.version = GEM_VERSION
|
21
25
|
s.platform = Gem::Platform::RUBY
|
22
26
|
s.has_rdoc = true
|
23
|
-
s.extra_rdoc_files = ["README.
|
27
|
+
s.extra_rdoc_files = [ "README.rdoc", "LICENSE" ]
|
28
|
+
s.rdoc_options << "--main" << "README.rdoc"
|
24
29
|
s.summary = SUMMARY
|
25
30
|
s.description = s.summary
|
26
31
|
s.author = AUTHOR
|
27
32
|
s.email = EMAIL
|
28
33
|
s.homepage = HOMEPAGE
|
29
34
|
s.require_path = 'lib'
|
30
|
-
s.files = %w(LICENSE README.
|
35
|
+
s.files = %w(LICENSE README.rdoc Rakefile TODO merb-recaptcha.gemspec) + Dir["lib/**/*"].select { |f| File.file?(f) }
|
31
36
|
s.test_files = %w(spec/spec_helper.rb) + Dir["spec/*_spec.rb"] + Dir["spec/fixture/app/**/*"].select { |f| File.file?(f) }
|
32
37
|
|
33
38
|
s.add_runtime_dependency "merb-core", ">= 1.0.0"
|
34
39
|
s.add_runtime_dependency "builder", "~> 2.0"
|
35
40
|
s.add_development_dependency "rspec", ">= 1.1.0"
|
41
|
+
s.add_development_dependency "mocha", ">= 0.9.3"
|
36
42
|
end
|
37
43
|
|
38
44
|
Rake::GemPackageTask.new(spec) do |pkg|
|
@@ -56,6 +62,15 @@ task :gemspec do
|
|
56
62
|
end
|
57
63
|
end
|
58
64
|
|
65
|
+
Rake::RDocTask.new do |rdoc|
|
66
|
+
files = ["README.rdoc", "LICENSE", "lib/**/*.rb"]
|
67
|
+
rdoc.rdoc_files.add(files)
|
68
|
+
rdoc.main = "README.rdoc"
|
69
|
+
rdoc.title = "merb-recaptcha docs"
|
70
|
+
rdoc.rdoc_dir = "doc"
|
71
|
+
rdoc.options << "--line-numbers" << "--inline-source"
|
72
|
+
end
|
73
|
+
|
59
74
|
Spec::Rake::SpecTask.new(:spec) do |t|
|
60
75
|
t.spec_opts << '--format' << 'specdoc' << '--colour'
|
61
76
|
t.spec_opts << '--loadby' << 'random'
|
data/lib/merb-recaptcha.rb
CHANGED
@@ -9,13 +9,14 @@ if defined?(Merb::Plugins)
|
|
9
9
|
|
10
10
|
Merb::BootLoader.before_app_loads do
|
11
11
|
# require code that must be loaded before the application
|
12
|
+
require 'merb-recaptcha/constants.rb'
|
12
13
|
require 'merb-recaptcha/view_helpers.rb'
|
13
14
|
require 'merb-recaptcha/exceptions.rb'
|
14
15
|
require 'merb-recaptcha/controller_mixin.rb'
|
15
|
-
module Merb::GlobalHelpers
|
16
|
+
module Merb::GlobalHelpers # :nodoc:
|
16
17
|
include Merb::Helpers::Recaptcha
|
17
18
|
end
|
18
|
-
class Merb::Controller
|
19
|
+
class Merb::Controller # :nodoc:
|
19
20
|
include Merb::RecaptchaMixin
|
20
21
|
end
|
21
22
|
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
|
3
|
-
module Merb
|
3
|
+
module Merb # :nodoc:
|
4
4
|
module RecaptchaMixin
|
5
|
+
|
6
|
+
# This method checks challenge and response data via Recaptcha API server.
|
7
|
+
# * It will return true, if filled captcha response is correct.
|
8
|
+
# * It will return false, if captcha is incorrect.
|
9
|
+
# * It will raise exception, if Recaptcha API server returns error.
|
10
|
+
#
|
5
11
|
def recaptcha_valid?
|
6
|
-
response = Net::HTTP.post_form(URI.parse("
|
12
|
+
response = Net::HTTP.post_form(URI.parse("#{Merb::Recaptcha::API_VERIFY_SERVER}/verify"), {
|
7
13
|
:privatekey => Merb::Plugins.config[:merb_recaptcha][:private_key],
|
8
14
|
:remoteip => request.remote_ip,
|
9
15
|
:challenge => params[:recaptcha_challenge_field],
|
@@ -1,10 +1,30 @@
|
|
1
|
-
module Merb
|
1
|
+
module Merb # :nodoc:
|
2
2
|
module Recaptcha
|
3
3
|
class GenericError < RuntimeError; end
|
4
|
+
|
5
|
+
# We weren't able to verify the public key.
|
6
|
+
# Possible solutions:
|
7
|
+
#
|
8
|
+
# * Did you swap the public and private key? It is important to use the correct one
|
9
|
+
# * Did you make sure to copy the entire key, with all hyphens and underscores, but without any spaces? The key should be exactly 40 letters long.
|
10
|
+
#
|
4
11
|
class InvalidSitePublicKey < GenericError; end
|
12
|
+
|
13
|
+
# We weren't able to verify the private key.
|
14
|
+
# Possible solutions:
|
15
|
+
#
|
16
|
+
# * Did you swap the public and private key? It is important to use the correct one
|
17
|
+
# * Did you make sure to copy the entire key, with all hyphens and underscores, but without any spaces? The key should be exactly 40 letters long.
|
18
|
+
#
|
5
19
|
class InvalidSitePrivateKey < GenericError; end
|
20
|
+
|
21
|
+
# The challenge parameter of the verify script was incorrect.
|
6
22
|
class InvalidRequestCookie < GenericError; end
|
23
|
+
|
24
|
+
# The parameters to /verify were incorrect, make sure you are passing all the required parameters.
|
7
25
|
class VerifyParamsIncorrect < GenericError; end
|
26
|
+
|
27
|
+
# reCAPTCHA API keys are tied to a specific domain name for security reasons.
|
8
28
|
class InvalidReferrer < GenericError; end
|
9
29
|
end
|
10
30
|
end
|
@@ -1,11 +1,52 @@
|
|
1
1
|
require 'builder'
|
2
2
|
|
3
|
-
module Merb
|
4
|
-
module Helpers
|
3
|
+
module Merb # :nodoc:
|
4
|
+
module Helpers # :nodoc:
|
5
5
|
module Recaptcha
|
6
|
-
API_SERVER = "http://api.recaptcha.net"
|
7
|
-
API_SECURE_SERVER = "https://api-secure.recaptcha.net"
|
8
6
|
|
7
|
+
# Display recaptcha widget in various ways.
|
8
|
+
#
|
9
|
+
# * Display in-place:
|
10
|
+
# <%= recaptcha_tags :ajax => false, :noscript => false %>
|
11
|
+
#
|
12
|
+
# * Display in-place with <noscript></noscript> block:
|
13
|
+
# <%= recaptcha_tags :ajax => false, :noscript => true, :iframe_height => 100, :iframe_width => 100 %>
|
14
|
+
#
|
15
|
+
# * Dynamically create Recaptcha widget:
|
16
|
+
# <%= recaptcha_tags :ajax => true, :element_id => "recaptcha_place" %>
|
17
|
+
# <div id="recaptcha_place"></div>
|
18
|
+
# The above code bind javascript code on onload event:
|
19
|
+
# <script type="text/javascript">
|
20
|
+
# ....
|
21
|
+
# window.onload = function() { Recaptcha.create(....); }
|
22
|
+
# ....
|
23
|
+
# </script>
|
24
|
+
# If you use jQuery, you could use special value for :ajax parameter:
|
25
|
+
# <%= recaptcha_tags :ajax => :jquery %>
|
26
|
+
# <div id="recpatcha"></div>
|
27
|
+
# This code generates following:
|
28
|
+
# <script type="text/javascript">
|
29
|
+
# ....
|
30
|
+
# $(document).ready(function() { Recaptcha.create(....); });
|
31
|
+
# ....
|
32
|
+
# </script>
|
33
|
+
# You can specified callback function that will be invoked after widget has been created:
|
34
|
+
# <%= recaptcha_tags :ajax => true, :callback => "Recaptcha.focus_response_field" %>
|
35
|
+
# <div id="recaptcha"></div>
|
36
|
+
# This code will set focus on response field of created widget.
|
37
|
+
#
|
38
|
+
# For both displaying ways, you can customize widget:
|
39
|
+
# <%= recaptcha_tags :theme => "clean", :tabindex => 2 %>
|
40
|
+
# More detailed description of customizing options is at http://recaptcha.net/apidocs/captcha/client.html
|
41
|
+
#
|
42
|
+
# Default values of options:
|
43
|
+
# * :ajax => false
|
44
|
+
# * :element_id => "recaptcha"
|
45
|
+
# * :callback => nil
|
46
|
+
# * :noscript => false
|
47
|
+
# * :iframe_height => 300
|
48
|
+
# * :iframe_width => 500
|
49
|
+
#
|
9
50
|
def recaptcha_tags(options = {})
|
10
51
|
public_key = Merb::Plugins.config[:merb_recaptcha][:public_key]
|
11
52
|
|
@@ -17,9 +58,9 @@ module Merb
|
|
17
58
|
iframe_width = options.delete(:iframe_width) || 500 # integer, only if noscript == true
|
18
59
|
|
19
60
|
api_url = if request.ssl?
|
20
|
-
API_SECURE_SERVER
|
61
|
+
Merb::Recaptcha::API_SECURE_SERVER
|
21
62
|
else
|
22
|
-
API_SERVER
|
63
|
+
Merb::Recaptcha::API_SERVER
|
23
64
|
end
|
24
65
|
|
25
66
|
result = ""
|
data/merb-recaptcha.gemspec
CHANGED
@@ -1,38 +1,44 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.name = %q{merb-recaptcha}
|
3
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.1"
|
4
6
|
|
5
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
8
|
s.authors = ["Anton Ageev"]
|
7
|
-
s.date = %q{2008-12-
|
9
|
+
s.date = %q{2008-12-12}
|
8
10
|
s.description = %q{Merb plugin that provides helpers for recaptcha.net service}
|
9
11
|
s.email = %q{antage@gmail.com}
|
10
|
-
s.extra_rdoc_files = ["README.
|
11
|
-
s.files = ["LICENSE", "README.
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
|
13
|
+
s.files = ["LICENSE", "README.rdoc", "Rakefile", "TODO", "merb-recaptcha.gemspec", "lib/merb-recaptcha/constants.rb", "lib/merb-recaptcha/merbtasks.rb", "lib/merb-recaptcha/controller_mixin.rb", "lib/merb-recaptcha/view_helpers.rb", "lib/merb-recaptcha/exceptions.rb", "lib/merb-recaptcha.rb", "spec/spec_helper.rb", "spec/recaptcha_noajax_without_noscript_spec.rb", "spec/recaptcha_noajax_with_noscript_spec.rb", "spec/recaptcha_valid_spec.rb", "spec/recaptcha_ajax_spec.rb", "spec/recaptcha_ajax_with_callback_spec.rb", "spec/recaptcha_ajax_with_options_spec.rb", "spec/recaptcha_noajax_with_options_spec.rb", "spec/recaptcha_ajax_with_jquery_spec.rb", "spec/fixture/app/controllers/application.rb", "spec/fixture/app/controllers/exceptions.rb", "spec/fixture/app/controllers/recaptcha.rb", "spec/fixture/app/views/exceptions/not_acceptable.html.erb", "spec/fixture/app/views/exceptions/not_found.html.erb", "spec/fixture/app/views/layout/application.html.erb", "spec/fixture/app/views/recaptcha/ajax.html.erb", "spec/fixture/app/views/recaptcha/ajax_with_callback.html.erb", "spec/fixture/app/views/recaptcha/ajax_with_options.html.erb", "spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb", "spec/fixture/app/views/recaptcha/noajax_with_options.html.erb", "spec/fixture/app/views/recaptcha/noajax_with_noscript.html.erb", "spec/fixture/app/views/recaptcha/ajax_with_jquery.html.erb", "spec/fixture/app/helpers/global_helpers.rb", "spec/fixture/app/helpers/recaptcha_helpers.rb"]
|
12
14
|
s.has_rdoc = true
|
13
15
|
s.homepage = %q{http://github.com/antage/merb-recaptcha/}
|
16
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
14
17
|
s.require_paths = ["lib"]
|
15
18
|
s.rubyforge_project = %q{merb-recaptcha}
|
16
|
-
s.rubygems_version = %q{1.
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
17
20
|
s.summary = %q{Merb plugin that provides helpers for recaptcha.net service}
|
18
|
-
s.test_files = ["spec/spec_helper.rb", "spec/
|
21
|
+
s.test_files = ["spec/spec_helper.rb", "spec/recaptcha_noajax_without_noscript_spec.rb", "spec/recaptcha_noajax_with_noscript_spec.rb", "spec/recaptcha_valid_spec.rb", "spec/recaptcha_ajax_spec.rb", "spec/recaptcha_ajax_with_callback_spec.rb", "spec/recaptcha_ajax_with_options_spec.rb", "spec/recaptcha_noajax_with_options_spec.rb", "spec/recaptcha_ajax_with_jquery_spec.rb", "spec/fixture/app/controllers/application.rb", "spec/fixture/app/controllers/exceptions.rb", "spec/fixture/app/controllers/recaptcha.rb", "spec/fixture/app/views/exceptions/not_acceptable.html.erb", "spec/fixture/app/views/exceptions/not_found.html.erb", "spec/fixture/app/views/layout/application.html.erb", "spec/fixture/app/views/recaptcha/ajax.html.erb", "spec/fixture/app/views/recaptcha/ajax_with_callback.html.erb", "spec/fixture/app/views/recaptcha/ajax_with_options.html.erb", "spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb", "spec/fixture/app/views/recaptcha/noajax_with_options.html.erb", "spec/fixture/app/views/recaptcha/noajax_with_noscript.html.erb", "spec/fixture/app/views/recaptcha/ajax_with_jquery.html.erb", "spec/fixture/app/helpers/global_helpers.rb", "spec/fixture/app/helpers/recaptcha_helpers.rb"]
|
19
22
|
|
20
23
|
if s.respond_to? :specification_version then
|
21
24
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
25
|
s.specification_version = 2
|
23
26
|
|
24
|
-
if
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
25
28
|
s.add_runtime_dependency(%q<merb-core>, [">= 1.0.0"])
|
26
29
|
s.add_runtime_dependency(%q<builder>, ["~> 2.0"])
|
27
30
|
s.add_development_dependency(%q<rspec>, [">= 1.1.0"])
|
31
|
+
s.add_development_dependency(%q<mocha>, [">= 0.9.3"])
|
28
32
|
else
|
29
33
|
s.add_dependency(%q<merb-core>, [">= 1.0.0"])
|
30
34
|
s.add_dependency(%q<builder>, ["~> 2.0"])
|
31
35
|
s.add_dependency(%q<rspec>, [">= 1.1.0"])
|
36
|
+
s.add_dependency(%q<mocha>, [">= 0.9.3"])
|
32
37
|
end
|
33
38
|
else
|
34
39
|
s.add_dependency(%q<merb-core>, [">= 1.0.0"])
|
35
40
|
s.add_dependency(%q<builder>, ["~> 2.0"])
|
36
41
|
s.add_dependency(%q<rspec>, [">= 1.1.0"])
|
42
|
+
s.add_dependency(%q<mocha>, [">= 0.9.3"])
|
37
43
|
end
|
38
44
|
end
|
@@ -7,12 +7,28 @@ class FakeController < Merb::Controller
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "FakeController#check_recaptcha" do
|
10
|
-
def do_request
|
11
|
-
@response = dispatch_to(FakeController,
|
10
|
+
def do_request(ssl = false)
|
11
|
+
@response = dispatch_to(FakeController, :check_recaptcha, { :recaptcha_challenge_field => "blabla", :recaptcha_response_field => "blabla" }, { "HTTPS" => ssl ? "on" : "off" })
|
12
12
|
end
|
13
13
|
|
14
14
|
def stub_response(body)
|
15
|
-
Net::HTTP.
|
15
|
+
Net::HTTP.stubs(:post_form).returns stub("Net::HTTPResponse", :body => body)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "with non-SSL request" do
|
19
|
+
it "should use non-ssl API server" do
|
20
|
+
cond = proc { |*args| args.first.is_a?(URI::HTTP) && args.first.scheme == "http" && args.first.host == "api-verify.recaptcha.net" }
|
21
|
+
Net::HTTP.expects(:post_form).with(&cond).returns(stub("Net::HTTPResponse", :body => "true"))
|
22
|
+
do_request(false)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "with SSL request" do
|
27
|
+
it "should use non-ssl API server" do
|
28
|
+
cond = proc { |*args| args.first.is_a?(URI::HTTP) && args.first.scheme == "http" && args.first.host == "api-verify.recaptcha.net" }
|
29
|
+
Net::HTTP.expects(:post_form).with(&cond).returns(stub("Net::HTTPResponse", :body => "true"))
|
30
|
+
do_request(true)
|
31
|
+
end
|
16
32
|
end
|
17
33
|
|
18
34
|
describe "with correct response" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: antage-merb-recaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Ageev
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-12 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,6 +39,15 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.1.0
|
41
41
|
version:
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: mocha
|
44
|
+
version_requirement:
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.9.3
|
50
|
+
version:
|
42
51
|
description: Merb plugin that provides helpers for recaptcha.net service
|
43
52
|
email: antage@gmail.com
|
44
53
|
executables: []
|
@@ -46,49 +55,50 @@ executables: []
|
|
46
55
|
extensions: []
|
47
56
|
|
48
57
|
extra_rdoc_files:
|
49
|
-
- README.
|
58
|
+
- README.rdoc
|
50
59
|
- LICENSE
|
51
|
-
- TODO
|
52
60
|
files:
|
53
61
|
- LICENSE
|
54
|
-
- README.
|
62
|
+
- README.rdoc
|
55
63
|
- Rakefile
|
56
64
|
- TODO
|
57
65
|
- merb-recaptcha.gemspec
|
58
|
-
- lib/merb-recaptcha.rb
|
59
|
-
- lib/merb-recaptcha/exceptions.rb
|
60
|
-
- lib/merb-recaptcha/view_helpers.rb
|
61
|
-
- lib/merb-recaptcha/controller_mixin.rb
|
66
|
+
- lib/merb-recaptcha/constants.rb
|
62
67
|
- lib/merb-recaptcha/merbtasks.rb
|
68
|
+
- lib/merb-recaptcha/controller_mixin.rb
|
69
|
+
- lib/merb-recaptcha/view_helpers.rb
|
70
|
+
- lib/merb-recaptcha/exceptions.rb
|
71
|
+
- lib/merb-recaptcha.rb
|
63
72
|
- spec/spec_helper.rb
|
64
|
-
- spec/
|
73
|
+
- spec/recaptcha_noajax_without_noscript_spec.rb
|
65
74
|
- spec/recaptcha_noajax_with_noscript_spec.rb
|
66
|
-
- spec/
|
75
|
+
- spec/recaptcha_valid_spec.rb
|
67
76
|
- spec/recaptcha_ajax_spec.rb
|
68
|
-
- spec/
|
77
|
+
- spec/recaptcha_ajax_with_callback_spec.rb
|
69
78
|
- spec/recaptcha_ajax_with_options_spec.rb
|
70
|
-
- spec/
|
71
|
-
- spec/
|
79
|
+
- spec/recaptcha_noajax_with_options_spec.rb
|
80
|
+
- spec/recaptcha_ajax_with_jquery_spec.rb
|
81
|
+
- spec/fixture/app/controllers/application.rb
|
82
|
+
- spec/fixture/app/controllers/exceptions.rb
|
83
|
+
- spec/fixture/app/controllers/recaptcha.rb
|
84
|
+
- spec/fixture/app/views/exceptions/not_acceptable.html.erb
|
85
|
+
- spec/fixture/app/views/exceptions/not_found.html.erb
|
72
86
|
- spec/fixture/app/views/layout/application.html.erb
|
87
|
+
- spec/fixture/app/views/recaptcha/ajax.html.erb
|
73
88
|
- spec/fixture/app/views/recaptcha/ajax_with_callback.html.erb
|
89
|
+
- spec/fixture/app/views/recaptcha/ajax_with_options.html.erb
|
90
|
+
- spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb
|
91
|
+
- spec/fixture/app/views/recaptcha/noajax_with_options.html.erb
|
74
92
|
- spec/fixture/app/views/recaptcha/noajax_with_noscript.html.erb
|
75
|
-
- spec/fixture/app/views/recaptcha/ajax.html.erb
|
76
93
|
- spec/fixture/app/views/recaptcha/ajax_with_jquery.html.erb
|
77
|
-
- spec/fixture/app/views/recaptcha/noajax_with_options.html.erb
|
78
|
-
- spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb
|
79
|
-
- spec/fixture/app/views/recaptcha/ajax_with_options.html.erb
|
80
|
-
- spec/fixture/app/views/exceptions/not_acceptable.html.erb
|
81
|
-
- spec/fixture/app/views/exceptions/not_found.html.erb
|
82
|
-
- spec/fixture/app/controllers/exceptions.rb
|
83
|
-
- spec/fixture/app/controllers/application.rb
|
84
|
-
- spec/fixture/app/controllers/recaptcha.rb
|
85
|
-
- spec/fixture/app/helpers/recaptcha_helpers.rb
|
86
94
|
- spec/fixture/app/helpers/global_helpers.rb
|
95
|
+
- spec/fixture/app/helpers/recaptcha_helpers.rb
|
87
96
|
has_rdoc: true
|
88
97
|
homepage: http://github.com/antage/merb-recaptcha/
|
89
98
|
post_install_message:
|
90
|
-
rdoc_options:
|
91
|
-
|
99
|
+
rdoc_options:
|
100
|
+
- --main
|
101
|
+
- README.rdoc
|
92
102
|
require_paths:
|
93
103
|
- lib
|
94
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -112,26 +122,26 @@ specification_version: 2
|
|
112
122
|
summary: Merb plugin that provides helpers for recaptcha.net service
|
113
123
|
test_files:
|
114
124
|
- spec/spec_helper.rb
|
115
|
-
- spec/
|
125
|
+
- spec/recaptcha_noajax_without_noscript_spec.rb
|
116
126
|
- spec/recaptcha_noajax_with_noscript_spec.rb
|
117
|
-
- spec/
|
127
|
+
- spec/recaptcha_valid_spec.rb
|
118
128
|
- spec/recaptcha_ajax_spec.rb
|
119
|
-
- spec/
|
129
|
+
- spec/recaptcha_ajax_with_callback_spec.rb
|
120
130
|
- spec/recaptcha_ajax_with_options_spec.rb
|
121
|
-
- spec/
|
122
|
-
- spec/
|
131
|
+
- spec/recaptcha_noajax_with_options_spec.rb
|
132
|
+
- spec/recaptcha_ajax_with_jquery_spec.rb
|
133
|
+
- spec/fixture/app/controllers/application.rb
|
134
|
+
- spec/fixture/app/controllers/exceptions.rb
|
135
|
+
- spec/fixture/app/controllers/recaptcha.rb
|
136
|
+
- spec/fixture/app/views/exceptions/not_acceptable.html.erb
|
137
|
+
- spec/fixture/app/views/exceptions/not_found.html.erb
|
123
138
|
- spec/fixture/app/views/layout/application.html.erb
|
139
|
+
- spec/fixture/app/views/recaptcha/ajax.html.erb
|
124
140
|
- spec/fixture/app/views/recaptcha/ajax_with_callback.html.erb
|
141
|
+
- spec/fixture/app/views/recaptcha/ajax_with_options.html.erb
|
142
|
+
- spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb
|
143
|
+
- spec/fixture/app/views/recaptcha/noajax_with_options.html.erb
|
125
144
|
- spec/fixture/app/views/recaptcha/noajax_with_noscript.html.erb
|
126
|
-
- spec/fixture/app/views/recaptcha/ajax.html.erb
|
127
145
|
- spec/fixture/app/views/recaptcha/ajax_with_jquery.html.erb
|
128
|
-
- spec/fixture/app/views/recaptcha/noajax_with_options.html.erb
|
129
|
-
- spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb
|
130
|
-
- spec/fixture/app/views/recaptcha/ajax_with_options.html.erb
|
131
|
-
- spec/fixture/app/views/exceptions/not_acceptable.html.erb
|
132
|
-
- spec/fixture/app/views/exceptions/not_found.html.erb
|
133
|
-
- spec/fixture/app/controllers/exceptions.rb
|
134
|
-
- spec/fixture/app/controllers/application.rb
|
135
|
-
- spec/fixture/app/controllers/recaptcha.rb
|
136
|
-
- spec/fixture/app/helpers/recaptcha_helpers.rb
|
137
146
|
- spec/fixture/app/helpers/global_helpers.rb
|
147
|
+
- spec/fixture/app/helpers/recaptcha_helpers.rb
|
data/README.textile
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
h1. merb-recaptcha
|
2
|
-
|
3
|
-
h2. About
|
4
|
-
|
5
|
-
Merb-recaptcha is plugin for "Merb":http://github.com/wycats/merb web-framework. It provides view and controller helpers for "Recaptcha":http://recaptcha.net service.
|
6
|
-
|
7
|
-
h2. Installation
|
8
|
-
|
9
|
-
Install gem from github.com:
|
10
|
-
<pre><code>gem install antage-merb-recaptcha --source=http://gems.github.com</code></pre>
|
11
|
-
|
12
|
-
Add following line in <tt>config/dependencies.rb</tt> of your web application:
|
13
|
-
<pre><code>dependency "antage-merb-recaptcha", "~> 1.0.0", :require_as => "merb-recaptcha"</code></pre>
|
14
|
-
|
15
|
-
Sign up at "Recaptcha":http://recaptcha.net and get public and private keys. Add keys in <tt>config/init.rb</tt>:
|
16
|
-
<pre><code>Merb::BootLoader.after_app_loads do
|
17
|
-
Merb::Plugins.config[:merb_recaptcha][:public_key] = "... here your public key ..."
|
18
|
-
Merb::Plugins.config[:merb_recaptcha][:private_key] = "... here your private key ..."
|
19
|
-
end</code></pre>
|
20
|
-
|
21
|
-
h2. Usage
|
22
|
-
|
23
|
-
Just add helper in your form:
|
24
|
-
<pre><code><%= form_for @users, :action => resource(:users), :method => :post do %>
|
25
|
-
.....
|
26
|
-
<%= recaptcha_tags %>
|
27
|
-
<%= submit "Send" %>
|
28
|
-
<% end %></code></pre>
|
29
|
-
|
30
|
-
And then check captcha in controller:
|
31
|
-
<pre><code>class Users < Application
|
32
|
-
......
|
33
|
-
def create(user)
|
34
|
-
@user = User.new(user)
|
35
|
-
if (captcha_correct = recaptcha_valid?) && @user.save
|
36
|
-
redirect resource(@user)
|
37
|
-
else
|
38
|
-
unless captcha_correct
|
39
|
-
@user.valid?
|
40
|
-
@user.errors.add(:general, "Captcha code is incorrect")
|
41
|
-
end
|
42
|
-
render :new
|
43
|
-
end
|
44
|
-
......
|
45
|
-
end</code></pre>
|