kf5 0.2.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 +4 -4
- data/.travis.yml +5 -0
- data/CHANGELOG.md +10 -0
- data/README.md +10 -1
- data/kf5.gemspec +1 -0
- data/lib/kf5.rb +4 -14
- data/lib/kf5/configuration.rb +1 -1
- data/lib/kf5/controller_helper.rb +49 -0
- data/lib/kf5/engine.rb +15 -0
- data/lib/kf5/helper.rb +0 -40
- data/lib/kf5/properties.rb +1 -1
- data/lib/kf5/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29dc0e29988f56fa9b40dc51e8c6401d3742bc8e
|
4
|
+
data.tar.gz: 81c05d4b48dfb389319fc2be05b326878004e9ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37b2772be1712255bd61b193f33d95c048f308bcc43bb4a64ce0007b312947bce02cffe6ef58c8adca114453dc72b7c1deb44603727adc0dacff67d6ec93f08f
|
7
|
+
data.tar.gz: b7d2b348205228468bee86c05b7cd0bc7aab4b0c664e70bc98d8b8bcb2222a317444b116d4eee6f4d2b8179c9d516ceb88878bdc4de4f432bcaa50899ce4a0c8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -26,9 +26,11 @@ For rails, create config `config/initializers/kf5.rb`
|
|
26
26
|
KF5.configure do |config|
|
27
27
|
config.key = "your key of KF5 service"
|
28
28
|
config.domain = "your domain of KF5 service"
|
29
|
+
# 1: login for 30 days, 0: login for 30 minutes
|
30
|
+
# config.remember_me = 1
|
29
31
|
|
30
32
|
# if you use devise, it will fetch following information from current_user if exsit
|
31
|
-
# default is :username, this is identification
|
33
|
+
# default is :username, this is identification with email format
|
32
34
|
config.properties.username = :your_username_column
|
33
35
|
|
34
36
|
# default is :name, optional
|
@@ -36,6 +38,9 @@ KF5.configure do |config|
|
|
36
38
|
|
37
39
|
# default is :phone, optional
|
38
40
|
config.properties.phone = :your_phone_column
|
41
|
+
|
42
|
+
# default is :photo, optional
|
43
|
+
config.properties.photo = :your_photo_column
|
39
44
|
end
|
40
45
|
```
|
41
46
|
|
@@ -52,6 +57,10 @@ Or you can assaign arguments manaully
|
|
52
57
|
```ruby
|
53
58
|
redirect_to_kf5 :username => 'username' # others....
|
54
59
|
```
|
60
|
+
Or you do not want to sso
|
61
|
+
```ruby
|
62
|
+
redirect_to_kf5 :sso => false
|
63
|
+
```
|
55
64
|
|
56
65
|
In view, you can use `kf5_tag` to include javascript plugin.
|
57
66
|
```ruby
|
data/kf5.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "actionview"
|
24
25
|
spec.add_development_dependency "rspec"
|
25
26
|
spec.add_development_dependency "rspec-its"
|
26
27
|
end
|
data/lib/kf5.rb
CHANGED
@@ -6,8 +6,12 @@ require "kf5/configuration"
|
|
6
6
|
require "kf5/properties"
|
7
7
|
require "kf5/helper"
|
8
8
|
require "kf5/view_helper"
|
9
|
+
require "kf5/controller_helper"
|
10
|
+
require "kf5/engine"
|
9
11
|
|
10
12
|
module KF5
|
13
|
+
Columns = [:username, :name, :phone, :photo]
|
14
|
+
|
11
15
|
def self.configure(&block)
|
12
16
|
yield configuration
|
13
17
|
end
|
@@ -15,18 +19,4 @@ module KF5
|
|
15
19
|
def self.configuration
|
16
20
|
@configuration ||= Configuration.new
|
17
21
|
end
|
18
|
-
|
19
|
-
if defined?(::Rails::Engine)
|
20
|
-
class Engine < ::Rails::Engine
|
21
|
-
initializer "kf5" do
|
22
|
-
ActiveSupport.on_load :action_controller do
|
23
|
-
include KF5::Helper
|
24
|
-
end
|
25
|
-
ActiveSupport.on_load :action_view do
|
26
|
-
include KF5::ViewHelper
|
27
|
-
end
|
28
|
-
Rails.application.config.assets.precompile += %w( kf5.js )
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
22
|
end
|
data/lib/kf5/configuration.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
module KF5
|
2
|
+
module ControllerHelper
|
3
|
+
def kf5_url(options = {})
|
4
|
+
username = Helper.indifferent_access(options, :username)
|
5
|
+
time = Time.now.to_i
|
6
|
+
token = Digest::MD5.hexdigest "#{username}#{time}#{KF5.configuration.key}"
|
7
|
+
|
8
|
+
params = {
|
9
|
+
:username => username,
|
10
|
+
:time => time,
|
11
|
+
:token => token
|
12
|
+
}
|
13
|
+
options[:rememberMe] = Helper.indifferent_access(options, :remember_me) || KF5.configuration.remember_me
|
14
|
+
options[:rememberMe] = KF5.configuration.remember_me unless
|
15
|
+
[:name, :phone, :return_to, :photo, :rememberMe].each do |key|
|
16
|
+
Helper.copy_if_exist(options, params, key)
|
17
|
+
end
|
18
|
+
|
19
|
+
query = URI.encode_www_form(params)
|
20
|
+
"https://#{KF5.configuration.domain}.kf5.com/user/remote?#{query}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def redirect_to_kf5(options = {})
|
24
|
+
if Helper.indifferent_access(options, :sso) == false
|
25
|
+
redirect_to "https://#{KF5.configuration.domain}.kf5.com/"
|
26
|
+
else
|
27
|
+
redirect_to current_user_kf5_url(options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def current_user_kf5_url(options = {})
|
34
|
+
kf5_url(current_user_kf5_options.merge(options))
|
35
|
+
end
|
36
|
+
|
37
|
+
def current_user_kf5_options
|
38
|
+
options = {}
|
39
|
+
return options unless respond_to? :current_user
|
40
|
+
[:username, :name, :phone, :photo].each { |key|
|
41
|
+
property = KF5.configuration.properties.send(key)
|
42
|
+
next if property.nil? || !current_user.respond_to?(property)
|
43
|
+
value = current_user.send(property)
|
44
|
+
options[key] = value unless value.nil?
|
45
|
+
}
|
46
|
+
options
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/kf5/engine.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
if defined?(::Rails::Engine)
|
2
|
+
module KF5
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
initializer "kf5" do
|
5
|
+
ActiveSupport.on_load :action_controller do
|
6
|
+
include KF5::ControllerHelper
|
7
|
+
end
|
8
|
+
ActiveSupport.on_load :action_view do
|
9
|
+
include KF5::ViewHelper
|
10
|
+
end
|
11
|
+
Rails.application.config.assets.precompile += %w( kf5.js )
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/kf5/helper.rb
CHANGED
@@ -1,45 +1,5 @@
|
|
1
1
|
module KF5
|
2
2
|
module Helper
|
3
|
-
def kf5_url(options)
|
4
|
-
username = Helper.indifferent_access(options, :username)
|
5
|
-
time = Time.now.to_i
|
6
|
-
token = Digest::MD5.hexdigest "#{username}#{time}#{KF5.configuration.key}"
|
7
|
-
|
8
|
-
params = {
|
9
|
-
:username => username,
|
10
|
-
:time => time,
|
11
|
-
:token => token
|
12
|
-
}
|
13
|
-
Helper.copy_if_exist(options, params, :name)
|
14
|
-
Helper.copy_if_exist(options, params, :phone)
|
15
|
-
Helper.copy_if_exist(options, params, :return_to)
|
16
|
-
|
17
|
-
query = URI.encode_www_form(params)
|
18
|
-
"https://#{KF5.configuration.domain}.kf5.com/user/remote?#{query}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def redirect_to_kf5(options = {})
|
22
|
-
redirect_to current_user_kf5_url(options)
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def current_user_kf5_url(options = {})
|
28
|
-
kf5_url(current_user_kf5_options.merge(options))
|
29
|
-
end
|
30
|
-
|
31
|
-
def current_user_kf5_options
|
32
|
-
options = {}
|
33
|
-
return options unless respond_to? :current_user
|
34
|
-
[:username, :name, :phone].each { |key|
|
35
|
-
property = KF5.configuration.properties.send(key)
|
36
|
-
next if property.nil? || !current_user.respond_to?(property)
|
37
|
-
value = current_user.send(property)
|
38
|
-
options[key] = value unless value.nil?
|
39
|
-
}
|
40
|
-
options
|
41
|
-
end
|
42
|
-
|
43
3
|
def self.indifferent_access(hash, key)
|
44
4
|
hash[key.to_s] || hash[key.to_sym]
|
45
5
|
end
|
data/lib/kf5/properties.rb
CHANGED
data/lib/kf5/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kf5
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chen Yi-Cyuan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: actionview
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,7 +92,6 @@ files:
|
|
78
92
|
- ".travis.yml"
|
79
93
|
- CHANGELOG.md
|
80
94
|
- Gemfile
|
81
|
-
- Gemfile.lock
|
82
95
|
- LICENSE.txt
|
83
96
|
- README.md
|
84
97
|
- Rakefile
|
@@ -86,6 +99,8 @@ files:
|
|
86
99
|
- kf5.gemspec
|
87
100
|
- lib/kf5.rb
|
88
101
|
- lib/kf5/configuration.rb
|
102
|
+
- lib/kf5/controller_helper.rb
|
103
|
+
- lib/kf5/engine.rb
|
89
104
|
- lib/kf5/helper.rb
|
90
105
|
- lib/kf5/properties.rb
|
91
106
|
- lib/kf5/version.rb
|