Class: TechlahomaAuth::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/techlahoma_auth/application_controller.rb

Direct Known Subclasses

UserSessionsController

Instance Method Summary collapse

Instance Method Details

#auth_redirectObject



30
31
32
# File 'app/controllers/techlahoma_auth/application_controller.rb', line 30

def auth_redirect
  observable_redirect_to "/auth/techlahoma?origin=#{request.protocol}#{request.host_with_port}#{request.fullpath}"
end


7
8
9
10
11
# File 'app/controllers/techlahoma_auth/application_controller.rb', line 7

def check_cookie
  if !cookie_valid?
    session[:user_id] = nil
  end
end

Returns:

  • (Boolean)


13
14
15
# File 'app/controllers/techlahoma_auth/application_controller.rb', line 13

def cookie_valid?
  cookies[:techlahoma_auth].present? && session[:user_id].present? && cookies[:techlahoma_auth].to_s == session[:user_id].to_s
end

#current_userObject



34
35
36
37
# File 'app/controllers/techlahoma_auth/application_controller.rb', line 34

def current_user
  return nil unless session[:user_id]
  @current_user ||= User.find_by_id(session[:user_id])
end

#login_requiredObject



17
18
19
20
21
# File 'app/controllers/techlahoma_auth/application_controller.rb', line 17

def 
  if !current_user
    not_authorized
  end
end

#not_authorizedObject



23
24
25
26
27
28
# File 'app/controllers/techlahoma_auth/application_controller.rb', line 23

def not_authorized
  respond_to do |format|
    format.html{ auth_redirect }
    format.json{ head :unauthorized }
  end
end

#signed_in?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/controllers/techlahoma_auth/application_controller.rb', line 39

def signed_in?
  current_user.present?
end