authie 3.3.0 → 3.3.1

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
- SHA1:
3
- metadata.gz: 65b0f0b0c1a8a8de1b9bd7759cd06cbcae80eddd
4
- data.tar.gz: 7069b86b31ce68a03bb2070e45c4e290fa862230
2
+ SHA256:
3
+ metadata.gz: 4351fb61c9e32ab9e4719b811ce293391275a3af0dc7d76972fecc4b10e755d8
4
+ data.tar.gz: e7522427a422d28cb6a41e9cd4f932384f3408a4bc13b83e47909377d1cc783e
5
5
  SHA512:
6
- metadata.gz: eba5598c28d8179aa79bc1ebcfe2e0f3c6f924ffe687f3910ec336edb53cfd8577f753dffba2c98f3e012da93adf3fcd9b4de8c8dbaca9a07ffd53face9ded0c
7
- data.tar.gz: 432cade42ac473df975d36c835ae8b22fca02213a62fa1febafafdf60d245f4826af4d116092d0df4b49f899a64cf1099110e359a388899f5c350ee43ed427d6
6
+ metadata.gz: b1f52adcafa68d13fc43c4cd00a374f3f8d0ac83e234973dc862e77a4aab51505c847c528e3bf81576ae473481ecf8b7659acb7944dfc6d4caa8ff972cabe865
7
+ data.tar.gz: ca2f130a5d8b671fce1026e8d7b2e327d2c9e9226768dcb466f69cdddac6dae64d7255eabfa636b97e13af4485062b16a2b0a338b202187c7c38181503b1a526
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,5 @@
1
+ require 'secure_random_string'
2
+
1
3
  module Authie
2
4
  class Session < ActiveRecord::Base
3
5
 
@@ -22,6 +24,7 @@ module Authie
22
24
  # Scopes
23
25
  scope :active, -> { where(:active => true) }
24
26
  scope :asc, -> { order(:last_activity_at => :desc) }
27
+ scope :for_user, -> (user) { where(:user_type => user.class.name, :user_id => user.id) }
25
28
 
26
29
  # Attributes
27
30
  serialize :data, Hash
@@ -39,7 +42,7 @@ module Authie
39
42
  end
40
43
 
41
44
  before_create do
42
- self.temporary_token = SecureRandom.base64(32)
45
+ self.temporary_token = SecureRandomString.new(44)
43
46
  self.token_hash = self.class.hash_token(self.temporary_token)
44
47
  if controller
45
48
  self.user_agent = controller.request.user_agent
@@ -59,6 +62,17 @@ module Authie
59
62
  end
60
63
  end
61
64
 
65
+ # Set the user
66
+ def user=(user)
67
+ if user
68
+ self.user_type = user.class.name
69
+ self.user_id = user.id
70
+ else
71
+ self.user_type = nil
72
+ self.user_id = nil
73
+ end
74
+ end
75
+
62
76
  # This method should be called each time a user performs an
63
77
  # action while authenticated with this session.
64
78
  def touch!
@@ -176,7 +190,7 @@ module Authie
176
190
 
177
191
  # Invalidate all sessions but this one for this user
178
192
  def invalidate_others!
179
- self.class.where("id != ?", self.id).where(:user => self.user).each do |s|
193
+ self.class.where("id != ?", self.id).for_user(self.user).each do |s|
180
194
  s.invalidate!
181
195
  end
182
196
  end
@@ -228,12 +242,12 @@ module Authie
228
242
 
229
243
  # Is this the first session for this session's browser?
230
244
  def first_session_for_browser?
231
- self.class.where("id < ?", self.id).where(:user => self.user, :browser_id => self.browser_id).empty?
245
+ self.class.where("id < ?", self.id).for_user(self.user).where(:browser_id => self.browser_id).empty?
232
246
  end
233
247
 
234
248
  # Is this the first session for the IP?
235
249
  def first_session_for_ip?
236
- self.class.where("id < ?", self.id).where(:user => self.user, :login_ip => self.login_ip).empty?
250
+ self.class.where("id < ?", self.id).for_user(self.user).where(:login_ip => self.login_ip).empty?
237
251
  end
238
252
 
239
253
  # Find a session from the database for the given controller instance.
@@ -262,13 +276,8 @@ module Authie
262
276
  self.active.where(:browser_id => cookies[:browser_id]).each(&:invalidate!)
263
277
  user_object = params.delete(:user)
264
278
 
265
- if user_object.nil?
266
- raise ActiveRecord::RecordInvalid, ':user must be provided when creating a session'
267
- end
268
-
269
279
  session = self.new(params)
270
- session.user_type = user_object.class.to_s
271
- session.user_id = user_object.id
280
+ session.user = user_object
272
281
  session.controller = controller
273
282
  session.browser_id = cookies[:browser_id]
274
283
  session.login_at = Time.now
@@ -1,3 +1,3 @@
1
1
  module Authie
2
- VERSION = '3.3.0'
2
+ VERSION = '3.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authie
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
@@ -30,8 +30,22 @@ cert_chain:
30
30
  3wUJNGnT5XYq+qvTqmjkTSTfdGvZCM63C6bGdN5CAyMokGOOatGqyCMAONolWnfC
31
31
  gm3t2GWWrxY=
32
32
  -----END CERTIFICATE-----
33
- date: 2019-08-27 00:00:00.000000000 Z
34
- dependencies: []
33
+ date: 2019-10-01 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: secure_random_string
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
35
49
  description: A Rails library for storing user sessions in a backend database
36
50
  email:
37
51
  - me@adamcooke.io
@@ -76,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
90
  - !ruby/object:Gem::Version
77
91
  version: '0'
78
92
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.5.2.3
93
+ rubygems_version: 3.0.6
81
94
  signing_key:
82
95
  specification_version: 4
83
96
  summary: A Rails library for storing user sessions in a backend database
metadata.gz.sig CHANGED
Binary file