Module: AsUser::SessionsHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/as_user/sessions_helper.rb
Instance Method Summary collapse
- #current_user ⇒ Object
- #current_user=(user) ⇒ Object
- #current_user?(user) ⇒ Boolean
- #redirect_back_or(default) ⇒ Object
- #sign_in(user) ⇒ Object
- #sign_out ⇒ Object
- #signed_in? ⇒ Boolean
- #store_location ⇒ Object
Instance Method Details
#current_user ⇒ Object
23 24 25 26 |
# File 'app/helpers/as_user/sessions_helper.rb', line 23 def current_user #@current_user ||= User.find_by_remember_token(cookies[:remember_token]) @current_user ||= User.find_by_id(session[:user_id]) if session[:user_id] end |
#current_user=(user) ⇒ Object
19 20 21 |
# File 'app/helpers/as_user/sessions_helper.rb', line 19 def current_user=(user) @current_user = user end |
#current_user?(user) ⇒ Boolean
28 29 30 |
# File 'app/helpers/as_user/sessions_helper.rb', line 28 def current_user?(user) user == current_user end |
#redirect_back_or(default) ⇒ Object
32 33 34 35 |
# File 'app/helpers/as_user/sessions_helper.rb', line 32 def redirect_back_or(default) redirect_to(session[:return_to] || default) session.delete(:return_to) end |
#sign_in(user) ⇒ Object
3 4 5 6 |
# File 'app/helpers/as_user/sessions_helper.rb', line 3 def sign_in(user) session[:user_id] = user.id self.current_user = user end |
#sign_out ⇒ Object
13 14 15 16 17 |
# File 'app/helpers/as_user/sessions_helper.rb', line 13 def sign_out #cookies.delete(:remember_token) session[:user_id] = nil self.current_user = nil end |
#signed_in? ⇒ Boolean
8 9 10 11 |
# File 'app/helpers/as_user/sessions_helper.rb', line 8 def signed_in? #session[:original_url] = request.url !current_user.nil? end |
#store_location ⇒ Object
37 38 39 |
# File 'app/helpers/as_user/sessions_helper.rb', line 37 def store_location session[:return_to] = request.url end |