Merge branch 'foodcourt' of gitlab.com:code2lab/SXRestaurant into foodcourt

This commit is contained in:
Myat Zin Wai Maw
2020-01-22 14:26:42 +06:30
10 changed files with 322 additions and 298 deletions

View File

@@ -16,9 +16,9 @@ App.checkin = App.cable.subscriptions.create('OutOfStockChannel', {
if (menus) {
menus = jQuery.parseJSON(menus);
menus.forEach(m =>
m.categories.forEach(c =>
c.items.forEach(i =>
menus.forEach(m => {
m.categories.forEach(c => {
c.items.forEach(i => {
i.instances.forEach(instance => {
if (instance.code == item_code) {
if (data.status == true) {
@@ -33,9 +33,10 @@ App.checkin = App.cable.subscriptions.create('OutOfStockChannel', {
}
}
})
)
)
);
})
})
});
localStorage.setItem('menus', JSON.stringify(menus));
}
}

View File

@@ -13,7 +13,7 @@ module MultiTenancy
end
def find_tenant_by_subdomain_or_frist
if request.subdomains.last && request.subdomains.last != 'www'
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)

View File

@@ -1,7 +1,6 @@
class InstallController < BaseController
skip_before_action :lookup_domain
skip_before_action :set_current_tenant_by_subdomain_or_first
skip_before_action :verify_authenticity_token
# before_action :check_license
def index
end
@@ -30,7 +29,7 @@ class InstallController < BaseController
# aes_iv = ENV["AES_IV"]
# end
@license = License.new(ENV["SX_PROVISION_URL"])
@license = License.new(ENV["SX_PROVISION_URL"], request.host)
response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password)
if response[:status]
redirect_to root_url, notice: response["message"]
@@ -39,27 +38,16 @@ class InstallController < BaseController
end
end
def check_license
if License.check_license_file
def lookup_domain
if (ENV["SERVER_MODE"] == "application") ||
(request.subdomain.present? && request.subdomain != "www" && ENV["SERVER_MODE"] != "cloud")
if check_license(request.host)
redirect_to root_url
end
else
not_found
end
end
# def lookup_domain
# if request.subdomain.present? && request.subdomain != "www"
# @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase)
# if (!@license.nil?)
# # logger.info "Location - " + @license.name
# ActiveRecord::Base.establish_connection(website_connection(@license))
# # 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
# end
# end
# def current_license(url, key)
# @license = License.new(url, key)

View File

@@ -1,12 +1,14 @@
require 'yaml'
class License
include HTTParty
base_uri "connect.smartsales.asia/api"
base_uri "https://l.doemal.app//api"
attr_accessor :name, :address_1, :address_2, :township, :city, :country, :email, :phone, :fax, :logo, :subdomain,
:plan_activation_date, :plan_next_renewal_date, :plan_max_products,:plan_max_customers, :plan_active_connections,
:dbhost, :dbschema, :dbusername, :dbpassword, :exchange_unqiue_id, :localqueue_host,:server_mode,:localhost_address,
:localqueue_user, :localqueue_password, :remotequeue_host, :remotequeue_user, :remotequeue_password, :api_token, :app_token
:localqueue_user, :localqueue_password, :remotequeue_host, :remotequeue_user, :remotequeue_password, :api_token, :app_token, :lookup
@license = nil
@secret = nil
@@ -14,7 +16,10 @@ class License
def initialize(server = "", lookup = "")
#this code is hard-code to reflect server mode - Very important.
self.server_mode = ENV["SERVER_MODE"]
unless ENV["SERVER_MODE"] == "cloud"
self.server_mode = "application"
end
self.lookup = lookup
if (server != "")
self.class.base_uri server
end
@@ -189,8 +194,11 @@ class License
end
# Check License File exists
def self.check_license_file
return File.exist?("config/license.yml")
def self.check_license_file(lookup)
return unless File.exist?("config/license.yml")
if license = YAML.load_file("config/license.yml")
license[lookup].present?
end
end
# read line by key for license file
@@ -199,11 +207,8 @@ class License
key, iv = get_redis_key()
if File.exist?("config/license.yml")
File.open("config/license.yml").each do |line|
if line.include? (key_name)
decrypted_line_array = line.split(": ")
decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
end
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'])
end
end
return decrypted_line
@@ -213,11 +218,8 @@ class License
def read_license_no_decrypt(key)
decrypted_line = ""
if File.exist?("config/license.yml")
File.open("config/license.yml").each do |line|
if line.include? (key)
decrypted_line_array = line.split(": ")
decrypted_line = decrypted_line_array[1]
end
if license = YAML.load_file("config/license.yml")
decrypted_line = license[lookup][key]
end
end
return decrypted_line
@@ -231,10 +233,9 @@ class License
crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
end
content_str = read_license_no_decrypt(content)
if File.exist?("config/license.yml")
file_str = File.read("config/license.yml")
new_file_str = file_str.gsub(content_str, encode_str(crypted_str))
if license = YAML.load_file("config/license.yml")
license[lookup][content] = encode_str(crypted_str)
# To write changes to the file, use:
File.open("config/license.yml", "w") {|file| file.puts new_file_str }
@@ -245,6 +246,7 @@ class License
# end
end
end
end
# Re-get keys
def get_key
@@ -314,23 +316,41 @@ class License
begin
# Licese File Creation
File.open("config/license.yml", "w") do |f|
f.puts("iv_key: #{response_data['iv_key']}")
f.puts("shop_name: #{response_data['shop_name']}")
f.puts("email: #{response_data['email']}")
f.puts("telephone: #{response_data['telephone']}")
f.puts("fax: #{response_data['fax']}")
f.puts("address: #{response_data['address']}")
f.puts("dbhost: #{response_data['dbhost']}")
f.puts("dbschema: #{response_data['dbschema']}")
f.puts("dbusername: #{response_data['dbusername']}")
f.puts("dbpassword: #{response_data['dbpassword']}")
f.puts("api_token: #{response_data['api_token']}")
f.puts("app_token: #{response_data['app_token']}")
f.puts("plan_sku: #{response_data['plan_sku']}")
f.puts("renewable_date: #{response_data['renewable_date']}")
f.puts("plan_name: #{response_data['plan_name']}")
end
# File.open("config/license.yml", "w") do |f|
# f.puts("iv_key: #{response_data['iv_key']}")
# f.puts("shop_name: #{response_data['shop_name']}")
# f.puts("email: #{response_data['email']}")
# f.puts("telephone: #{response_data['telephone']}")
# f.puts("fax: #{response_data['fax']}")
# f.puts("address: #{response_data['address']}")
# f.puts("dbhost: #{response_data['dbhost']}")
# f.puts("dbschema: #{response_data['dbschema']}")
# f.puts("dbusername: #{response_data['dbusername']}")
# f.puts("dbpassword: #{response_data['dbpassword']}")
# f.puts("api_token: #{response_data['api_token']}")
# f.puts("app_token: #{response_data['app_token']}")
# f.puts("plan_sku: #{response_data['plan_sku']}")
# f.puts("renewable_date: #{response_data['renewable_date']}")
# f.puts("plan_name: #{response_data['plan_name']}")
# end
license = {lookup => {"iv_key" => response_data['iv_key'],
"shop_name" => response_data['shop_name'],
"email" => response_data['email'],
"telephone" => response_data['telephone'],
"fax" => response_data['fax'],
"address" => response_data['address'],
"dbhost" => response_data['dbhost'],
"dbschema" => response_data['dbschema'],
"dbusername" => response_data['dbusername'],
"dbpassword" => response_data['dbpassword'],
"api_token" => response_data['api_token'],
"app_token" => response_data['app_token'],
"plan_sku" => response_data['plan_sku'],
"renewable_date" => response_data['renewable_date'],
"plan_name" => response_data['plan_name']}
}
File.open("config/license.yml", "w"){ |file| file.write(license.to_yaml) }
rescue IOError
response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"}
end

View File

@@ -20,7 +20,8 @@ Rails.application.configure do
#config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.js_compressor = :uglifier
config.assets.js_compressor = Uglifier.new(harmony: true)
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.

View File

@@ -20,25 +20,25 @@ class ActionController::Base
end
elsif request.subdomain.present? && request.subdomain != "www" || ENV["SERVER_MODE"] == "application"
# check for license file
if check_license
current_license(ENV["SX_PROVISION_URL"])
if check_license(request.host)
current_license(ENV["SX_PROVISION_URL"], request.host)
else
redirect_to activate_path
end
else
render_not_found
not_found
end
end
def render_not_found
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)
@license = License.new(url)
def current_license(url, lookup)
@license = License.new(url, lookup)
flag = @license.detail_with_local_file()
if (flag == 0)
flash[:notice] = 'Expired or No License!'
@@ -59,8 +59,8 @@ class ActionController::Base
end
end
def check_license
License.check_license_file
def check_license(lookup)
License.check_license_file(lookup)
end
def check_installation

