blogelator 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acad8c4010bf554be6cf98e0e36d9ce1cb0dce26
4
- data.tar.gz: 6b3bba0bd2d7139a4be61651d04868433c83e16d
3
+ metadata.gz: 7df71289e4cc6e46f08ae106d85e09c816c42c6b
4
+ data.tar.gz: 4b681bfd0e777ba2ed89021179cfd20cb636d5a0
5
5
  SHA512:
6
- metadata.gz: b43de5d0f6652facb9fa2c0fe33a07784f9b961a1bf170f5b8d9811ea17bfdf1c221a990ffac9e3ef35de5249aa55d41e471521061f60a17cacf797433110e39
7
- data.tar.gz: 9a5032e3ecdd8247cbce2ccbab196478d0e62b3de81f4722df3380d71d7470ef30cbb7aedead4923845b4352aa5cc7c21a5bac71280e869b8557804488ddfa5e
6
+ metadata.gz: 6b59799baac3caf6722179a6ef3490954c14ff9c2af1e4ef91ff54644b8c75b326b825d7d66bae748fbc48bc6ad4c3cae1265164e0b8528d3007ba3ec7c24f25
7
+ data.tar.gz: 945d64199355dbae5c76198985caf4ded75909d452f81e4df1fd9a278de577f2bc7315990534b17b50021eb595170bf653eb616c533fe1066cbcad32b1caefd4
@@ -2,22 +2,54 @@ module Blogelator
2
2
  module Admin
3
3
  module Auth
4
4
  extend ActiveSupport::Concern
5
-
5
+
6
6
  included do
7
7
  check_authorization
8
8
  rescue_from CanCan::AccessDenied do |exception|
9
- redirect_to main_app.root_url, alert: exception.message
9
+ unauthorized(exception)
10
10
  end
11
11
  end
12
-
12
+
13
13
  def blogelator_current_user
14
14
  respond_to?(:current_user) ? current_user : nil
15
15
  end
16
-
16
+
17
17
  def current_ability
18
18
  @current_ability ||= Blogelator::Ability.new(blogelator_current_user)
19
19
  end
20
-
20
+
21
+ def devise_resource_name
22
+ Blogelator.user_class.underscore.gsub('/', '_')
23
+ end
24
+
25
+ def login_redirect_path
26
+ # Try to use Devise's new session path or use the app's root path
27
+ devise_new_session_path = "new_#{devise_resource_name}_session_path"
28
+ if main_app.respond_to?(devise_new_session_path)
29
+ main_app.send(devise_new_session_path)
30
+ else
31
+ main_app.root_path
32
+ end
33
+ end
34
+
35
+ def redirect_back_or_default(default)
36
+ redirect_to(session["#{devise_resource_name}_return_to"] || default)
37
+ session["#{devise_resource_name}_return_to"] = nil
38
+ end
39
+
40
+ def store_location
41
+ session["#{devise_resource_name}_return_to"] = request.fullpath.gsub('//', '/')
42
+ end
43
+
44
+ def unauthorized(exception)
45
+ if blogelator_current_user
46
+ redirect_to main_app.root_url, alert: exception.message
47
+ else
48
+ store_location
49
+ redirect_to login_redirect_path, alert: exception.message
50
+ end
51
+ end
52
+
21
53
  end
22
54
  end
23
55
  end
@@ -1,3 +1,3 @@
1
1
  module Blogelator
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blogelator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Pattison
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-12 00:00:00.000000000 Z
12
+ date: 2014-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk