jpoz-sinatra-recaptcha 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +5 -2
- data/Rakefile +52 -0
- data/lib/sinatra/recaptcha.rb +28 -13
- metadata +8 -7
data/README.markdown
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Quick, simple, easy way to implement REcaptcha for Sinatra apps
|
2
2
|
|
3
3
|
## Installation
|
4
|
-
|
5
4
|
gem sources -a http://gems.github.com
|
5
|
+
|
6
6
|
sudo gem install jpoz-sinatra-captcha
|
7
7
|
|
8
8
|
<pre><code>
|
@@ -14,6 +14,7 @@ configure do
|
|
14
14
|
# https://admin.recaptcha.net/accounts/signup/
|
15
15
|
Sinatra::ReCaptcha.public_key = 'your_public_key'
|
16
16
|
Sinatra::ReCaptcha.private_key = 'your_private_key'
|
17
|
+
# to use ssl set Sinatra::ReCaptcha.server = 'https://api-secure.recaptcha.net'
|
17
18
|
end
|
18
19
|
|
19
20
|
|
@@ -30,7 +31,9 @@ __END__
|
|
30
31
|
|
31
32
|
@@ captcha
|
32
33
|
|
33
|
-
%h1 Try
|
34
|
+
%h1 Try ReCaptcha
|
34
35
|
%form{:method=>"post", :action=>"/post"}
|
35
36
|
= recaptcha
|
37
|
+
# you can also use recaptcha(:ajax) to use a pure ajax version
|
36
38
|
%input{:type=>'submit', :value => 'Send'}
|
39
|
+
</code></pre>
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rubygems/specification'
|
4
|
+
require 'date'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
GEM = 'sinatra-recaptcha'
|
8
|
+
GEM_NAME = 'sinatra-recaptcha'
|
9
|
+
GEM_VERSION = '0.0.2'
|
10
|
+
AUTHORS = ['James Pozdena']
|
11
|
+
EMAIL = "jpoz@jpoz.net"
|
12
|
+
HOMEPAGE = "http://github.com/jpoz/sinatra-recaptcha"
|
13
|
+
SUMMARY = "Simple, easy way to implement recaptcha for Sinatra"
|
14
|
+
|
15
|
+
spec = Gem::Specification.new do |s|
|
16
|
+
s.name = GEM
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.summary = SUMMARY
|
21
|
+
s.description = s.summary
|
22
|
+
s.authors = AUTHORS
|
23
|
+
s.email = EMAIL
|
24
|
+
s.homepage = HOMEPAGE
|
25
|
+
s.require_path = 'lib'
|
26
|
+
s.autorequire = GEM
|
27
|
+
s.files = %w(README.markdown Rakefile) + Dir.glob("{lib}/**/*")
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => :spec
|
31
|
+
|
32
|
+
desc "Run specs"
|
33
|
+
Spec::Rake::SpecTask.new do |t|
|
34
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
35
|
+
t.spec_opts = %w(-fs --color)
|
36
|
+
end
|
37
|
+
|
38
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
39
|
+
pkg.gem_spec = spec
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "install the gem locally"
|
43
|
+
task :install => [:package] do
|
44
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "create a gemspec file"
|
48
|
+
task :make_spec do
|
49
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
50
|
+
file.puts spec.to_ruby
|
51
|
+
end
|
52
|
+
end
|
data/lib/sinatra/recaptcha.rb
CHANGED
@@ -11,20 +11,10 @@ module Sinatra
|
|
11
11
|
attr_accessor :public_key, :private_key, :server
|
12
12
|
attr_reader :verify
|
13
13
|
end
|
14
|
-
|
15
|
-
def captcha_pass?
|
16
|
-
session = params[:captcha_session].to_i
|
17
|
-
answer = params[:captcha_answer].gsub(/\W/, '')
|
18
|
-
open("http://captchator.com/captcha/check_answer/#{session}/#{answer}").read.to_i.nonzero? rescue false
|
19
|
-
end
|
20
14
|
|
21
|
-
def recaptcha
|
22
|
-
"
|
23
|
-
|
24
|
-
<script type='text/javascript' >
|
25
|
-
Recaptcha.create('#{Sinatra::ReCaptcha.public_key}', document.getElementById('dynamic_recaptcha') );
|
26
|
-
</script>
|
27
|
-
</div>"
|
15
|
+
def recaptcha(type = :iframe)
|
16
|
+
raise "Recaptcha type: #{type} is not known, please use (:iframe or :ajax)" unless [:iframe, :ajax].include?(type.to_sym)
|
17
|
+
self.send("recaptcha_#{type}")
|
28
18
|
end
|
29
19
|
|
30
20
|
def recaptcha_correct?
|
@@ -41,6 +31,31 @@ module Sinatra
|
|
41
31
|
return true
|
42
32
|
end
|
43
33
|
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def recaptcha_iframe
|
38
|
+
"<script type='text/javascript'
|
39
|
+
src='#{Sinatra::ReCaptcha.server}/challenge?k=#{Sinatra::ReCaptcha.public_key}'>
|
40
|
+
</script>
|
41
|
+
<noscript>
|
42
|
+
<iframe src='#{Sinatra::ReCaptcha.server}/noscript?k=#{Sinatra::ReCaptcha.public_key}'
|
43
|
+
height='300' width='500' frameborder='0'></iframe><br>
|
44
|
+
<textarea name='recaptcha_challenge_field' rows='3' cols='40'>
|
45
|
+
</textarea>
|
46
|
+
<input type='hidden' name='recaptcha_response_field'
|
47
|
+
value='manual_challenge'>
|
48
|
+
</noscript>"
|
49
|
+
end
|
50
|
+
|
51
|
+
def recaptcha_ajax
|
52
|
+
"<div id='recaptcha_div'> </div>
|
53
|
+
<script type='text/javascript' src='#{Sinatra::ReCaptcha.server}/js/recaptcha_ajax.js'></script>
|
54
|
+
<script type='text/javascript' >
|
55
|
+
Recaptcha.create('#{Sinatra::ReCaptcha.public_key}', 'recaptcha_div' );
|
56
|
+
</script>"
|
57
|
+
end
|
58
|
+
|
44
59
|
end
|
45
60
|
|
46
61
|
helpers ReCaptcha
|
metadata
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jpoz-sinatra-recaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Blake Mizerany
|
8
7
|
- James Pozdena
|
9
|
-
autorequire:
|
8
|
+
autorequire: sinatra-recaptcha
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
11
|
|
13
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-11 00:00:00 -07:00
|
14
13
|
default_executable:
|
15
14
|
dependencies: []
|
16
15
|
|
17
16
|
description: Simple, easy way to implement recaptcha for Sinatra
|
18
|
-
email:
|
17
|
+
email: jpoz@jpoz.net
|
19
18
|
executables: []
|
20
19
|
|
21
20
|
extensions: []
|
@@ -24,9 +23,11 @@ extra_rdoc_files: []
|
|
24
23
|
|
25
24
|
files:
|
26
25
|
- README.markdown
|
26
|
+
- Rakefile
|
27
|
+
- lib/sinatra
|
27
28
|
- lib/sinatra/recaptcha.rb
|
28
|
-
has_rdoc:
|
29
|
-
homepage:
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://github.com/jpoz/sinatra-recaptcha
|
30
31
|
post_install_message:
|
31
32
|
rdoc_options: []
|
32
33
|
|