Files
sx-fc/app/controllers/concerns/login_verification.rb
2018-02-23 15:49:29 +06:30

64 lines
1.3 KiB
Ruby
Executable File

module LoginVerification
extend ActiveSupport::Concern
included do
before_action :authenticate_session_token
helper_method :current_company,:current_login_employee
end
#this is base api base controller to need to inherit.
#all token authentication must be done here
#response format must be set to JSON
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
protected
# Authenticate the user with token based authentication
def authenticate
authenticate_session_token || render_unauthorized
end
def authenticate_session_token
token = session[:session_token]
if (token)
#@current_user = User.find_by(api_key: token)
#Rails.logger.debug "token - " + token.to_s
@user = Employee.authenticate_by_token(token)
if @user
return true
#Maybe log - login?
else
flash[:notice] = 'Invalid Access!'
# return false
end
end
end
def render_unauthorized()
redirect_to root_path
end
private
def check_license
License.check_license_file
end
def check_installation
if current_company.nil?
redirect_to install_path
end
end
end