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.
@@ -1,45 +1,55 @@
1
1
  module DeviseLoginCookie
2
2
 
3
- def success!(resource)
4
- super
5
- if succeeded?
6
- cookies["login_#{scope}_token"] = cookie_values(resource)
3
+ class Cookie
4
+
5
+ def initialize(warden, scope)
6
+ @scope = scope
7
+ @warden = warden
7
8
  end
8
- end
9
9
 
10
- def self.delete_cookie(record, warden, options)
11
- warden.cookies.delete("login_#{options[:scope]}_token", cookie_options)
12
- end
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
- protected
15
+ def unset
16
+ cookies.delete cookie_name, cookie_options
17
+ end
16
18
 
17
- def cookie_options
18
- Rails.configuration.session_options.slice(:path, :domain, :secure, :httponly)
19
- end
19
+ private
20
20
 
21
- def cookie_values(resource)
22
- value = sign [ resource.id, Time.now.to_i ]
23
- cookie_options.merge :value => value
24
- end
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
- def succeeded?
27
- @result == :success
28
- end
27
+ def cookie_name
28
+ "login_#{@scope}_token"
29
+ end
29
30
 
30
- #######
31
- private
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
- end
47
+ Warden::Manager.after_set_user do |user, warden, options|
48
+ Cookie.new(warden, options[:scope]).set(user)
49
+ end
40
50
 
41
- Devise::Strategies::Authenticatable.send :include, DeviseLoginCookie
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
@@ -1,3 +1,3 @@
1
1
  module DeviseLoginCookie
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
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 00:00:00 +11:00
17
+ date: 2010-11-18 00:00:00 +11:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency