cloud for api and doemal

This commit is contained in:
Yan
2018-04-11 11:27:05 +06:30
parent 70cd6576b1
commit 04ae741462
5 changed files with 60 additions and 8 deletions

View File

@@ -1,7 +1,8 @@
class Api::ApiController < ActionController::API
include TokenVerification
helper_method :current_token, :current_login_employee, :get_cashier
before_action :lookup_domain
helper_method :current_token, :current_login_employee, :get_cashier
private
#this is base api base controller to need to inherit.
@@ -21,4 +22,32 @@ class Api::ApiController < ActionController::API
def current_login_employee
@employee = Employee.find_by_token_session(current_token)
end
def lookup_domain
if request.subdomain.present? && request.subdomain != "www"
from = request.subdomain.downcase + "." + request.domain.downcase
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
if (!@license.nil?)
logger.info "Location - " + @license.dbhost
ActiveRecord::Base.establish_connection(website_connection(@license))
# authenticate_session_token
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
else8
# reconnect_default_db
logger.info 'License is nil'
# redirect_to root_url(:host => request.domain) + "store_error"
render :json => [{ status: false, message: 'Invalid Access!'}]
end
end
end
def cache_license(url, lookup)
@license = License.new(url, lookup)
if (@license.detail_with_local_cache(lookup) == true)
return @license
else
return nil
end
end
end