gee_test 0.1.0

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: d093e2ff837b1c461368557f8f9f968dc3ac07e3
4
+ data.tar.gz: c7f03d4b96127081573e4fd3610b0f5456213a8a
5
+ SHA512:
6
+ metadata.gz: 604fcbb7fadc61a3a062a52fe63dacb86b7dae65f02b1b2ce79ca032538d3492aea0f945ad360ba4b7e263f7805f3296d828b39cd99d2bdd57c4f57b344add25
7
+ data.tar.gz: 70abd2e3c01e89c06d114270032dafd0d04533bbb2151ebe296f86b44da4f62d718755549190b467c79c642e389d83f442521e9271fcf932e69e6a29a212d2c9
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+ .idea/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+
37
+ *.swo
38
+ *.swp
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gee_test-ruby-sdk.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gee_test (0.1.0)
5
+ activesupport (~> 4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.2.6)
11
+ i18n (~> 0.7)
12
+ json (~> 1.7, >= 1.7.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.3, >= 0.3.4)
15
+ tzinfo (~> 1.1)
16
+ i18n (0.7.0)
17
+ json (1.8.3)
18
+ minitest (5.8.4)
19
+ rake (10.5.0)
20
+ thread_safe (0.3.5)
21
+ tzinfo (1.2.2)
22
+ thread_safe (~> 0.1)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.8)
29
+ gee_test!
30
+ rake (~> 10.0)
31
+
32
+ BUNDLED WITH
33
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 xiajian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # Geetest ruby sdk
2
+
3
+
4
+ Geetest是一个很不错的验证码组件,使用方便,安全性强。可惜没有ruby的sdk。于是顺手写了一个,由于实在太简单,所以没有做成gem,只留下实现和demo自取。
5
+
6
+ ## 安装
7
+
8
+
9
+ ```ruby
10
+ gem 'gee_test'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gee_test
20
+
21
+
22
+ ## Rails 中使用
23
+
24
+ 在 Rails 项目的 initilizer 中,添加 `geetest.rb`:
25
+
26
+ ```
27
+ require 'gee_test'
28
+
29
+ GeeTest.app_id = 'xxx'
30
+ GeeTest.app_key = 'xx'
31
+ ```
32
+
33
+ ## 如何使用demo
34
+
35
+
36
+ ```
37
+ git clone
38
+ cd gt_ruby_sdk/demo
39
+ bundle
40
+ ruby geetest.rb
41
+ access localhost:4567 via your browser
42
+ ```
43
+
44
+ ## 如何在rails项目中使用geetest
45
+
46
+ 将geetest_ruby_sdk.rb拷贝至lib目录
47
+
48
+ ```html
49
+ 在view页面加上
50
+ <script type="text/javascript" src="http://api.geetest.com/get.php?gt=id"></script>
51
+ ```
52
+
53
+ 其中id为geetest的公钥,这是要注册后才能得到的
54
+
55
+
56
+
57
+ ```ruby
58
+ # in your controller action
59
+
60
+ require 'geetest_ruby_sdk'
61
+
62
+ challenge = params[:geetest_challenge] || ''
63
+ validate = params[:geetest_validate] || ''
64
+ seccode = params[:geetest_seccode] || ''
65
+
66
+ # 将私钥传入,要注册的
67
+ sdk = GeetestSDK.new('private key')
68
+ if sdk.validate(challenge, validate, seccode)
69
+ do something
70
+ else
71
+ do something
72
+ end #if
73
+ ```
74
+
75
+ ## 在sinatra项目中使用geetest
76
+
77
+ 将geetest_ruby_sdk.rb拷贝至当前路径
78
+
79
+ ```ruby
80
+ # app.rb
81
+
82
+ require 'sinatra'
83
+ require './geetest_ruby_sdk'
84
+
85
+ get '/' do
86
+ send_file 'login.html'
87
+ end
88
+
89
+ post '/log' do
90
+ challenge = params[:geetest_challenge] || ''
91
+ validate = params[:geetest_validate] || ''
92
+ seccode = params[:geetest_seccode] || ''
93
+
94
+ # 将私钥传入,要注册的
95
+ sdk = GeetestSDK.new('private key')
96
+ if sdk.validate(challenge, validate, seccode)
97
+ 'successfully'
98
+ else
99
+ 'Can not validate'
100
+ end #if
101
+ end
102
+ ```
103
+
104
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gee_test/ruby/sdk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/demo/geetest.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'sinatra'
2
+ require './geetest_ruby_sdk'
3
+
4
+ get '/' do
5
+ send_file 'login.html'
6
+ end
7
+
8
+ post '/log' do
9
+ challenge = params[:geetest_challenge] || ''
10
+ validate = params[:geetest_validate] || ''
11
+ seccode = params[:geetest_seccode] || ''
12
+
13
+ sdk = GeetestSDK.new('0f1a37e33c9ed10dd2e133fe2ae9c459')
14
+ if sdk.validate(challenge, validate, seccode)
15
+ 'successfully'
16
+ else
17
+ 'Can not validate'
18
+ end #if
19
+ end
@@ -0,0 +1,32 @@
1
+ require 'digest'
2
+ require 'net/http'
3
+
4
+ class GeetestSDK
5
+ def initialize(key, new_uri=nil)
6
+ @gee_uri = new_uri || 'http://api.geetest.com/validate.php'
7
+ @key = key
8
+ end
9
+
10
+ def validate(challenge='', validate='', seccode='')
11
+ md5 = Digest::MD5.hexdigest(@key + 'geetest' + challenge)
12
+ if validate == md5
13
+ back = post(@gee_uri, seccode: seccode) rescue ''
14
+ if back == Digest::MD5.hexdigest(seccode)
15
+ return true
16
+ else
17
+ return false
18
+ end #if
19
+ else
20
+ return false
21
+ end #if
22
+ end #geetest_validate
23
+
24
+ # data.is_a?(Hash)==true
25
+ def post(uri, data)
26
+ uri = URI(uri)
27
+ res = Net::HTTP.post_form(uri, data)
28
+ res.body
29
+ end
30
+
31
+ end
32
+
data/demo/login.html ADDED
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
5
+ <title>极验行为式验证 php 类网站安装测试页面</title>
6
+ <style>
7
+ body {
8
+ background-color: #9e9;
9
+ }
10
+ .wrap {
11
+ width: 960px;
12
+ margin: 100px auto;
13
+ font-size: 125%;
14
+ }
15
+ .row {
16
+ margin: 30px 0;
17
+ }
18
+
19
+ </style>
20
+ </head>
21
+ <body>
22
+ <div class="wrap">
23
+ <h1>极验行为式验证 php 类网站安装测试页面</h1>
24
+ <form method="post" action="/log">
25
+ <div class="row">
26
+ <label for="name">邮箱</label>
27
+ <input type="text" id="email" name="email" value="geetest@126.com"/>
28
+ </div>
29
+ <div class="row">
30
+ <label for="passwd">密码</label>
31
+ <input type="password" id="passwd" name="passwd" value="gggggggg"/>
32
+ </div>
33
+ <div class="row">
34
+ <script type="text/javascript" src="http://api.geetest.com/get.php?gt=a40fd3b0d712165c5d13e6f747e948d4"></script>
35
+ </div>
36
+ <div class="row">
37
+ <input type="submit" value="登陆" />
38
+ </div>
39
+ </form>
40
+ </div>
41
+ </body>
42
+ </html>
43
+
data/gee_test.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gee_test/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gee_test"
8
+ spec.version = GeeTest::VERSION
9
+ spec.authors = ["xiajian"]
10
+ spec.email = ["jhqy2011@gmail.com"]
11
+
12
+ spec.summary = %q{GeeTest is Ruby SDK for geetest。 }
13
+ spec.description = %q{GeeTest 就是我将某段 ruby 代码封装成 ruby gem。}
14
+ spec.homepage = "https://github.com/xiajian/gt-ruby-sdk"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency 'activesupport', '~> 4.0'
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.8"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ end
@@ -0,0 +1,11 @@
1
+ module GeeTest
2
+ module Configure
3
+
4
+ mattr_accessor :app_id
5
+
6
+ mattr_accessor :app_key
7
+
8
+ mattr_accessor :validate_url
9
+ self.validate_url = 'http://api.geetest.com/validate.php'
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module GeeTest
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gee_test.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'net/http'
2
+ require 'gee_test/version'
3
+ require 'active_support/core_ext/module/attribute_accessors'
4
+
5
+ module GeeTest
6
+ autoload :Configure, File.expand_path('../gee_test/configure', __FILE__)
7
+
8
+ class << self
9
+ include Configure
10
+
11
+ def validate(params = {})
12
+ challenge = params[:geetest_challenge] || ''
13
+ validate = params[:geetest_validate] || ''
14
+ seccode = params[:geetest_seccode] || ''
15
+
16
+ md5 = Digest::MD5.hexdigest(app_key + 'geetest' + challenge)
17
+
18
+ if validate == md5
19
+ response = post(validate_url, seccode: seccode)
20
+ response == Digest::MD5.hexdigest(seccode)
21
+ end
22
+ rescue => e
23
+ puts "Exception is happened, It is #{e}"
24
+ end
25
+
26
+ def post(uri, data)
27
+ uri = URI(uri)
28
+ res = Net::HTTP.post_form(uri, data)
29
+ res.body
30
+ end
31
+
32
+ def gee_test_tag
33
+ "<script type='text/javascript' src='http://api.geetest.com/get.php?gt=#{app_id}'></script>"
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gee_test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - xiajian
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-01 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: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: GeeTest 就是我将某段 ruby 代码封装成 ruby gem。
56
+ email:
57
+ - jhqy2011@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - demo/geetest.rb
72
+ - demo/geetest_ruby_sdk.rb
73
+ - demo/login.html
74
+ - gee_test.gemspec
75
+ - lib/gee_test.rb
76
+ - lib/gee_test/configure.rb
77
+ - lib/gee_test/version.rb
78
+ homepage: https://github.com/xiajian/gt-ruby-sdk
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: GeeTest is Ruby SDK for geetest。
102
+ test_files: []