Module: HubriseApp::ApplicationController::SessionMethods

Extended by:
ActiveSupport::Concern
Included in:
HubriseApp::ApplicationController
Defined in:
app/controllers/hubrise_app/application_controller/session_methods.rb

Instance Method Summary collapse

Instance Method Details

#current_userObject



20
21
22
# File 'app/controllers/hubrise_app/application_controller/session_methods.rb', line 20

def current_user
  @current_user ||= User.where(id: session[:user_id]).take
end

#ensure_authenticated!Object



28
29
30
31
32
33
34
35
# File 'app/controllers/hubrise_app/application_controller/session_methods.rb', line 28

def ensure_authenticated!
  unless logged_in?
    redirect_to(, allow_other_host: true)
    return
  end

  yield if block_given?
end

#logged_in?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/controllers/hubrise_app/application_controller/session_methods.rb', line 24

def logged_in?
  !!current_user
end

#login(user) ⇒ Object



11
12
13
14
# File 'app/controllers/hubrise_app/application_controller/session_methods.rb', line 11

def (user)
  session[:user_id] = user.id
  @current_user = user
end

#logoutObject



16
17
18
# File 'app/controllers/hubrise_app/application_controller/session_methods.rb', line 16

def logout
  session[:user_id] = nil
end