easy_auth 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,7 +40,7 @@ module EasyAuth::Controllers::PasswordReset
40
40
  end
41
41
 
42
42
  def after_successful_password_reset(identity)
43
- session[:session_token] = identity.generate_session_token!
43
+ identity.set_account_session(session)
44
44
  identity.update_attribute(:reset_token, nil)
45
45
  redirect_to after_successful_password_reset_path(identity), :notice => I18n.t('easy_auth.password_reset.update.notice')
46
46
  end
@@ -5,7 +5,7 @@ module EasyAuth::Controllers::Sessions
5
5
 
6
6
  def create
7
7
  if identity = EasyAuth.identity_model.authenticate(params[:identity])
8
- session[:session_token] = identity.generate_session_token!
8
+ identity.set_account_session(session)
9
9
  if identity.remember
10
10
  cookies[:remember_token] = { :value => identity.generate_remember_token!, :expires => identity.remember_time.from_now }
11
11
  end
@@ -7,9 +7,9 @@ module EasyAuth
7
7
  end
8
8
 
9
9
  def current_account
10
- if session[:session_token]
10
+ if session[:session_token] && session[:account_class]
11
11
  begin
12
- @current_account ||= EasyAuth.identity_model.find_by_session_token(session[:session_token]).account
12
+ @current_account ||= session[:account_class].constantize.find_by_session_token(session[:session_token])
13
13
  rescue
14
14
  @current_account = nil
15
15
  session.delete(:session_token)
@@ -29,6 +29,17 @@ module EasyAuth::Models::Account
29
29
  end
30
30
  end
31
31
 
32
+ def generate_session_token!
33
+ token = BCrypt::Password.create("#{id}-session_token-#{DateTime.current}")
34
+ self.update_attribute(:session_token, token)
35
+ self.session_token
36
+ end
37
+
38
+ def set_session(session)
39
+ session[:session_token] = generate_session_token!
40
+ session[:account_class] = self.class.to_s
41
+ end
42
+
32
43
  private
33
44
 
34
45
  def setup_identity
@@ -18,6 +18,10 @@ module EasyAuth::Models::Identity
18
18
  end
19
19
  end
20
20
 
21
+ def set_account_session(session)
22
+ account.set_session(session)
23
+ end
24
+
21
25
  def remember
22
26
  @remember
23
27
  end
@@ -31,11 +35,6 @@ module EasyAuth::Models::Identity
31
35
  self.reset_token
32
36
  end
33
37
 
34
- def generate_session_token!
35
- self.update_attribute(:session_token, _generate_token(:session))
36
- self.session_token
37
- end
38
-
39
38
  def generate_remember_token!
40
39
  self.update_attribute(:remember_token, _generate_token(:remember))
41
40
  self.remember_token
@@ -48,6 +47,6 @@ module EasyAuth::Models::Identity
48
47
  private
49
48
 
50
49
  def _generate_token(type)
51
- BCrypt::Password.create("#{id}-#{type}_token-#{DateTime.current}")
50
+ token = BCrypt::Password.create("#{id}-#{type}_token-#{DateTime.current}")
52
51
  end
53
52
  end
@@ -6,12 +6,11 @@ class CreateIdentities < ActiveRecord::Migration
6
6
  t.string :account_type
7
7
  t.integer :account_id
8
8
  t.string :reset_token
9
- t.string :session_token
10
9
  t.string :remember_token
11
10
  t.timestamps
12
11
  end
13
12
 
14
- [:username, :reset_token, :remember_token, :session_token].each do |column|
13
+ [:username, :reset_token, :remember_token].each do |column|
15
14
  add_index :identities, column
16
15
  end
17
16
  end
@@ -1,3 +1,3 @@
1
1
  module EasyAuth
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Cardarella
9
+ - Dan McClain
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-06-18 00:00:00.000000000 Z
13
+ date: 2012-06-19 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rails
16
- requirement: &70232324597080 !ruby/object:Gem::Requirement
17
+ requirement: &70156579670080 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ~>
@@ -21,10 +22,10 @@ dependencies:
21
22
  version: 3.2.1
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70232324597080
25
+ version_requirements: *70156579670080
25
26
  - !ruby/object:Gem::Dependency
26
27
  name: bcrypt-ruby
27
- requirement: &70232324611280 !ruby/object:Gem::Requirement
28
+ requirement: &70156579667400 !ruby/object:Gem::Requirement
28
29
  none: false
29
30
  requirements:
30
31
  - - ~>
@@ -32,10 +33,10 @@ dependencies:
32
33
  version: 3.0.0
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70232324611280
36
+ version_requirements: *70156579667400
36
37
  - !ruby/object:Gem::Dependency
37
38
  name: sqlite3
38
- requirement: &70232324607420 !ruby/object:Gem::Requirement
39
+ requirement: &70156579516800 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
42
  - - ! '>='
