Class: OpenStax::Accounts::CurrentUserManager
- Inherits:
-
Object
- Object
- OpenStax::Accounts::CurrentUserManager
- Defined in:
- lib/openstax/accounts/current_user_manager.rb
Instance Method Summary collapse
-
#accounts_current_user ⇒ Object
Returns the current accounts user.
-
#current_user ⇒ Object
Returns the current app user.
- #initialize(request, session, cookies) ⇒ CurrentUserManager constructor
-
#sign_in(user) ⇒ Object
Signs in the given user; the argument can be either an accounts user or an app user.
-
#sign_out! ⇒ Object
Signs out the user.
-
#signed_in? ⇒ Boolean
Returns true iff there is a user signed in.
Constructor Details
#initialize(request, session, cookies) ⇒ CurrentUserManager
References:
http://railscasts.com/episodes/356-dangers-of-session-hijacking
8 9 10 11 12 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 8 def initialize(request, session, ) @request = request @session = session = end |
Instance Method Details
#accounts_current_user ⇒ Object
Returns the current accounts user
39 40 41 42 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 39 def accounts_current_user load_current_users @accounts_current_user end |
#current_user ⇒ Object
Returns the current app user
15 16 17 18 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 15 def current_user load_current_users @app_current_user end |
#sign_in(user) ⇒ Object
Signs in the given user; the argument can be either an accounts user or an app user
22 23 24 25 26 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 22 def sign_in(user) user.is_a?(User) ? self.accounts_current_user = user : self.current_user = user end |
#sign_out! ⇒ Object
Signs out the user
29 30 31 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 29 def sign_out! sign_in(OpenStax::Accounts::User.anonymous) end |
#signed_in? ⇒ Boolean
Returns true iff there is a user signed in
34 35 36 |
# File 'lib/openstax/accounts/current_user_manager.rb', line 34 def signed_in? !accounts_current_user.is_anonymous? end |