Class: StandardId::Web::SessionManager
- Inherits:
-
Object
- Object
- StandardId::Web::SessionManager
- Defined in:
- lib/standard_id/web/session_manager.rb
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#token_manager ⇒ Object
readonly
Returns the value of attribute token_manager.
Instance Method Summary collapse
- #clear_session! ⇒ Object
- #current_account ⇒ Object
- #current_session ⇒ Object
-
#initialize(token_manager, request:, session:, cookies:) ⇒ SessionManager
constructor
A new instance of SessionManager.
- #revoke_current_session! ⇒ Object
- #set_remember_cookie(password_credential) ⇒ Object
- #sign_in_account(account) ⇒ Object
Constructor Details
#initialize(token_manager, request:, session:, cookies:) ⇒ SessionManager
Returns a new instance of SessionManager.
6 7 8 9 10 11 |
# File 'lib/standard_id/web/session_manager.rb', line 6 def initialize(token_manager, request:, session:, cookies:) @token_manager = token_manager @request = request @session = session @cookies = end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
4 5 6 |
# File 'lib/standard_id/web/session_manager.rb', line 4 def @cookies end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
4 5 6 |
# File 'lib/standard_id/web/session_manager.rb', line 4 def request @request end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
4 5 6 |
# File 'lib/standard_id/web/session_manager.rb', line 4 def session @session end |
#token_manager ⇒ Object (readonly)
Returns the value of attribute token_manager.
4 5 6 |
# File 'lib/standard_id/web/session_manager.rb', line 4 def token_manager @token_manager end |
Instance Method Details
#clear_session! ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/standard_id/web/session_manager.rb', line 42 def clear_session! # TODO: make token key names configurable session.delete(:session_token) .encrypted[:session_token] = nil .delete(:remember_token) Current.session = nil end |
#current_account ⇒ Object
17 18 19 |
# File 'lib/standard_id/web/session_manager.rb', line 17 def current_account Current.account ||= current_session&.account&.tap { |a| a.strict_loading!(false) } end |
#current_session ⇒ Object
13 14 15 |
# File 'lib/standard_id/web/session_manager.rb', line 13 def current_session Current.session ||= load_current_session end |
#revoke_current_session! ⇒ Object
33 34 35 36 |
# File 'lib/standard_id/web/session_manager.rb', line 33 def revoke_current_session! current_session&.revoke! clear_session! end |
#set_remember_cookie(password_credential) ⇒ Object
38 39 40 |
# File 'lib/standard_id/web/session_manager.rb', line 38 def (password_credential) [:remember_token] = token_manager.create_remember_token(password_credential) end |
#sign_in_account(account) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/standard_id/web/session_manager.rb', line 21 def sign_in_account(account) emit_session_creating(account, "browser") token_manager.create_browser_session(account).tap do |browser_session| # Store in both session and encrypted cookie for backward compatibility # Action Cable will use the encrypted cookie session[:session_token] = browser_session.token .encrypted[:session_token] = browser_session.token Current.session = browser_session emit_session_created(browser_session, account, "browser") end end |