Class: OpenStax::Accounts::CurrentUserManager
- Inherits:
-
Object
- Object
- OpenStax::Accounts::CurrentUserManager
- Defined in:
- lib/openstax/accounts/current_user_manager.rb
Instance Method Summary collapse
-
#current_account ⇒ Object
Returns the current account.
-
#current_user ⇒ Object
Returns the current user.
-
#initialize(request, session, cookies) ⇒ CurrentUserManager
constructor
A new instance of CurrentUserManager.
-
#sign_in!(user) ⇒ Object
(also: #sign_in)
Signs in the given user or account.
-
#sign_out! ⇒ Object
(also: #sign_out)
Signs out the currently signed in user.
-
#signed_in? ⇒ Boolean
Returns true iff there is a user signed in.
Constructor Details
#initialize(request, session, cookies) ⇒ CurrentUserManager
Returns a new instance of CurrentUserManager.
4 5 6 7 8 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 4 def initialize(request, session, ) @request = request @session = session @cookies = end |
Instance Method Details
#current_account ⇒ Object
Returns the current account
11 12 13 14 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 11 def current_account load_session @current_account end |
#current_user ⇒ Object
Returns the current user
17 18 19 20 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 17 def current_user load_session @current_user end |
#sign_in!(user) ⇒ Object Also known as: sign_in
Signs in the given user or account
23 24 25 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 23 def sign_in!(user) user.is_a?(Account) ? self.current_account = user : self.current_user = user end |
#sign_out! ⇒ Object Also known as: sign_out
Signs out the currently signed in user
30 31 32 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 30 def sign_out! self.current_account = AnonymousAccount.instance end |
#signed_in? ⇒ Boolean
Returns true iff there is a user signed in
37 38 39 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 37 def signed_in? !current_account.is_anonymous? end |