authie 1.0.3 → 1.1.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
2
  SHA1:
3
- metadata.gz: 552e0b30c5866a15eec565be0df2a97701d3ecdb
4
- data.tar.gz: c3e542cf860658dbf144cc411fd3c787a1e252c7
3
+ metadata.gz: 39ab496b724091644d8e1818cd7df218a0bfc4c6
4
+ data.tar.gz: 8a2b3c21f0f32168a1d22618d492e88e81fc2845
5
5
  SHA512:
6
- metadata.gz: 9db009386f2f59d6daf7ebe69f6d285c9523e1346dad4429c3156cb5068072020d41d9bfff4a4f56787a247acf21c80d165906dbe7c6f08f8e815915d29b862a
7
- data.tar.gz: 7d08d6723c5623714e55e6845a01013f1b9cc67170fd7411f6a2de6c7a2fcf36ef2c9ed2d805ce373c9b1792bf7f7cf146f8f52ccd8d20e368216693ccd9255d
6
+ metadata.gz: 4089297f7f66a03d4826c189c3e57a04b77c70ed83afd60b9d5c426f3eaa261c1a48e3a70eca7548c1a712055721f1d08ac7f51329cadc661b094d47a6d1cc51
7
+ data.tar.gz: edc387d32a375722abd482d988da48f77f49bc363ecee408cbd5fba26300168ca7d914ef14cb024a32f7184c29210cac39ec4b24548cb62b84e022cb6d9c2c28
@@ -11,7 +11,7 @@ class CreateAuthieSessions < ActiveRecord::Migration
11
11
  t.datetime :last_activity_at
12
12
  t.string :last_activity_ip, :last_activity_path
13
13
  t.string :user_agent
14
- t.timestamps
14
+ t.timestamps :null => true
15
15
  end
16
16
  end
17
17
  end
@@ -5,4 +5,4 @@ class AddIndexesToAuthieSessions < ActiveRecord::Migration
5
5
  add_index :authie_sessions, :browser_id
6
6
  add_index :authie_sessions, :user_id
7
7
  end
8
- end
8
+ end
@@ -2,4 +2,4 @@ class AddParentIdToAuthieSessions < ActiveRecord::Migration
2
2
  def change
3
3
  add_column :authie_sessions, :parent_id, :integer
4
4
  end
5
- end
5
+ end
@@ -1,4 +1,7 @@
1
1
  require 'authie/version'
2
- require 'authie/engine'
3
2
  require 'authie/config'
4
3
  require 'authie/error'
4
+
5
+ if defined?(Rails)
6
+ require 'authie/engine'
7
+ end
@@ -1,18 +1,18 @@
1
1
  module Authie
2
2
  class Config
3
-
3
+
4
4
  def session_inactivity_timeout
5
5
  @session_inactivity_timeout || 12.hours
6
6
  end
7
7
  attr_writer :session_inactivity_timeout
8
-
8
+
9
9
  def persistent_session_length
10
10
  @persistent_session_length || 2.months
11
11
  end
12
12
  attr_writer :persistent_session_length
13
-
13
+
14
14
  end
15
-
15
+
16
16
  def self.config
17
17
  @config ||= Config.new
18
18
  end
@@ -0,0 +1,61 @@
1
+ module Authie
2
+ class ControllerDelegate
3
+
4
+ def initialize(controller)
5
+ @controller = controller
6
+ end
7
+
8
+ # Set a random browser ID for this browser.
9
+ def set_browser_id
10
+ until cookies[:browser_id]
11
+ proposed_browser_id = SecureRandom.uuid
12
+ unless Session.where(:browser_id => proposed_browser_id).exists?
13
+ cookies[:browser_id] = {:value => proposed_browser_id, :expires => 20.years.from_now}
14
+ end
15
+ end
16
+ end
17
+
18
+ # Touch the auth session on each request if logged in
19
+ def touch_auth_session
20
+ if logged_in?
21
+ auth_session.touch!
22
+ end
23
+ end
24
+
25
+ # Return the currently logged in user object
26
+ def current_user
27
+ auth_session.user
28
+ end
29
+
30
+ # Set the currently logged in user
31
+ def current_user=(user)
32
+ if user
33
+ unless logged_in?
34
+ @auth_session = Session.start(@controller, :user => user)
35
+ end
36
+ @current_user = user
37
+ else
38
+ auth_session.destroy if logged_in?
39
+ @current_user = nil
40
+ end
41
+ end
42
+
43
+ # Is anyone currently logged in?
44
+ def logged_in?
45
+ auth_session.is_a?(Session)
46
+ end
47
+
48
+ # Return the currently logged in user session
49
+ def auth_session
50
+ @auth_session ||= Session.get_session(@controller)
51
+ end
52
+
53
+ private
54
+
55
+ # Return cookies for the controller
56
+ def cookies
57
+ @controller.send(:cookies)
58
+ end
59
+
60
+ end
61
+ end
@@ -1,57 +1,42 @@
1
+ require 'authie/controller_delegate'
2
+
1
3
  module Authie
