re_captcha 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/re_captcha/application.rb +2 -8
- data/lib/re_captcha/engine.rb +15 -0
- data/lib/re_captcha/{helper.rb → helpers.rb} +1 -1
- data/lib/re_captcha/rails/helpers.rb +21 -0
- data/lib/re_captcha/version.rb +1 -1
- data/lib/re_captcha.rb +5 -1
- data/spec/re_captcha/{helper_spec.rb → helpers_spec.rb} +2 -2
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ca32da95a571dc0176b5e575c2035bc7e1cd129
|
4
|
+
data.tar.gz: ace2e275c19d90ab39beadade6dd26c57a830ef3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 304b18bec79e191ee1eca20cdfd66bd61475f9d30f48f62a6a46fa29a8a6070120042b7c9b04d1cbceb3a3933ceecbd7aab33908ea7c4ec204743abd2119cd43
|
7
|
+
data.tar.gz: 55ec2d825e617b9d32856a954dcc118c14c281dc4e75e96b47a3a6a354fc779092b033c9502e9e5225aee312398afa64d48a98ecaee855e608426e75418f2452
|
@@ -5,13 +5,11 @@ module ReCaptcha
|
|
5
5
|
module Application
|
6
6
|
include API
|
7
7
|
|
8
|
-
def recaptcha_valid?(response, remote_ip: nil
|
8
|
+
def recaptcha_valid?(response, remote_ip: nil)
|
9
9
|
return true if skip_verification?
|
10
10
|
params = generate_verification_params(response, remote_ip)
|
11
11
|
verification = verify_recaptcha(params)
|
12
|
-
|
13
|
-
add_error_on_model(model, message) unless valid
|
14
|
-
valid
|
12
|
+
verification['success']
|
15
13
|
end
|
16
14
|
|
17
15
|
private
|
@@ -27,9 +25,5 @@ module ReCaptcha
|
|
27
25
|
def skip_verification?
|
28
26
|
skipped_env.include? env
|
29
27
|
end
|
30
|
-
|
31
|
-
def add_error_on_model(model, message)
|
32
|
-
model.errors.add :base, message if model && message
|
33
|
-
end
|
34
28
|
end
|
35
29
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 're_captcha/rails/helpers'
|
2
|
+
|
3
|
+
module ReCaptcha
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
initializer 're_captcha.action_controller.helpers' do
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
7
|
+
include ReCaptcha::Rails::Helpers
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
initializer 're_captcha.action_view.helpers' do
|
12
|
+
ApplicationHelper.send(:include, ReCaptcha::Helpers)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ReCaptcha
|
2
|
+
module Rails
|
3
|
+
module Helpers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def recaptcha_valid?(model: nil, message: nil)
|
7
|
+
recaptcha_response = params.fetch(:"g-recaptcha-response", "")
|
8
|
+
remote_ip = request.remote_ip
|
9
|
+
valid = ReCaptcha.client.recaptcha_valid?(recaptcha_response, remote_ip: remote_ip)
|
10
|
+
add_error_on_model(model, message) unless valid
|
11
|
+
valid
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def add_error_on_model(model, message)
|
17
|
+
model.errors.add :base, message if model && message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/re_captcha/version.rb
CHANGED
data/lib/re_captcha.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 're_captcha/configurable'
|
2
2
|
require 're_captcha/client'
|
3
|
-
require 're_captcha/
|
3
|
+
require 're_captcha/helpers'
|
4
4
|
|
5
5
|
module ReCaptcha
|
6
6
|
extend Configurable
|
@@ -13,3 +13,7 @@ module ReCaptcha
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
if defined?(Rails)
|
18
|
+
require 're_captcha/engine'
|
19
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ReCaptcha::
|
4
|
-
let(:dummy_class) { Class.new { include ReCaptcha::
|
3
|
+
describe ReCaptcha::Helpers do
|
4
|
+
let(:dummy_class) { Class.new { include ReCaptcha::Helpers } }
|
5
5
|
|
6
6
|
before(:all) do
|
7
7
|
ReCaptcha.configure do |config|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: re_captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Jeusette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -86,14 +86,16 @@ files:
|
|
86
86
|
- lib/re_captcha/client.rb
|
87
87
|
- lib/re_captcha/configurable.rb
|
88
88
|
- lib/re_captcha/configuration.rb
|
89
|
+
- lib/re_captcha/engine.rb
|
89
90
|
- lib/re_captcha/exceptions.rb
|
90
|
-
- lib/re_captcha/
|
91
|
+
- lib/re_captcha/helpers.rb
|
92
|
+
- lib/re_captcha/rails/helpers.rb
|
91
93
|
- lib/re_captcha/secure_token_builder.rb
|
92
94
|
- lib/re_captcha/version.rb
|
93
95
|
- re_captcha.gemspec
|
94
96
|
- spec/re_captcha/client_spec.rb
|
95
97
|
- spec/re_captcha/configuration_spec.rb
|
96
|
-
- spec/re_captcha/
|
98
|
+
- spec/re_captcha/helpers_spec.rb
|
97
99
|
- spec/re_captcha/secure_token_builder_spec.rb
|
98
100
|
- spec/re_captcha_spec.rb
|
99
101
|
- spec/spec_helper.rb
|
@@ -124,7 +126,7 @@ summary: reCaptcha helpers
|
|
124
126
|
test_files:
|
125
127
|
- spec/re_captcha/client_spec.rb
|
126
128
|
- spec/re_captcha/configuration_spec.rb
|
127
|
-
- spec/re_captcha/
|
129
|
+
- spec/re_captcha/helpers_spec.rb
|
128
130
|
- spec/re_captcha/secure_token_builder_spec.rb
|
129
131
|
- spec/re_captcha_spec.rb
|
130
132
|
- spec/spec_helper.rb
|