Files
sx-fc/app/controllers/application_controller.rb
2017-06-21 10:05:07 +06:30

41 lines
943 B
Ruby

class ApplicationController < ActionController::Base
include LoginVerification
#before_action :check_installation
protect_from_forgery with: :exception
helper_method :current_company,:current_login_employee
#this is base api base controller to need to inherit.
#all token authentication must be done here
#response format must be set to JSON
# rescue_from CanCan::AccessDenied do |exception|
# flash[:warning] = exception.message
# redirect_to root_path
# end
def current_user
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
end
def current_company
begin
return Company.first
rescue
return nil
end
end
def current_login_employee
@employee = Employee.find_by_token_session(session[:session_token])
end
private
def check_installation
if current_company.nil?
redirect_to install_path
end
end
end