Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/templates/html_controllers/application_controller.rb,
lib/templates/json_controllers/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#current_userObject



6
7
8
# File 'lib/templates/html_controllers/application_controller.rb', line 6

def current_user
  @current_user ||= User.find_by(session_token: session[:session_token])
end

#logged_in?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/templates/html_controllers/application_controller.rb', line 20

def logged_in?
  !!current_user
end

#login!(user) ⇒ Object



10
11
12
13
# File 'lib/templates/html_controllers/application_controller.rb', line 10

def login!(user)
  @current_user = user
  session[:session_token] = user.reset_session_token!
end

#logout!Object



15
16
17
18
# File 'lib/templates/html_controllers/application_controller.rb', line 15

def logout!
  current_user.reset_session_token!
  session[:session_token] = nil
end