devise-login-cookie 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/devise-login-cookie.rb +40 -30
- data/lib/devise-login-cookie/version.rb +1 -1
- metadata +3 -3
data/lib/devise-login-cookie.rb
CHANGED
@@ -1,45 +1,55 @@
|
|
1
1
|
module DeviseLoginCookie
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
class Cookie
|
4
|
+
|
5
|
+
def initialize(warden, scope)
|
6
|
+
@scope = scope
|
7
|
+
@warden = warden
|
7
8
|
end
|
8
|
-
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def set(user)
|
11
|
+
require 'ruby-debug'; debugger
|
12
|
+
cookies[cookie_name] = cookie_options.merge(:value => cookie_value(user))
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def unset
|
16
|
+
cookies.delete cookie_name, cookie_options
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
Rails.configuration.session_options.slice(:path, :domain, :secure, :httponly)
|
19
|
-
end
|
19
|
+
private
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def cookies
|
22
|
+
# .cookies provided by Devise in warden_compat.rb
|
23
|
+
# Roughly equivalent to: ActionDispatch::Request.new(env).cookie_jar
|
24
|
+
@warden.cookies
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def cookie_name
|
28
|
+
"login_#{@scope}_token"
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
def cookie_value(user)
|
32
|
+
sign [ user.id, Time.now.to_i ]
|
33
|
+
end
|
34
|
+
|
35
|
+
def cookie_options
|
36
|
+
Rails.configuration.session_options.slice(:path, :domain, :secure, :httponly)
|
37
|
+
end
|
38
|
+
|
39
|
+
def sign(input)
|
40
|
+
require 'signed_json'
|
41
|
+
signer = SignedJson::Signer.new(Rails.configuration.secret_token)
|
42
|
+
signer.encode input
|
43
|
+
end
|
32
44
|
|
33
|
-
def sign(input)
|
34
|
-
require 'signed_json'
|
35
|
-
signer = SignedJson::Signer.new(Rails.configuration.secret_token)
|
36
|
-
signer.encode input
|
37
45
|
end
|
38
46
|
|
39
|
-
|
47
|
+
Warden::Manager.after_set_user do |user, warden, options|
|
48
|
+
Cookie.new(warden, options[:scope]).set(user)
|
49
|
+
end
|
40
50
|
|
41
|
-
|
51
|
+
Warden::Manager.before_logout do |user, warden, options|
|
52
|
+
Cookie.new(warden, options[:scope]).unset
|
53
|
+
end
|
42
54
|
|
43
|
-
Warden::Manager.before_logout do |record, warden, options|
|
44
|
-
DeviseLoginCookie::delete_cookie record, warden, options
|
45
55
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Paul Annesley
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-18 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|