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
|
||||
|
||||
@@ -3,22 +3,28 @@ 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"
|
||||
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
|
||||
|
||||
def not_found
|
||||
respond_to do |format|
|
||||
|
||||
@@ -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