2
4
  module ControllerExtension
3
-
5
+
4
6
  def self.included(base)
5
7
  base.helper_method :logged_in?, :current_user, :auth_session
6
8
  base.before_filter :set_browser_id, :touch_auth_session
7
9
  end
8
-
10
+
9
11
  private
10
-
11
- # Set a random browser ID for this browser.
12
+
13
+ def auth_session_delegate
14
+ @auth_session_delegate ||= Authie::ControllerDelegate.new(self)
15
+ end
16
+
12
17
  def set_browser_id
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
18
+ auth_session_delegate.set_browser_id
19
+ end
20
+
22
21
  def touch_auth_session
23
- if logged_in?
24
- auth_session.touch!
25
- end
22
+ auth_session_delegate.touch_auth_session
26
23
  end
27
-
28
- # Return the currently logged in user object
24
+
29
25
  def current_user
30
- auth_session.user
26
+ auth_session_delegate.current_user
31
27
  end
32
-
33
- # Set the currently logged in user
28
+
34
29
  def current_user=(user)
35
- if user
36
- unless logged_in?
37
- @auth_session = Session.start(self, :user => user)
38
- end
39
- @current_user = user
40
- else
41
- auth_session.destroy if logged_in?
42
- @current_user = nil
43
- end
44
- end
45
-
46
- # Is anyone currently logged in?
30
+ auth_session_delegate.current_user = user
31
+ end
32
+
47
33
  def logged_in?
48
- auth_session.is_a?(Session)
34
+ auth_session_delegate.logged_in?
49
35
  end
50
-
51
- # Return the currently logged in user session
36
+
52
37
  def auth_session
53
- @auth_session ||= Session.get_session(self)
38
+ auth_session_delegate.auth_session
54
39
  end
55
-
40
+
56
41
  end
57
42
  end
@@ -1,21 +1,21 @@
1
1
  module Authie
2
2
  class Engine < ::Rails::Engine
3
-
3
+
4
4
  initializer 'authie.initialize' do |app|
5
5
  config.paths["db/migrate"].expanded.each do |expanded_path|
6
6
  app.config.paths["db/migrate"] << expanded_path
7
7
  end
8
-
8
+
9
9
  ActiveSupport.on_load :active_record do
10
10
  require 'authie/session'
11
11
  end
12
-
12
+
13
13
  ActiveSupport.on_load :action_controller do
14
14
  require 'authie/controller_extension'
15
15
  include Authie::ControllerExtension
16
16
  end
17
-
17
+
18
18
  end
19
-
19
+
20
20
  end
21
21
  end
@@ -1,9 +1,9 @@
1
1
  # If you're dealing with your authentication in a middleware and you only have
2
2
  # access to your rack environment, this will wrap around rack and make it look
3
3
  # close enough to an ActionController to work with Authie
4
- #
4
+ #
5
5
  # Usage:
6
- #
6
+ #
7
7
  # controller = Authie::RackController.new(@env)
8
8
  # controller.current_user = user
9
9
 
@@ -22,7 +22,7 @@ module Authie
22
22
  @request.cookie_jar
23
23
  end
24
24
 
25
- # Set a random browser ID for this browser.
25
+ # Set a random browser ID for this browser.
26
26
  def set_browser_id
27
27
  until cookies[:browser_id]
28
28
  proposed_browser_id = SecureRandom.uuid
@@ -36,6 +36,7 @@ module Authie
36
36
  # This method should be called each time a user performs an
37
37
  # action while authenticated with this session.
38
38
  def touch!
39
+ self.check_security!
39
40
  self.last_activity_at = Time.now
40
41
  self.last_activity_ip = controller.request.ip
41
42
  self.last_activity_path = controller.request.path
@@ -157,4 +158,4 @@ module Authie
157
158
  end
158
159
 
159
160
  end
160
- end
161
+ end
@@ -1,3 +1,3 @@
1
1
  module Authie
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.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.3
4
+ version: 1.1.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: 2015-02-03 00:00:00.000000000 Z
11
+ date: 2015-02-27 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:
@@ -22,6 +22,7 @@ files:
22
22
  - db/migrate/20150109144120_add_parent_id_to_authie_sessions.rb
23
23
  - lib/authie.rb
24
24
  - lib/authie/config.rb
25
+ - lib/authie/controller_delegate.rb
25
26
  - lib/authie/controller_extension.rb
26
27
  - lib/authie/engine.rb
27
28
  - lib/authie/error.rb