pretender 0.0.2 → 0.0.3

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.
data/README.md CHANGED
@@ -59,7 +59,7 @@ current_user
59
59
 
60
60
  Now we need to setup a way to login as another user. **Pretender makes no assumptions about how you want to do this**. I like to add this to my admin dashboard.
61
61
 
62
- #### Sample Implementation
62
+ ### Sample Implementation
63
63
 
64
64
  ```ruby
65
65
  class Admin::UsersController < ApplicationController
@@ -80,9 +80,24 @@ class Admin::UsersController < ApplicationController
80
80
  end
81
81
  ```
82
82
 
83
+ ### Very Important!
84
+
85
+ Be sure to call `stop_impersonating_user` before the current user logs out.
86
+
87
+ ```ruby
88
+ class SessionsController < ActionController::Base
89
+ def logout
90
+ # it's safe to call this regardless of whether the user is being impersonated
91
+ stop_impersonating_user
92
+ # now, log out the user
93
+ # ...
94
+ end
95
+ end
96
+ ```
97
+
83
98
  You may want to make it obvious to an admin when he / she is logged in as another user. I like to add this to the application layout.
84
99
 
85
- #### Haml / Slim
100
+ ### Haml / Slim
86
101
 
87
102
  ```haml
88
103
  - # app/views/layouts/application.haml
@@ -17,7 +17,10 @@ module Pretender
17
17
  if !instance_variable_get(impersonated_var)
18
18
  # only fetch impersonation if user is logged in and impersonation_id exists
19
19
  true_resource = send(true_method)
20
- value = (true_resource && session[session_key] && impersonate_with.call(session[session_key])) || true_resource
20
+ if session[session_key] and !true_resource
21
+ raise "Security warning: Be sure to call stop_impersonating_#{scope} before logging out"
22
+ end
23
+ value = (session[session_key] && impersonate_with.call(session[session_key])) || true_resource
21
24
  instance_variable_set(impersonated_var, value) if value
22
25
  end
23
26
  instance_variable_get(impersonated_var)
@@ -1,3 +1,3 @@
1
1
  module Pretender
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pretender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -73,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  segments:
75
75
  - 0
76
- hash: -122711431740665312
76
+ hash: 1172062548524424326
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  segments:
84
84
  - 0
85
- hash: -122711431740665312
85
+ hash: 1172062548524424326
86
86
  requirements: []
87
87
  rubyforge_project:
88
88
  rubygems_version: 1.8.23