Module: Rack::Casual::Controller

Included in:
ActionController::Base
Defined in:
lib/rack/casual/controller.rb

Overview

Mixin module for ActionController

Instance Method Summary collapse

Instance Method Details

#authenticate!Object

Will send a 401 response to the user if user isn’t logged in.



10
11
12
# File 'lib/rack/casual/controller.rb', line 10

def authenticate!
  authenticate_or_request_with_http_token unless logged_in?
end

#current_userObject

Returns the logged in user



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rack/casual/controller.rb', line 20

def current_user
  return @current_user if @current_user
  @current_user = UserFactory.resource.find(session[Casual.session_key])
  
  # If user is not active, unset session
  if UserFactory.user_not_active(@current_user)
    @current_user = nil 
    session[Casual.session_key] = nil
  end
  
  @current_user
end

#logged_in?Boolean

Returns true if user is logged in

Returns:

  • (Boolean)


15
16
17
# File 'lib/rack/casual/controller.rb', line 15

def logged_in?
  !session[Casual.session_key].nil?
end