update multi_tenancy/license
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class Api::ShopsController < Api::ApiController
|
||||
skip_before_action :set_current_tenant_by_subdomain_or_first, only: [:index, :show]
|
||||
skip_before_action :set_current_tenant_by_subdomain_or_name, only: [:index, :show]
|
||||
|
||||
def index
|
||||
@shops = Shop.select('id,logo,name,shop_code,address,phone_no').all
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,20 +3,26 @@ module MultiTenancy
|
||||
|
||||
included do
|
||||
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
|
||||
before_action :set_current_tenant_by_subdomain_or_first if respond_to? :before_action
|
||||
before_action :set_current_tenant_by_subdomain_or_name if respond_to? :before_action
|
||||
helper_method :current_shop if respond_to? :helper_method
|
||||
end
|
||||
|
||||
private
|
||||
def set_current_tenant_by_subdomain_or_first
|
||||
find_tenant_by_subdomain_or_frist || not_found
|
||||
def set_current_tenant_by_subdomain_or_name
|
||||
find_tenant_by_subdomain_or_name || not_found
|
||||
end
|
||||
|
||||
def find_tenant_by_subdomain_or_frist
|
||||
def find_tenant_by_subdomain_or_name
|
||||
if request.subdomains.last && request.subdomains.last != "www"
|
||||
set_current_tenant(Shop.find_by(subdomain: request.subdomains.last))
|
||||
elsif ENV["SERVER_MODE"] == "application"
|
||||
set_current_tenant(Shop.first)
|
||||
license = License.new(ENV["SX_PROVISION_URL"], request.host)
|
||||
shop_name = license.read_license_no_decrypt("shop_name")
|
||||
if Rails.env.production? || shop_name
|
||||
set_current_tenant(Shop.find_by(name: shop_name))
|
||||
else
|
||||
set_current_tenant(Shop.first)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class InstallController < BaseController
|
||||
skip_before_action :set_current_tenant_by_subdomain_or_first
|
||||
skip_before_action :set_current_tenant_by_subdomain_or_name
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
||||
def index
|
||||
|
||||
Reference in New Issue
Block a user