View File

@@ -1,6 +1,8 @@
if File.exist?("config/license.yml")
config = YAML.load_file(Rails.root.join("config/license.yml"))
if config
config.fetch(Rails.env, {}).each do |key, value|
ENV[key.upcase] = value.to_s
end
end
end

View File

@@ -24,7 +24,7 @@ test:
# instead read values from the environment.
production:
secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22
sx_provision_url: connect.smartsales.asia/api #52.221.188.144:9292/api #192.168.1.147:3002/api
sx_provision_url: l.doemal.app/api #52.221.188.144:9292/api #192.168.1.147:3002/api
server_mode: application
cipher_type: AES-256-CBC
sx_key: Wh@t1$C2L

View File

@@ -129,6 +129,10 @@ delete from sym_node;
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('display_images','display_images','setting',current_timestamp,current_timestamp);
insert into sym_trigger
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('out_of_stocks','out_of_stocks','setting',current_timestamp,current_timestamp);
# Create Trigger for Dining Channel
insert into sym_trigger
@@ -397,6 +401,10 @@ delete from sym_node;
(trigger_id,router_id,initial_load_order,last_update_time,create_time)
values('display_images','cloud_2_sx', 100, current_timestamp, current_timestamp);
insert into sym_trigger_router
(trigger_id,router_id,initial_load_order,last_update_time,create_time)
values('out_of_stocks','cloud_2_sx', 100, current_timestamp, current_timestamp);
# Setting Channel # From Master to cloud
insert into sym_trigger_router
@@ -439,6 +447,10 @@ delete from sym_node;
(trigger_id,router_id,initial_load_order,last_update_time,create_time)
values('display_images','sx_2_cloud', 100, current_timestamp, current_timestamp);
insert into sym_trigger_router
(trigger_id,router_id,initial_load_order,last_update_time,create_time)
values('out_of_stocks','sx_2_cloud', 100, current_timestamp, current_timestamp);
#End Setting Channel
# Dining Channel # From cloud to SX

