Module: Incline::Extensions::Session::Common
- Defined in:
- lib/incline/extensions/session.rb
Overview
Contains the methods common to both controllers and views.
Instance Method Summary collapse
-
#current_user ⇒ Object
Gets the currently logged in user.
-
#current_user?(user) ⇒ Boolean
Is the specified user the current user?.
-
#logged_in? ⇒ Boolean
Is a user logged in?.
-
#system_admin? ⇒ Boolean
Is the current user a system administrator?.
-
#user_id_cookie ⇒ Object
Gets the name of the cookie containing the user ID for the current user.
-
#user_token_cookie ⇒ Object
Gets the name of the cookie containing the remember token for the current user.
Instance Method Details
#current_user ⇒ Object
Gets the currently logged in user.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/incline/extensions/session.rb', line 34 def current_user @current_user ||= if (user_id = session[:user_id]) Incline::User.find_by(id: user_id) elsif (&.respond_to?(:signed)) && (user_id = .signed[]) && (user = Incline::User.find_by(id: user_id)) && (user.authenticated?(:remember, [])) log_in user if respond_to?(:log_in) user else nil end ||Incline::User::anonymous end |
#current_user?(user) ⇒ Boolean
Is the specified user the current user?
51 52 53 |
# File 'lib/incline/extensions/session.rb', line 51 def current_user?(user) current_user == user end |
#logged_in? ⇒ Boolean
Is a user logged in?
57 58 59 |
# File 'lib/incline/extensions/session.rb', line 57 def logged_in? !current_user.anonymous? end |
#system_admin? ⇒ Boolean
Is the current user a system administrator?
63 64 65 |
# File 'lib/incline/extensions/session.rb', line 63 def system_admin? logged_in? && current_user.system_admin? && current_user.enabled? && current_user.activated? end |
#user_id_cookie ⇒ Object
Gets the name of the cookie containing the user ID for the current user.
This gets set when the user selects the “Remember me” checkbox when logging in.
20 21 22 |
# File 'lib/incline/extensions/session.rb', line 20 def @user_id_cookie ||= Rails.application.(:user_id) end |
#user_token_cookie ⇒ Object
Gets the name of the cookie containing the remember token for the current user.
This gets set when the user selects the “Remember me” checkbox when logging in.
28 29 30 |
# File 'lib/incline/extensions/session.rb', line 28 def @user_token_cookie ||= Rails.application.(:user_token) end |