brand_captcha 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +19 -0
- data/README.md +38 -0
- data/bin/brand_captcha +1 -0
- data/brand_captcha.gemspec +17 -0
- data/lib/brand_captcha.rb +40 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NGNhMTRhYzkxZGI3MWVkMzMxNjFlMmRmNWRjOTBjMjkyYzNkNjE5Yw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTZkMjhlNzFmYzQ5Y2ZjNmQ0MTY1NWQxYjNlNjM3N2Y0YWJiYWM3Yw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTJhMjc4YmY5ODU1MTc1NWFkNzVjMmNkNDc2YzI5NjBlNjFiMzg5MjQ2NjUy
|
10
|
+
OWIwYzUwYTgwN2EwZWMzOTNmM2NkZTc5NjFmNzQ2N2JjMGNiOTFjYWRkY2Zl
|
11
|
+
Y2IxZWE3OTQ1ZjA1OTdlY2JiYmNlNjRhMGZhNzdmZmRmYWIwNmY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjNmZGE0YmIwNGI3OTEyM2M0ODZhMDY0YzEzZDMxOTcxN2QxMzFkZTE4ZDVk
|
14
|
+
ZDMxYzhkZWIwOGI4YTAzMjliNmE2NmIwNjQxODcxNTkwN2U2ZWJkNTgxN2Y0
|
15
|
+
ODQ1MDIzY2I4YjY0N2M1MmVjN2MxMTYxODliMGQ5ODgwNjE0MTE=
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Joaquín Vicente
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
brand_captcha
|
2
|
+
=============
|
3
|
+
|
4
|
+
A BrandCAPTCHA library for ruby
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
API to interact with BrandCAPTCHA
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```
|
14
|
+
$ gem install brand_captcha
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```
|
20
|
+
BrandCaptcha.configure do |c|
|
21
|
+
c.public_key = ENV['BRANDCAPTCHA_PUBLIC_KEY']
|
22
|
+
c.private_key = ENV['BRANDCAPTCHA_PRIVATE_KEY']
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
On the view, inside the <form>
|
28
|
+
```
|
29
|
+
<%= BrandCaptcha.widget =>
|
30
|
+
```
|
31
|
+
|
32
|
+
To validate the captcha:
|
33
|
+
```
|
34
|
+
valid = BrandCaptcha.check_answer remote_ip, challenge, response
|
35
|
+
```
|
36
|
+
|
37
|
+
## Acknowledgement
|
38
|
+
Based on [BrandCaptcha plugin](http://www.pontamedia.com/) for WordPress and [reCAPTCHA](http://recaptcha.net)
|
data/bin/brand_captcha
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "brand_captcha"
|
5
|
+
s.version = "0.0.1"
|
6
|
+
s.summary = "A BrandCAPTCHA library"
|
7
|
+
s.description = "A BrandCAPTCHA library"
|
8
|
+
s.authors = ["Joaquín Vicente"]
|
9
|
+
s.email = ["joakin@gmail.com"]
|
10
|
+
s.homepage = "http://www.pontamedia.com/en/brandcaptcha/"
|
11
|
+
s.files = []
|
12
|
+
s.files = Dir["lib/brand_captcha.rb", "README.md", "LICENSE", "brand_captcha.gemspec"]
|
13
|
+
|
14
|
+
s.license = "MIT"
|
15
|
+
s.executables.push("brand_captcha")
|
16
|
+
s.add_development_dependency "cutest", "~> 1"
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class BrandCaptcha
|
4
|
+
Configuration = Struct.new(:public_key, :private_key)
|
5
|
+
|
6
|
+
API_HOST = 'api.pontamedia.net'
|
7
|
+
VERIFY_PATH = '/verify.php'
|
8
|
+
CHALLENGE_PATH = '/challenge.php'
|
9
|
+
|
10
|
+
Error = Class.new(StandardError)
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
self.configuration
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.widget error=nil
|
22
|
+
raise Error.new('To use BrandCaptcha you must get an API Key') if configuration.public_key.to_s.empty?
|
23
|
+
url = '//' + API_HOST + CHALLENGE_PATH
|
24
|
+
error_part = error ? "&error=#{error}" : ""
|
25
|
+
|
26
|
+
"<script type='text/javascript' src='#{url}?k=#{configuration.public_key}#{error_part}'></script>";
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.check_answer remote_ip, challenge, response, extra_params={}
|
30
|
+
raise Error.new('To use BrandCaptcha you must get an API key') if configuration.private_key.to_s.empty?
|
31
|
+
raise Error.new('For security reasons, you must pass the remote ip to BrandCaptcha') if remote_ip.to_s.empty?
|
32
|
+
return false if challenge.to_s.empty? or response.to_s.empty?
|
33
|
+
|
34
|
+
params = { privatekey: configuration.private_key, remoteip: remote_ip, challenge: challenge, response: response }.merge extra_params
|
35
|
+
uri = URI('http://' + API_HOST + VERIFY_PATH)
|
36
|
+
res = Net::HTTP.post_form(uri, params)
|
37
|
+
res.body =~ /true/
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brand_captcha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joaquín Vicente
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cutest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description: A BrandCAPTCHA library
|
28
|
+
email:
|
29
|
+
- joakin@gmail.com
|
30
|
+
executables:
|
31
|
+
- brand_captcha
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- bin/brand_captcha
|
38
|
+
- brand_captcha.gemspec
|
39
|
+
- lib/brand_captcha.rb
|
40
|
+
homepage: http://www.pontamedia.com/en/brandcaptcha/
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.3.0
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: A BrandCAPTCHA library
|
64
|
+
test_files: []
|