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.
5 6 7 8 9 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 5 def initialize(request, session, ) @request = request @session = session @cookies = end |
Instance Method Details
#current_account ⇒ Object
Returns the current account
12 13 14 15 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 12 def current_account load_session @current_account end |
#current_user ⇒ Object
Returns the current user
18 19 20 21 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 18 def current_user load_session @current_user end |
#sign_in!(user) ⇒ Object Also known as: sign_in
Signs in the given user or account
24 25 26 27 28 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 24 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
33 34 35 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 33 def sign_out! self.current_account = AnonymousAccount.instance end |
#signed_in? ⇒ Boolean
Returns true iff there is a user signed in
40 41 42 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 40 def signed_in? !current_account.is_anonymous? end |