cul_omniauth 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/cul/omniauth/authorizing_controller.rb +50 -0
- data/app/controllers/concerns/cul/omniauth/callbacks.rb +6 -0
- data/app/models/concerns/cul/omniauth/abilities.rb +9 -1
- data/app/models/concerns/cul/omniauth/users.rb +1 -1
- data/lib/cul/omniauth/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2f5e75dcb59b3b93419a19e1d32b6cfb0fdf251
|
4
|
+
data.tar.gz: 90baff7e34e64d4e86343977f47389c956b1780d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c73212bcb608d24654e4188575c72925012d9a0a60807e2354acea1a246f9e147995bb47312e4118c6ddba70ec3469d4cc29f76a092eaf89be77d7552ce18589
|
7
|
+
data.tar.gz: c8761a6dfd0805bc324f3e125b98736c6bc49896c020fb4245acc11528a8ab5a512a4f916be827764edc368d4fc51a5f4ceef4dbe92b040eeb45117885812ba8
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Cul::Omniauth::AuthorizingController
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
def store_location
|
5
|
+
session[:return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def redirect_back_or_default(default)
|
9
|
+
redirect_to(session[:return_to] || default)
|
10
|
+
session[:return_to] = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def require_user
|
14
|
+
unless current_user
|
15
|
+
store_location
|
16
|
+
redirect_to_login
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def require_no_user
|
22
|
+
if current_user
|
23
|
+
store_location
|
24
|
+
flash[:notice] = "You must be logged out to access this page"
|
25
|
+
redirect_to root_url
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def authorize_action
|
31
|
+
if can? :"#{controller_name.to_s}##{params[:action].to_s}", Cul::Omniauth::AbilityProxy.new
|
32
|
+
return true
|
33
|
+
else
|
34
|
+
if current_user
|
35
|
+
access_denied
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
store_location
|
40
|
+
redirect_to_login
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
def access_denied(url=nil)
|
45
|
+
flash[:notice] = "You not permitted to access this page"
|
46
|
+
redirect_to url || root_url
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -3,9 +3,16 @@ module Cul::Omniauth::Abilities
|
|
3
3
|
EMPTY = [].freeze
|
4
4
|
def initialize(user, opts={})
|
5
5
|
@user = user || User.new
|
6
|
-
|
6
|
+
if user
|
7
|
+
role_permissions = self.class.config.select {|role,config| user.role? role }
|
8
|
+
else
|
9
|
+
role_permissions = {:'*' => self.class.config.fetch(:*,EMPTY)}
|
10
|
+
end
|
11
|
+
puts role_permissions.inspect
|
12
|
+
role_permissions.each do |role, config|
|
7
13
|
config.fetch(:can,EMPTY).each do |action, conditions|
|
8
14
|
if conditions.blank?
|
15
|
+
puts "can #{action}, :all"
|
9
16
|
can action, :all
|
10
17
|
else
|
11
18
|
can action, Cul::Omniauth::AbilityProxy do |proxy|
|
@@ -45,6 +52,7 @@ module Cul::Omniauth::Abilities
|
|
45
52
|
context.eql? value
|
46
53
|
end
|
47
54
|
def self.in?(context, value)
|
55
|
+
puts "#{context.inspect} #{value}"
|
48
56
|
(Array(value) & Array(context)).size > 0
|
49
57
|
end
|
50
58
|
end
|
data/lib/cul/omniauth/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cul_omniauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- barmintor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- Rakefile
|
106
106
|
- app/assets/javascripts/cul/omniauth/application.js
|
107
107
|
- app/assets/stylesheets/cul/omniauth/application.css
|
108
|
+
- app/controllers/concerns/cul/omniauth/authorizing_controller.rb
|
108
109
|
- app/controllers/concerns/cul/omniauth/callbacks.rb
|
109
110
|
- app/controllers/concerns/cul/omniauth/remote_ip_ability.rb
|
110
111
|
- app/controllers/cul/omniauth/application_controller.rb
|