improvement

This commit is contained in:
Myat Zin Wai Maw
2020-02-07 09:31:20 +06:30
parent 0582587f75
commit a645e3348d
8 changed files with 96 additions and 151 deletions

View File

@@ -1,12 +1,12 @@
class ActionController::Base
before_action :lookup_domain if Rails.env.production?
before_action :set_locale
before_action :lookup_domain, :set_locale
private
def lookup_domain
if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_MODE"] == "cloud"
@license = cache_license(ENV["SX_PROVISION_URL"], request.host) # request.subdomain.downcase
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.dbschema
ActiveRecord::Base.establish_connection(website_connection(@license))
@@ -18,34 +18,26 @@ class ActionController::Base
# redirect_to root_url(:host => request.domain) + "store_error"
render :json => [{ status: false, message: 'Invalid Access!'}]
end
elsif request.subdomains.last && request.subdomains.last != "www" || ENV["SERVER_MODE"] == "application"
else
# check for license file
if check_license(request.host)
current_license(ENV["SX_PROVISION_URL"], request.host)
if check_license
current_license(ENV["SX_PROVISION_URL"])
else
redirect_to activate_path
end
else
not_found
end
end
def not_found
respond_to do |format|
format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
format.json { head :not_found }
end
end
def current_license(url, lookup)
@license = License.new(url, lookup)
def current_license(url)
@license = License.new(url)
flag = @license.detail_with_local_file()
if (flag == 0)
flash[:notice] = 'Expired or No License!'
elsif (flag == 2)
flash[:notice] = 'Expiring! Please, License extend...'
else
Rails.logger.info "Run License"
puts "RUN SAY BYAR"
end
end
@@ -59,8 +51,8 @@ class ActionController::Base
end
end
def check_license(lookup)
License.check_license_file(lookup)
def check_license
License.check_license_file
end
def check_installation
@@ -97,13 +89,14 @@ class ActionController::Base
end
class ActionController::API
before_action :lookup_domain if Rails.env.production?
before_action :lookup_domain
private
def lookup_domain
if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_CODE"] == "cloud"
@license = cache_license(ENV["SX_PROVISION_URL"], request.host) # request.subdomain.downcase
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.dbschema
ActiveRecord::Base.establish_connection(website_connection(@license))