easy_login 1.1.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -16
- data/lib/easy_login/permission.rb +35 -0
- data/lib/easy_login/version.rb +1 -1
- data/lib/easy_login.rb +2 -2
- metadata +3 -3
- data/lib/easy_login/redirect.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e00cd84fb0550b1f959fd94e89b221d5b8ae86bd
|
4
|
+
data.tar.gz: c570dcae15f361d3c20809352f027d614f2395f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85626c496515785223794660e051b19e58a1c1a97e3b630683fd1054df7a4e2396cf1c2835ffaf57a2de7025cf210225d64b2fbfb60c193870efcd04218ed57a
|
7
|
+
data.tar.gz: 03f6b8b3ac5394d18157d59e106e0167a1d39c9938acbecf8a2e1e9375bba2e7afc90e6adbcad665440f8149788e70c8fd3670df98b59eea323fae8f0a024f83
|
data/README.md
CHANGED
@@ -47,41 +47,44 @@ Add a config file to `config/redirect_to.yml` as following
|
|
47
47
|
|
48
48
|
```yaml
|
49
49
|
default:
|
50
|
-
|
50
|
+
ope: pass
|
51
|
+
customer: pass
|
52
|
+
unsigned: redirect_to->login_users_path
|
51
53
|
users:
|
52
54
|
login:
|
53
|
-
ope: root_path
|
54
|
-
customer: root_path
|
55
|
+
ope: redirect_to->root_path
|
56
|
+
customer: redirect_to->root_path
|
55
57
|
tools:
|
56
58
|
default:
|
57
|
-
customer:
|
58
|
-
|
59
|
+
customer: raise->Routing Error
|
60
|
+
unsigned: redirect_to->/tools/login
|
59
61
|
login:
|
60
|
-
ope: tools_path
|
61
|
-
customer:
|
62
|
+
ope: redirect_to->tools_path
|
63
|
+
customer: raise->Other Error
|
62
64
|
```
|
63
65
|
|
64
|
-
The basic format for this
|
66
|
+
The basic format for this permission schema is like
|
65
67
|
|
66
68
|
```yaml
|
67
69
|
controller:
|
68
70
|
action:
|
69
|
-
user_role1:
|
70
|
-
user_role2:
|
71
|
-
user_role3:
|
71
|
+
user_role1: pass
|
72
|
+
user_role2: redirect_to->{path}
|
73
|
+
user_role3: raise->{message}
|
72
74
|
```
|
73
75
|
|
74
76
|
The `user_role` if the role attribute of your user model configed in
|
75
77
|
`config/application.rb` or `config/environments/*.rb`
|
76
|
-
`
|
78
|
+
`action` has 3 types
|
77
79
|
|
78
80
|
```
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
otherwise --> means using as absolute url string
|
81
|
+
pass --> run the logic in action normally
|
82
|
+
redirect_to --> redirect to other {path}, {path} also has two types, {xxx_path} means using rails routing method, and {other format} means used as absolute url string
|
83
|
+
raise --> raise a 404 response with {message}
|
83
84
|
```
|
84
85
|
|
86
|
+
If the schema was not defined in controller/action/user_role, the schema in controller/default/user_role will be used, Also, if it was not defined in controller/default/user_role, default/user_role will be used, if still default/user_role could not be found, easylogin will do action same as 'pass'
|
87
|
+
|
85
88
|
*※ If you also want to use in ActionCable in Rails 5*
|
86
89
|
Add following code to `application_cable/connection.rb`
|
87
90
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module EasyLogin
|
2
|
+
class Permission
|
3
|
+
def self.action(controller_ins)
|
4
|
+
url = self.parse controller_ins
|
5
|
+
if url
|
6
|
+
params = url.split ':'
|
7
|
+
return if params[0] == "pass"
|
8
|
+
raise ActionController::RoutingError.new(params[1]) if params[0] == "raise"
|
9
|
+
if params[0] == "redirect_to"
|
10
|
+
params[1] = controller_ins.send params[1] if params[1].end_with? "path"
|
11
|
+
controller_ins.redirect_to params[1]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def self.parse(controller_ins)
|
18
|
+
per = YAML.load_file Rails.root.join "config", "easy_login_permission.yml"
|
19
|
+
controller = controller_ins.params[:controller]
|
20
|
+
action = controller_ins.params[:action]
|
21
|
+
|
22
|
+
default = nil
|
23
|
+
role = controller_ins.signed_in? ? controller_ins.current_user.send(EasyLogin.config.user_role_attr) : 'unsigned'
|
24
|
+
default = per['default'][role] if per['default'] && per['default'][role]
|
25
|
+
|
26
|
+
return default unless per[controller]
|
27
|
+
per = per[controller]
|
28
|
+
default = per['default'][role] if per['default'] && per['default'][role]
|
29
|
+
|
30
|
+
return default unless per[action]
|
31
|
+
per = per[action]
|
32
|
+
return per[role] || default
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/easy_login/version.rb
CHANGED
data/lib/easy_login.rb
CHANGED
@@ -6,7 +6,7 @@ require "easy_login/version"
|
|
6
6
|
require "easy_login/config"
|
7
7
|
require "easy_login/session"
|
8
8
|
require "easy_login/grape_helper"
|
9
|
-
require "easy_login/
|
9
|
+
require "easy_login/permission"
|
10
10
|
|
11
11
|
module EasyLogin
|
12
12
|
def self.helper_method
|
@@ -30,7 +30,7 @@ module EasyLogin
|
|
30
30
|
if base == ApplicationController
|
31
31
|
base.helper_method EasyLogin.helper_method
|
32
32
|
base.send :before_action do |controller|
|
33
|
-
|
33
|
+
Permission.action controller
|
34
34
|
end
|
35
35
|
elsif base == ApplicationCable::Connection
|
36
36
|
base.send :identified_by, :client
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_login
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- goshan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,7 +70,7 @@ files:
|
|
70
70
|
- lib/easy_login.rb
|
71
71
|
- lib/easy_login/config.rb
|
72
72
|
- lib/easy_login/grape_helper.rb
|
73
|
-
- lib/easy_login/
|
73
|
+
- lib/easy_login/permission.rb
|
74
74
|
- lib/easy_login/session.rb
|
75
75
|
- lib/easy_login/version.rb
|
76
76
|
- pkg/easy_login-0.1.0.gem
|
data/lib/easy_login/redirect.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module EasyLogin
|
2
|
-
class Redirect
|
3
|
-
def self.parse(controller_ins)
|
4
|
-
per = YAML.load_file Rails.root.join "config", "redirect_to.yml"
|
5
|
-
controller = controller_ins.params[:controller]
|
6
|
-
action = controller_ins.params[:action]
|
7
|
-
p = per[controller]
|
8
|
-
p = p[action] || p['default'] if p
|
9
|
-
p = per['default'] unless p
|
10
|
-
if controller_ins.signed_in?
|
11
|
-
url = p[controller_ins.current_user.send(EasyLogin.config.user_role_attr)]
|
12
|
-
else
|
13
|
-
url = p['unsign']
|
14
|
-
end
|
15
|
-
if url
|
16
|
-
raise ActionController::RoutingError.new("Routing Error") if url == 404
|
17
|
-
url = controller_ins.send url if url.end_with? "path"
|
18
|
-
return if url == "nil"
|
19
|
-
controller_ins.redirect_to url
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|