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
|
||||
|
||||
@@ -219,26 +219,22 @@ class License
|
||||
|
||||
# read line by key for license file
|
||||
def read_license(key_name)
|
||||
decrypted_line = ""
|
||||
key, iv = get_redis_key()
|
||||
|
||||
if File.exist?("config/license.yml")
|
||||
if license = YAML.load(File.read("config/license.yml"))
|
||||
decrypted_line = AESCrypt.decrypt_data(decode_str(license[lookup][key_name]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
|
||||
AESCrypt.decrypt_data(decode_str(license[lookup][key_name]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
|
||||
end
|
||||
end
|
||||
return decrypted_line
|
||||
end
|
||||
|
||||
# read line by key for license file without decrypt
|
||||
def read_license_no_decrypt(key)
|
||||
decrypted_line = ""
|
||||
if File.exist?("config/license.yml")
|
||||
if license = YAML.load_file("config/license.yml")
|
||||
decrypted_line = license[lookup][key]
|
||||
end
|
||||
end
|
||||
return decrypted_line
|
||||
end
|
||||
|
||||
# Update license file for line
|
||||
@@ -255,11 +251,6 @@ class License
|
||||
|
||||
# To write changes to the file, use:
|
||||
File.open("config/license.yml", "w") {|file| file.write(license.to_yaml) }
|
||||
|
||||
# File.open("config/license.yml").each do |line|
|
||||
# new_file_str = line.gsub(content, crypted_str)
|
||||
# f.put
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -306,6 +297,7 @@ class License
|
||||
redis = Redis.new
|
||||
cache_shop = redis.get(cache_key)
|
||||
|
||||
puts Marshal.load(cache_shop)
|
||||
if !cache_shop.nil?
|
||||
@shop = Marshal.load(cache_shop)
|
||||
key = @shop["key"]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class ActionController::Base
|
||||
before_action :lookup_domain, :set_locale
|
||||
before_action :lookup_domain if Rails.env.production?
|
||||
before_action :set_locale
|
||||
|
||||
private
|
||||
|
||||
@@ -96,7 +97,7 @@ class ActionController::Base
|
||||
end
|
||||
|
||||
class ActionController::API
|
||||
before_action :lookup_domain
|
||||
before_action :lookup_domain if Rails.env.production?
|
||||
|
||||
private
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace :shop do
|
||||
|
||||
|
||||
#Create Adminstrator employee
|
||||
ActiveRecord::Base.connection.execute("INSERT INTO employees(name,role,password_digest,emp_id,created_by,shop_code,created_at,updated_at,app_id,app_token) VALUES ('Administrator','administrator','$2a$10$OKFA4b4yh0xCJNmzjMMijusnO712LUSEL4/y56p2XmdKBRPWgXwDa','999','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Cashier','cashier','$2a$10$rXWBQro.YqUu5klH9oxqA.vcdq7webHm75FeXylY4uoJlek82luOq','333','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Manager','manager','$2a$10$JmzePPoejam8alpR6hrjr.8jIe/pm36IhErtoP4WwK788x2JfHUL2','777','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Application','application','$2a$12$Kzr5OIFb7B7KU52iKNoeSu5LnXtfJx0YX3s3d.HHJzxeodCv31Ehm','444','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(), '#{SecureRandom.urlsafe_base64(nil, false)}', '#{SecureRandom.hex(10)}');")
|
||||
ActiveRecord::Base.connection.execute("INSERT INTO employees(name,role,password_digest,emp_id,created_by,shop_code,created_at,updated_at,app_id,app_token) VALUES ('Administrator','administrator','$2a$10$OKFA4b4yh0xCJNmzjMMijusnO712LUSEL4/y56p2XmdKBRPWgXwDa','999','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Cashier','cashier','$2a$10$rXWBQro.YqUu5klH9oxqA.vcdq7webHm75FeXylY4uoJlek82luOq','333','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL),('Manager','manager','$2a$10$JmzePPoejam8alpR6hrjr.8jIe/pm36IhErtoP4WwK788x2JfHUL2','777','SYSTEM DEFAULT','#{args.shop_code}',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),NULL,NULL);")
|
||||
Rails.logger.info " Finished Create Adminstrator employee Set Up Data"
|
||||
|
||||
#PrintSetting
|
||||
|
||||
Reference in New Issue
Block a user