update multi_tenancy/license

This commit is contained in:
Thein Lin Kyaw
2020-01-29 14:20:50 +06:30
parent 0ea212bf65
commit 11ffaa738f
7 changed files with 37 additions and 38 deletions

View File

@@ -2,32 +2,32 @@ module LicenseVerification
extend ActiveSupport::Concern
included do
before_action :lookup_domain
before_action :lookup_domain
end
protected
def lookup_domain
if request.subdomain.present? && request.subdomain != "www"
from = request.subdomain.downcase + "." + request.domain.downcase
protected
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.name
ActiveRecord::Base.establish_connection(website_connection(@license))
# authenticate_session_token
# logger.info "Location - " + @license.name
ActiveRecord::Base.establish_connection(website_connection(@license))
# authenticate_session_token
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
else
# 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
else
end
else
# check for license file
# if check_license
# current_license(ENV["SX_PROVISION_URL"])
# else
# redirect_to activate_path
# end
# end
end
end
@@ -41,27 +41,27 @@ module LicenseVerification
if @user
return true
#Maybe log - login?
else
else
flash[:notice] = 'Invalid Access!'
# return false
end
end
end
def current_license(url)
def current_license(url)
@license = License.new(url)
flag = @license.detail_with_local_file()
if (flag == 0)
flash[:notice] = 'Expired or No License!'
flash[:notice] = 'Expired or No License!'
elsif (flag == 2)
flash[:notice] = 'Expiring! Please, License extend...'
flash[:notice] = 'Expiring! Please, License extend...'
else
Rails.logger.info "License successed"
end
end
def cache_license(url, lookup)
@license = License.new(url, lookup)
def cache_license(url, lookup)
@license = License.new(url, lookup)
if (@license.detail_with_local_cache(lookup) == true)
return @license
@@ -84,4 +84,4 @@ module LicenseVerification
def default_connection
@default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup
end
end
end