authie 1.0.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fae3a28b39351d3fd2d65cceb2fb3c27ae48fc8
4
- data.tar.gz: f495eea593432bacdfb352cf81e22c06a4d51e43
3
+ metadata.gz: a723ac0bdb1ef36ed3084611c603fc5e17d3b65a
4
+ data.tar.gz: ca93a21ef49d797fd9aa69eb97b596a8f3e5bbd6
5
5
  SHA512:
6
- metadata.gz: b4ea09a545f6e32133e3c07fc79a8b2f925dd3ca796146fc1beff04e4863fd7acaa0cdc725a035087f2d6d0616ea18a29afaedaf937846bd7a1b5ff49b9431d7
7
- data.tar.gz: 556e8ae46773fefcd25b11e9e3d0f30c8cd7b71dcc54986f28255ce57f7867e9d984d1237002a9bd7eb6e8b6467ffb846b77acb457dfa091eb3ce73f838f85d0
6
+ metadata.gz: fe7a982ff92db20e736ae166eaefe30398bbd0e5cf2ac863bc1ceef0a4f0d092a1a176cb21b6c06b76aa42d9918eb654f6904bceaa65a1172587d13ac7a6b829
7
+ data.tar.gz: 728eb60de7c26c260c55144d4bed89a8794f57b642daefcd5412c79173f2d93a695364281e4a724cacca3e44355706ece8a919799e08f6ed6d660f8c82f3ecee
@@ -0,0 +1,8 @@
1
+ class AddIndexesToAuthieSessions < ActiveRecord::Migration
2
+ def change
3
+ add_column :authie_sessions, :user_type, :string
4
+ add_index :authie_sessions, :token
5
+ add_index :authie_sessions, :browser_id
6
+ add_index :authie_sessions, :user_id
7
+ end
8
+ end
@@ -10,12 +10,7 @@ module Authie
10
10
  @persistent_session_length || 2.months
11
11
  end
12
12
  attr_writer :persistent_session_length
13
-
14
- def user_model_class_name
15
- @user_model_class_name || 'User'
16
- end
17
- attr_writer :user_model_class_name
18
-
13
+
19
14
  end
20
15
 
21
16
  def self.config
@@ -3,16 +3,25 @@ module Authie
3
3
 
4
4
  def self.included(base)
5
5
  base.helper_method :logged_in?, :current_user, :auth_session
6
- base.before_filter :set_browser_id
6
+ base.before_filter :set_browser_id, :touch_auth_session
7
7
  end
8
8
 
9
9
  private
10
10
 
11
11
  # Set a random browser ID for this browser.
12
- # TODO: check that this is unique before setting it.
13
12
  def set_browser_id
14
- unless cookies[:browser_id]
15
- cookies[:browser_id] = {:value => SecureRandom.uuid, :expires => 20.years.from_now}
13
+ until cookies[:browser_id]
14
+ proposed_browser_id = SecureRandom.uuid
15
+ unless Session.where(:browser_id => proposed_browser_id).exists?
16
+ cookies[:browser_id] = {:value => proposed_browser_id, :expires => 20.years.from_now}
17
+ end
18
+ end
19
+ end
20
+
21
+ # Touch the auth session on each request if logged in
22
+ def touch_auth_session
23
+ if logged_in?
24
+ auth_session.touch!
16
25
  end
17
26
  end
18
27
 
@@ -23,7 +32,7 @@ module Authie
23
32
 
24
33
  # Set the currently logged in user
25
34
  def current_user=(user)
26
- if user.is_a?(Authie.config.user_model_class_name.constantize)
35
+ if user
27
36
  unless logged_in?
28
37
  @auth_session = Session.start(self, :user => user)
29
38
  end
@@ -10,7 +10,7 @@ module Authie
10
10
  self.table_name = "authie_sessions"
11
11
 
12
12
  # Relationships
13
- belongs_to :user, :class_name => Authie.config.user_model_class_name, :foreign_key => 'user_id'
13
+ belongs_to :user, :polymorphic => true
14
14
 
15
15
  # Scopes
16
16
  scope :active, -> { where(:active => true) }
@@ -1,3 +1,3 @@
1
1
  module Authie
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-12 00:00:00.000000000 Z
11
+ date: 2014-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Rails library for storing user sessions in a backend database
14
14
  email:
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - db/migrate/20141012174250_create_authie_sessions.rb
21
+ - db/migrate/20141013115205_add_indexes_to_authie_sessions.rb
21
22
  - lib/authie.rb
22
23
  - lib/authie/config.rb
23
24
  - lib/authie/controller_extension.rb