@@ -43,10 +44,10 @@ dependencies:
43
44
  version: '0'
44
45
  type: :development
45
46
  prerelease: false
46
- version_requirements: *70232324607420
47
+ version_requirements: *70156579516800
47
48
  - !ruby/object:Gem::Dependency
48
49
  name: rspec-rails
49
- requirement: &70232324618400 !ruby/object:Gem::Requirement
50
+ requirement: &70156579515800 !ruby/object:Gem::Requirement
50
51
  none: false
51
52
  requirements:
52
53
  - - ! '>='
@@ -54,10 +55,10 @@ dependencies:
54
55
  version: '0'
55
56
  type: :development
56
57
  prerelease: false
57
- version_requirements: *70232324618400
58
+ version_requirements: *70156579515800
58
59
  - !ruby/object:Gem::Dependency
59
60
  name: capybara
60
- requirement: &70232324626620 !ruby/object:Gem::Requirement
61
+ requirement: &70156579515000 !ruby/object:Gem::Requirement
61
62
  none: false
62
63
  requirements:
63
64
  - - ! '>='
@@ -65,10 +66,10 @@ dependencies:
65
66
  version: '0'
66
67
  type: :development
67
68
  prerelease: false
68
- version_requirements: *70232324626620
69
+ version_requirements: *70156579515000
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: capybara-email
71
- requirement: &70232324623920 !ruby/object:Gem::Requirement
72
+ requirement: &70156579514180 !ruby/object:Gem::Requirement
72
73
  none: false
73
74
  requirements:
74
75
  - - ! '>='
@@ -76,10 +77,10 @@ dependencies:
76
77
  version: '0'
77
78
  type: :development
78
79
  prerelease: false
79
- version_requirements: *70232324623920
80
+ version_requirements: *70156579514180
80
81
  - !ruby/object:Gem::Dependency
81
82
  name: valid_attribute
82
- requirement: &70232324632240 !ruby/object:Gem::Requirement
83
+ requirement: &70156579513340 !ruby/object:Gem::Requirement
83
84
  none: false
84
85
  requirements:
85
86
  - - ! '>='
@@ -87,10 +88,10 @@ dependencies:
87
88
  version: '0'
88
89
  type: :development
89
90
  prerelease: false
90
- version_requirements: *70232324632240
91
+ version_requirements: *70156579513340
91
92
  - !ruby/object:Gem::Dependency
92
93
  name: factory_girl_rails
93
- requirement: &70232324638780 !ruby/object:Gem::Requirement
94
+ requirement: &70156579512540 !ruby/object:Gem::Requirement
94
95
  none: false
95
96
  requirements:
96
97
  - - ! '>='
@@ -98,10 +99,10 @@ dependencies:
98
99
  version: '0'
99
100
  type: :development
100
101
  prerelease: false
101
- version_requirements: *70232324638780
102
+ version_requirements: *70156579512540
102
103
  - !ruby/object:Gem::Dependency
103
104
  name: bourne
104
- requirement: &70232324827900 !ruby/object:Gem::Requirement
105
+ requirement: &70156579528620 !ruby/object:Gem::Requirement
105
106
  none: false
106
107
  requirements:
107
108
  - - ! '>='
@@ -109,10 +110,21 @@ dependencies:
109
110
  version: '0'
110
111
  type: :development
111
112
  prerelease: false
112
- version_requirements: *70232324827900
113
+ version_requirements: *70156579528620
114
+ - !ruby/object:Gem::Dependency
115
+ name: launchy
116
+ requirement: &70156579527160 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: *70156579527160
113
125
  - !ruby/object:Gem::Dependency
114
126
  name: debugger
115
- requirement: &70232324835380 !ruby/object:Gem::Requirement
127
+ requirement: &70156579525340 !ruby/object:Gem::Requirement
116
128
  none: false
117
129
  requirements:
118
130
  - - ! '>='
@@ -120,11 +132,12 @@ dependencies:
120
132
  version: '0'
121
133
  type: :development
122
134
  prerelease: false
123
- version_requirements: *70232324835380
135
+ version_requirements: *70156579525340
124
136
  description: EasyAuth
125
137
  email:
126
138
  - brian@dockyard.com
127
139
  - bcardarella@gmail.com
140
+ - rubygems@danmcclain.net
128
141
  executables: []
129
142
  extensions: []
130
143
  extra_rdoc_files: []
@@ -172,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
185
  version: '0'
173
186
  segments:
174
187
  - 0
175
- hash: 908636940412963380
188
+ hash: -1391021110248690404
176
189
  required_rubygems_version: !ruby/object:Gem::Requirement
177
190
  none: false
178
191
  requirements:
@@ -181,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
194
  version: '0'
182
195
  segments:
183
196
  - 0
184
- hash: 908636940412963380
197
+ hash: -1391021110248690404
185
198
  requirements: []
186
199
  rubyforge_project:
187
200
  rubygems_version: 1.8.11