wechat-validator 0.3.1 → 0.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 544b1d0748f4dd1814c1000a2f6bba67eb75d395
4
- data.tar.gz: c29c808358598ca9d7edc6e9062b530a22b50337
3
+ metadata.gz: 9e9283ec864182a64ebcfdb830e867177d1544f1
4
+ data.tar.gz: 4189ecacf67257f45c2b4622fef9515800bdb408
5
5
  SHA512:
6
- metadata.gz: 405b0d2eab7d21cf3434b1770ccef44bdfe1c3e950834d198cafd473189a233442dbffe05332070c8f0d46e844f7977c8a3d5368c41374ef2896f49a93a03438
7
- data.tar.gz: 6a5aa6da41e11bb1f2f7659c9c08949cfa3215ee87bfc594e82541dc1a0ea8e3fe2d71dfe2d30940da5a098f1e51ab6554ea75d4310a470f4566568f024abca7
6
+ metadata.gz: 58119aca68cebfdc5c9e1ef7ab238c05a59b40caccfa18bb1daaa3c99e2179143957c437c82700e80a5b33a392bf27c7616e8ab398dbf40f22b0626dad14ea8a
7
+ data.tar.gz: 044a8aa4563581fee9227e1ae2ad5cadb0a319143c38bb9ccffb35f8c32bc947ad833ddbcdb65f12df814acb6a7c72fd1c54379518283dd54f1886f982ef1087
data/README.md CHANGED
@@ -1,16 +1,25 @@
1
1
  # Wechat Validator 微信服务器验证器引擎
2
2
 
3
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/wechat-validator/frames)
3
4
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
5
+
4
6
  [![Gem Version](https://badge.fury.io/rb/wechat-validator.svg)](https://badge.fury.io/rb/wechat-validator)
7
+ [![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/wechat-validator.svg)](https://gemnasium.com/github.com/topbitdu/wechat-validator)
5
8
 
6
9
  The Wechat Server Validator Engine is an engine which handles the Wechat server validation requests.
7
10
  微信服务器验证引擎是一个处理[微信服务器验证](http://mp.weixin.qq.com/wiki/8/f9a0b8382e0b77d87b3bcc1ce6fbc104.html#.E7.AC.AC.E4.BA.8C.E6.AD.A5.EF.BC.9A.E9.AA.8C.E8.AF.81.E6.9C.8D.E5.8A.A1.E5.99.A8.E5.9C.B0.E5.9D.80.E7.9A.84.E6.9C.89.E6.95.88.E6.80.A7)请求的引擎。
8
11
 
12
+
13
+
9
14
  ## Recent Update
15
+
10
16
  Check out the [Road Map](ROADMAP.md) to find out what's the next.
11
17
  Check out the [Change Log](CHANGELOG.md) to find out what's new.
12
18
 
19
+
20
+
13
21
  ## Usage
22
+
14
23
  In the application's /config/routes.rb file, add the following line:
15
24
  ```ruby
16
25
  mount Wechat::Validator::Engine, at: '/wechat-validator'
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
10
10
  rdoc.rdoc_dir = 'rdoc'
11
11
  rdoc.title = 'Validator'
12
12
  rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
13
+ rdoc.rdoc_files.include('README.md')
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
@@ -20,5 +20,5 @@ load 'rails/tasks/statistics.rake'
20
20
 
21
21
 
22
22
 
23
- Bundler::GemHelper.install_tasks
23
+ require 'bundler/gem_tasks'
24
24
 
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/wechat/validator .js
2
+ //= link_directory ../stylesheets/wechat/validator .css
@@ -5,7 +5,7 @@
5
5
  // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
6
  //
7
7
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
9
  //
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
@@ -6,9 +6,9 @@
6
6
  * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
7
  *
8
8
  * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
- * file per style scope.
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
12
  *
13
13
  *= require_self
14
14
  */
@@ -1,2 +1,6 @@
1
+ ##
2
+ # Application controller 是模块内所有控制器的基类。
3
+
1
4
  class Wechat::Validator::ApplicationController < ActionController::Base
5
+ protect_from_forgery with: :exception
2
6
  end
@@ -1,8 +1,11 @@
1
+ ##
2
+ # Signature Validator 是微信签名验证的领域逻辑关注点。
3
+
1
4
  module Wechat::Validator::Concerns::SignatureValidator
2
5
 
3
6
  extend ActiveSupport::Concern
4
7
 
5
- self.included do |includer|
8
+ included do |includer|
6
9
 
7
10
  def validate_signature(token)
8
11
 
@@ -22,7 +25,7 @@ module Wechat::Validator::Concerns::SignatureValidator
22
25
  return unless validate_parameter 'signature', signature
23
26
  return unless validate_parameter 'echo', echo
24
27
 
25
- actual_signature = Wechat::Validation::Signature.create nonce, timestamp, token # ::Wechat::Validation.sign nonce, timestamp, token
28
+ actual_signature = Wechat::Validation::Signature.create nonce, timestamp, token
26
29
  signature_matched = signature==actual_signature
27
30
  Rails.logger.warn "Actual signature is #{actual_signature}, which #{signature_matched ? 'equals' : 'does not equal'} to the given signature #{signature}."
28
31
 
@@ -45,7 +48,6 @@ module Wechat::Validator::Concerns::SignatureValidator
45
48
  end
46
49
 
47
50
  module ClassMethods
48
- # def method_name do end
49
51
  end
50
52
 
51
53
  end
@@ -1,11 +1,11 @@
1
1
  class Wechat::Validator::ServerValidationsController < ::Wechat::Validator::ApplicationController
2
2
 
3
- include ::Wechat::Validator::Concerns::SignatureChecker
3
+ include ::Wechat::Validator::Concerns::SignatureValidator
4
4
 
5
5
  def index
6
6
 
7
7
  token = Rails.application.secrets.wechat_validation_token
8
- check_signature token
8
+ validate_signature token
9
9
 
10
10
  end
11
11
 
@@ -13,4 +13,4 @@ class Wechat::Validator::ServerValidationsController < ::Wechat::Validator::Appl
13
13
  render text: ''
14
14
  end
15
15
 
16
- end
16
+ end
@@ -0,0 +1,5 @@
1
+ ##
2
+ # Application job 是模块内所有异步任务的基类。
3
+
4
+ class Wechat::Validator::ApplicationJob < ActiveJob::Base
5
+ end
@@ -0,0 +1,7 @@
1
+ ##
2
+ # Application mailer 是模块内所有电子邮件发送类的基类。
3
+
4
+ class Wechat::Validator::ApplicationMailer < ActionMailer::Base
5
+ default from: 'from@example.com'
6
+ layout 'mailer'
7
+ end
@@ -0,0 +1,6 @@
1
+ ##
2
+ # Application record 是模块内所有模型的抽象基类。
3
+
4
+ class Wechat::Validator::ApplicationRecord < ActiveRecord::Base
5
+ self.abstract_class = true
6
+ end
@@ -1,8 +1,8 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Validator</title>
5
- <%= stylesheet_link_tag "validator/application", media: "all" %>
4
+ <title>Wechat Validator</title>
5
+ <%= stylesheet_link_tag "wechat/validator/application", media: "all" %>
6
6
  <%= csrf_meta_tags %>
7
7
  </head>
8
8
  <body>
@@ -3,16 +3,6 @@ module Wechat
3
3
 
4
4
  class Engine < ::Rails::Engine
5
5
 
6
- config.autoload_paths += %W(
7
- #{config.root}/lib
8
- #{config.root}/app/controllers/wechat/validator/concerns
9
- )
10
-
11
- config.eager_load_paths += %W(
12
- #{config.root}/lib
13
- #{config.root}/app/controllers/wechat/validator/concerns
14
- )
15
-
16
6
  isolate_namespace Wechat::Validator
17
7
 
18
8
  end
@@ -1,5 +1,5 @@
1
1
  module Wechat
2
2
  module Validator
3
- VERSION = '0.3.1'.freeze
3
+ VERSION = '0.3.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wechat-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: wechat-validation
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.2'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.2.1
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - ">="
41
+ - - "~>"
39
42
  - !ruby/object:Gem::Version
40
43
  version: '0.2'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.1
41
47
  description: The Wechat Validator engine handles the Wechat server validation requests.
42
48
  微信验证器引擎处理微信服务器的验证请求。
43
49
  email:
@@ -49,13 +55,16 @@ files:
49
55
  - MIT-LICENSE
50
56
  - README.md
51
57
  - Rakefile
58
+ - app/assets/config/wechat-validator_manifest.js
52
59
  - app/assets/javascripts/wechat/validator/application.js
53
60
  - app/assets/stylesheets/wechat/validator/application.css
54
61
  - app/controllers/wechat/validator/application_controller.rb
55
- - app/controllers/wechat/validator/concerns/signature_checker.rb
56
62
  - app/controllers/wechat/validator/concerns/signature_validator.rb
57
63
  - app/controllers/wechat/validator/server_validations_controller.rb
58
64
  - app/helpers/wechat/validator/application_helper.rb
65
+ - app/jobs/wechat/validator/application_job.rb
66
+ - app/mailers/wechat/validator/application_mailer.rb
67
+ - app/models/wechat/validator/application_record.rb
59
68
  - app/views/layouts/wechat/validator/application.html.erb
60
69
  - config/routes.rb
61
70
  - lib/tasks/validator_tasks.rake
@@ -1,62 +0,0 @@
1
- module Wechat
2
- module Validator
3
- module Concerns
4
-
5
- module SignatureChecker
6
-
7
- extend ActiveSupport::Concern
8
-
9
- self.included do |includer|
10
-
11
- def check_signature(token)
12
-
13
- if token.blank?
14
- Rails.logger.warn 'Token is required to validate URL by Wechat.'
15
- render status: :bad_request, text: 'The token parameter is required.'
16
- return
17
- end
18
-
19
- timestamp = params[:timestamp]
20
- nonce = params[:nonce]
21
- signature = params[:signature]
22
- echo = params[:echostr]
23
-
24
- return unless check_parameter 'timestamp', timestamp
25
- return unless check_parameter 'nonce', nonce
26
- return unless check_parameter 'signature', signature
27
- return unless check_parameter 'echo', echo
28
-
29
- actual_signature = ::Wechat::Validation::Signature.create nonce, timestamp, token # ::Wechat::Validation.sign nonce, timestamp, token
30
- signature_matched = signature==actual_signature
31
- Rails.logger.warn "Actual signature is #{actual_signature}, which #{signature_matched ? 'equals' : 'does not equal'} to the given signature #{signature}."
32
-
33
- if signature_matched
34
- render text: echo
35
- else
36
- render status: :bad_request, text: "The signature parameter '#{signature}' and the generated parameter '#{actual_signature}' is not matched."
37
- end
38
-
39
- end
40
-
41
- def check_parameter(name, value)
42
- if value.blank?
43
- Rails.logger.warn "The #{name} parameter is blank. Failed to validate URL by Wechat."
44
- render status: :bad_request, text: "The #{name} parameter is required."
45
- end
46
- value.present?
47
- end
48
-
49
- deprecate check_signature: :'Wechat::Validator::Concerns::SignatureValidator.validate_signature', deprecator: ActiveSupport::Deprecation.new('1.0', 'wechat-validator')
50
- deprecate check_parameter: :'Wechat::Validator::Concerns::SignatureValidator.validate_parameter', deprecator: ActiveSupport::Deprecation.new('1.0', 'wechat-validator')
51
-
52
- end
53
-
54
- module ClassMethods
55
- # def method_name do end
56
- end
57
-
58
- end
59
-
60
- end
61
- end
62
- end