View File

@@ -1,9 +1,9 @@
namespace :shop do
desc "Create shop and seed data"
task :create, [:name, :shop_code, :client_name, :client_code, :address, :phone_no] => :environment do |t, args|
task :create, [:name, :shop_code, :subdomain, :client_name, :client_code, :address, :phone_no] => :environment do |t, args|
ActiveRecord::Base.connection.execute("INSERT INTO shops (logo, name, shop_code, subdomain, client_name, client_code, address, township, city, state, country, phone_no, reservation_no, license, activated_at, license_data, base_currency, cloud_url, cloud_token, owner_token, id_prefix, is_rounding_adj, quick_sale_summary, calc_tax_order, show_account_info, note, created_at, updated_at)
VALUES (NULL, '#{args.name}', '#{args.shop_code}', '#{args.name}-#{args.shop_code}', '#{args.client_name}', '#{args.client_code}', '#{args.address}', '', '', '', '', '#{args.phone_no}', '111', '', CURRENT_TIMESTAMP(), 'test', '111', NULL, NULL, NULL, '111', 0, 0, 0, 1, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP())")
VALUES (NULL, '#{args.name}', '#{args.shop_code}', '#{args.subdomain}', '#{args.client_name}', '#{args.client_code}', '#{args.address}', '', '', '', '', '#{args.phone_no}', '111', '', CURRENT_TIMESTAMP(), 'test', '111', NULL, NULL, NULL, '111', 0, 0, 0, 1, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP())")
logger.info " Shop created for #{args.name}-#{args.shop_code}"
gateway_communication_type =Lookup.create([{lookup_type:'gateway_communication_type',name: 'API',value: 'api',shop_code: args.shop_code},