nyargl_recaptcha 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e30087777bff51c696c8818c303374a604bc054
4
+ data.tar.gz: 3e70eaf75fbafb7ccf249251b7bc9b1809cea1bb
5
+ SHA512:
6
+ metadata.gz: 7a5ccd8cafb023f212fca693f7945e7af28adff9a9bc43b3e3a96d1621f4b46a2ba10ef29cc8c7ce2c4bcf2c9fbe3025e4d7ce9959ba81136b7ff2d17468a7d7
7
+ data.tar.gz: a8c0c9a5404acf1260c269ca539711094441d7533e6d3b107d825f183517a4dbca1516828fbd98945e5265c4cdf24821bd68a41e22153544e166c7ec887f7ff4
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 evg2108
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # NyarglRecaptcha
2
+
3
+ NyarglRecaptcha is a simple gem for integration Google reCAPTCHA v2.0 to your projects
4
+
5
+ # installation
6
+
7
+ Add it to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'nyargl_recaptcha'
11
+ ```
12
+
13
+ Run the following command to install it:
14
+
15
+ ```console
16
+ bundle install
17
+ ```
18
+
19
+ and that's all
20
+
21
+ ## Usage
22
+
23
+ 1. NyarglRecaptcha uses Google reCAPTCHA API, and first what you need to do is a go to (https://www.google.com/recaptcha), click button "Get reCAPTCHA" and follow the instructions. As result, you will get public key and private key. NyarglRecaptcha uses `ENV['RECAPTCHA_SITEKEY']` for get public site key, and `ENV['RECAPTCHA_PRIVATE_KEY']` for get private key. You need some way to pass the keys in the server options:
24
+
25
+ ```console
26
+ RECAPTCHA_SITEKEY=<public_key> RECAPTCHA_PRIVATE_KEY=<private_key> rails s
27
+ ```
28
+
29
+ 2. add to your form div block with some identifier, like class or id attributes (by default it's a class **g-recaptcha**):
30
+
31
+ ```erb
32
+ <%= form_tag do %>
33
+ <div class="g-recaptcha"></div>
34
+ <% end %>
35
+ ```
36
+
37
+ 3. add to head section of your html document call the following helper method:
38
+
39
+ ```erb
40
+ <html>
41
+ <head>
42
+ ...
43
+ <%= include_recaptcha_scripts %>
44
+ ...
45
+ </head>
46
+ <body>
47
+ ...
48
+ </body>
49
+ </html>
50
+ ```
51
+
52
+ **Note:** if you want to use div block with non-default identifier, then you must pass suitable css as argument for call `include_recaptcha_scripts`, for example:
53
+
54
+ ```erb
55
+ <%= include_recaptcha_scripts('#my_recaptcha.my_class') %>
56
+ ...
57
+ <%= form_tag do %>
58
+ <div id="my_recaptcha" class="my_class"></div>
59
+ <% end %>
60
+ ```
61
+
62
+ 4. for verifying captcha result, add call `verify_recaptcha` to action form processing in controller:
63
+
64
+ ```ruby
65
+ class MyController < ActionController::Base
66
+ def update
67
+ is_catcha_valid = verify_recaptcha
68
+ end
69
+ end
70
+ ```
71
+
72
+ this method returns `true` if captcha is valid, otherwise it returns `false`
73
+
74
+ ## License
75
+ This project rocks and uses [MIT-LICENSE](/MIT-LICENSE).
@@ -0,0 +1,15 @@
1
+ module NyarglRecaptcha
2
+ module Concerns
3
+ module Checker
4
+ extend ActiveSupport::Concern
5
+
6
+ def verify_recaptcha
7
+ response = Net::HTTP.post_form(URI('https://www.google.com/recaptcha/api/siteverify'),
8
+ { secret: ENV['RECAPTCHA_PRIVATE_KEY'],
9
+ response: params['g-recaptcha-response'],
10
+ remoteip: request.remote_ip })
11
+ JSON.parse(response.body)['success']
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module NyarglRecaptcha
2
+ module ApplicationHelper
3
+ def include_recaptcha_scripts(selector = '.g-recaptcha')
4
+ output = ActiveSupport::SafeBuffer.new
5
+ output << render(partial: 'nyargl_recaptcha/shared/callback.js', locals: { sitekey: ENV['RECAPTCHA_SITEKEY'], selector: selector })
6
+ output << javascript_include_tag('https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ <%= javascript_tag do %>
2
+ var onloadCallback = function () {
3
+ grecaptcha.render(document.querySelector('<%= selector %>'), {
4
+ sitekey: '<%= sitekey %>'
5
+ });
6
+ };
7
+ <%- end %>
@@ -0,0 +1,5 @@
1
+ module NyarglRecaptcha
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace NyarglRecaptcha
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module NyarglRecaptcha
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'nyargl_recaptcha/engine'
2
+
3
+ module NyarglRecaptcha
4
+ ActiveSupport.on_load(:action_controller) do
5
+ include NyarglRecaptcha::Concerns::Checker
6
+ helper NyarglRecaptcha::Engine.helpers
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nyargl_recaptcha
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - evg2108
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionview
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: NyarglRecaptcha is a simple gem for integration Google reCAPTCHA v2.0
56
+ to your projects
57
+ email:
58
+ - evg2108@yandex.ru
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - app/controllers/nyargl_recaptcha/concerns/checker.rb
66
+ - app/helpers/nyargl_recaptcha/application_helper.rb
67
+ - app/views/nyargl_recaptcha/shared/_callback.js.erb
68
+ - lib/nyargl_recaptcha.rb
69
+ - lib/nyargl_recaptcha/engine.rb
70
+ - lib/nyargl_recaptcha/version.rb
71
+ homepage: https://github.com/evg2108
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.5
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: NyarglRecaptcha is a simple gem for integration Google reCAPTCHA v2.0 to
95
+ your projects
96
+ test_files: []