authie 4.0.0.rc2 → 4.0.0.rc5

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
  SHA256:
3
- metadata.gz: d5347676808e3554dde1670a91c8402ed166be59767298dfea961a9020659843
4
- data.tar.gz: 03ee0e9cc60e7ae24a9e83c7a6ead5d72ebec109ef558898395d476014843a65
3
+ metadata.gz: 1d9373c828cdac9b7663eb05db6954ff069f5e6d8164d64c8dcf5fd165ca0d09
4
+ data.tar.gz: c4b98e9bb20edce2539761806affda87fd4d56082b7c9e956842424cac8a6e27
5
5
  SHA512:
6
- metadata.gz: 219676dee96408c5cb85432ab4d919967415b9e575cb9681c4b4a9d210f041213af2a841a63ebdd4c88d9a8d3856f4ab306ddfd5e4947dee6e3d3654de8538b0
7
- data.tar.gz: 7dd321dd2d407fd73b89ea6e1894d60362ac7e4fd792d0d74ea9e2cc5178b30eebd8d42ab3bf7baa356bc3d6f161d6809e0c545d9430d6db3267e8dfbda87190
6
+ metadata.gz: b90a45ff82b29992deec7c2e7c09604a3a569bdfbe099ba2f7be26989c9bd91417b7446d7ea2d8ad0f85f55d42d9ed9356a203dc239e88f568ccf64cb4faa363
7
+ data.tar.gz: 9c66674049a1a8c36389faa84764b296f7879d59b5cdd3c6bc7b06946874ffec6fec23cd1194a0b68367391237814938a1de19db0ef7958af005d7a9ce2d66ef
@@ -36,18 +36,25 @@ module Authie
36
36
  proposed_browser_id
37
37
  end
38
38
 
39
- # Touch the session on each request to ensure that it is validated and all last activity
40
- # information is updated. This will return the session if one has been touched otherwise
41
- # it will reteurn false if there is no session/not logged in. It is safe to run this on
42
- # all requests even if there is no session.
39
+ # Validate the auth session to ensure that it is current validate and raise an error if it
40
+ # is not suitable for use.
43
41
  #
44
42
  # @return [Authie::Session, false]
45
- def touch_auth_session
46
- return auth_session.touch if logged_in?
43
+ def validate_auth_session
44
+ return auth_session.validate if logged_in?
47
45
 
48
46
  false
49
47
  end
50
48
 
49
+ # Touch the session to update details on the latest activity.
50
+ #
51
+ # @return [Authie::Session, false]
52
+ def touch_auth_session
53
+ yield if block_given?
54
+ ensure
55
+ auth_session.touch if logged_in?
56
+ end
57
+
51
58
  # Return the user for the currently logged in user or nil if no user is logged in
52
59
  #
53
60
  # @return [ActiveRecord::Base, nil]
@@ -61,9 +68,9 @@ module Authie
61
68
  # will be invalidated.
62
69
  #
63
70
  # @return [Authie::Session, nil]
64
- def create_auth_session(user)
71
+ def create_auth_session(user, **kwargs)
65
72
  if user
66
- @auth_session = Authie::Session.start(@controller, user: user)
73
+ @auth_session = Authie::Session.start(@controller, user: user, **kwargs)
67
74
  return @auth_session
68
75
  end
69
76
 
@@ -7,9 +7,11 @@ module Authie
7
7
  class << self
8
8
  def included(base)
9
9
  base.helper_method :logged_in?, :current_user, :auth_session
10
- base.before_action :set_browser_id, :touch_auth_session
10
+ base.before_action :set_browser_id, :validate_auth_session
11
+ base.around_action :touch_auth_session
11
12
 
12
13
  base.delegate :set_browser_id, to: :auth_session_delegate
14
+ base.delegate :validate_auth_session, to: :auth_session_delegate
13
15
  base.delegate :touch_auth_session, to: :auth_session_delegate
14
16
  base.delegate :current_user, to: :auth_session_delegate
15
17
  base.delegate :create_auth_session, to: :auth_session_delegate
@@ -88,7 +88,6 @@ module Authie
88
88
  # @raises [ActiveRecord::RecordInvalid]
89
89
  # @return [Authie::Session]
90
90
  def touch
91
- validate
92
91
  @session.last_activity_at = Time.now
93
92
  @session.last_activity_ip = @controller.request.ip
94
93
  @session.last_activity_path = @controller.request.path
@@ -206,20 +205,22 @@ module Authie
206
205
  # Create a new session within the given controller for the
207
206
  #
208
207
  # @param controller [ActionController::Base]
209
- # @option params [ActiveRecord::Base] user
208
+ # @param user [ActiveRecord::Base] user
209
+ # @param persistent [Boolean] create a persistent session
210
210
  # @return [Authie::Session]
211
- def start(controller, params = {})
211
+ def start(controller, user:, persistent: false, see_password: false, **params)
212
212
  cookies = controller.send(:cookies)
213
213
  SessionModel.active.where(browser_id: cookies[:browser_id]).each(&:invalidate!)
214
- user_object = params.delete(:user)
215
214
 
216
215
  session = SessionModel.new(params)
217
- session.user = user_object
216
+ session.user = user
218
217
  session.browser_id = cookies[:browser_id]
219
218
  session.login_at = Time.now
220
219
  session.login_ip = controller.request.ip
221
220
  session.host = controller.request.host
222
221
  session.user_agent = controller.request.user_agent
222
+ session.expires_at = Time.now + Authie.config.persistent_session_length if persistent
223
+ session.password_seen_at = Time.now if see_password
223
224
  session.save!
224
225
 
225
226
  new(controller, session).start
@@ -261,6 +262,7 @@ module Authie
261
262
  delegate :active?, to: :session
262
263
  delegate :browser_id, to: :session
263
264
  delegate :expired?, to: :session
265
+ delegate :expires_at, to: :session
264
266
  delegate :first_session_for_browser?, to: :session
265
267
  delegate :first_session_for_ip?, to: :session
266
268
  delegate :get, to: :session
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: 4.0.0.rc2
4
+ version: 4.0.0.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-29 00:00:00.000000000 Z
11
+ date: 2022-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord