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

View File

@@ -13,7 +13,7 @@ module MultiTenancy
end end
def find_tenant_by_subdomain_or_frist 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)) set_current_tenant(Shop.find_by(subdomain: request.subdomains.last))
elsif ENV["SERVER_MODE"] == "application" elsif ENV["SERVER_MODE"] == "application"
set_current_tenant(Shop.first) set_current_tenant(Shop.first)

View File

@@ -1,7 +1,6 @@
class InstallController < BaseController class InstallController < BaseController
skip_before_action :lookup_domain skip_before_action :set_current_tenant_by_subdomain_or_first
skip_before_action :verify_authenticity_token skip_before_action :verify_authenticity_token
# before_action :check_license
def index def index
end end
@@ -9,7 +8,7 @@ class InstallController < BaseController
def activate def activate
flag = "<%= ENV['AES_IV'] %>" flag = "<%= ENV['AES_IV'] %>"
key_base = "<%= ENV['secret_key_base'] %>" key_base = "<%= ENV['secret_key_base'] %>"
restaurant = params[:restaurant_name] restaurant = params[:restaurant_name]
license_key = params[:license_key] license_key = params[:license_key]
# admin_user = params[:admin_user] # admin_user = params[:admin_user]
@@ -18,20 +17,20 @@ class InstallController < BaseController
db_schema = params[:db_schema] db_schema = params[:db_schema]
db_user = params[:db_user] db_user = params[:db_user]
db_password = params[:db_password] db_password = params[:db_password]
phrase = license_key phrase = license_key
# Check Exists IV # Check Exists IV
# if flag == "<%= ENV['AES_IV'] %>" # if flag == "<%= ENV['AES_IV'] %>"
# # Export for Key # # Export for Key
# aes = MyAesCrypt.new # aes = MyAesCrypt.new
# aes_key, aes_iv = aes.export_key(phrase) # aes_key, aes_iv = aes.export_key(phrase)
# else # else
# aes_key = ENV["AES_KEY"] # aes_key = ENV["AES_KEY"]
# aes_iv = ENV["AES_IV"] # aes_iv = ENV["AES_IV"]
# end # 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) response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password)
if response[:status] if response[:status]
redirect_to root_url, notice: response["message"] redirect_to root_url, notice: response["message"]
else else
@@ -39,28 +38,17 @@ class InstallController < BaseController
end end
end end
def check_license def lookup_domain
if License.check_license_file if (ENV["SERVER_MODE"] == "application") ||
redirect_to root_url (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
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) # def current_license(url, key)
# @license = License.new(url, key) # @license = License.new(url, key)

View File

@@ -1,12 +1,14 @@
require 'yaml'
class License class License
include HTTParty 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, 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, :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, :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 @license = nil
@secret = nil @secret = nil
@@ -14,7 +16,10 @@ class License
def initialize(server = "", lookup = "") def initialize(server = "", lookup = "")
#this code is hard-code to reflect server mode - Very important. #this code is hard-code to reflect server mode - Very important.
self.server_mode = ENV["SERVER_MODE"] self.server_mode = ENV["SERVER_MODE"]
unless ENV["SERVER_MODE"] == "cloud"
self.server_mode = "application"
end
self.lookup = lookup
if (server != "") if (server != "")
self.class.base_uri server self.class.base_uri server
end end
@@ -189,8 +194,11 @@ class License
end end
# Check License File exists # Check License File exists
def self.check_license_file def self.check_license_file(lookup)
return File.exist?("config/license.yml") return unless File.exist?("config/license.yml")
if license = YAML.load_file("config/license.yml")
license[lookup].present?
end
end end
# read line by key for license file # read line by key for license file
@@ -199,11 +207,8 @@ class License
key, iv = get_redis_key() key, iv = get_redis_key()
if File.exist?("config/license.yml") if File.exist?("config/license.yml")
File.open("config/license.yml").each do |line| if license = YAML.load(File.read("config/license.yml"))
if line.include? (key_name) decrypted_line = AESCrypt.decrypt_data(decode_str(license[lookup][key_name]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
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
end end
end end
return decrypted_line return decrypted_line
@@ -213,11 +218,8 @@ class License
def read_license_no_decrypt(key) def read_license_no_decrypt(key)
decrypted_line = "" decrypted_line = ""
if File.exist?("config/license.yml") if File.exist?("config/license.yml")
File.open("config/license.yml").each do |line| if license = YAML.load_file("config/license.yml")
if line.include? (key) decrypted_line = license[lookup][key]
decrypted_line_array = line.split(": ")
decrypted_line = decrypted_line_array[1]
end
end end
end end
return decrypted_line return decrypted_line
@@ -231,18 +233,18 @@ class License
crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE'])
end end
content_str = read_license_no_decrypt(content)
if File.exist?("config/license.yml") if File.exist?("config/license.yml")
file_str = File.read("config/license.yml") if license = YAML.load_file("config/license.yml")
new_file_str = file_str.gsub(content_str, encode_str(crypted_str)) license[lookup][content] = encode_str(crypted_str)
# To write changes to the file, use: # To write changes to the file, use:
File.open("config/license.yml", "w") {|file| file.puts new_file_str } File.open("config/license.yml", "w") {|file| file.puts new_file_str }
# File.open("config/license.yml").each do |line| # File.open("config/license.yml").each do |line|
# new_file_str = line.gsub(content, crypted_str) # new_file_str = line.gsub(content, crypted_str)
# f.put # f.put
# end # end
end
end end
end end
@@ -314,23 +316,41 @@ class License
begin begin
# Licese File Creation # Licese File Creation
File.open("config/license.yml", "w") do |f| # File.open("config/license.yml", "w") do |f|
f.puts("iv_key: #{response_data['iv_key']}") # f.puts("iv_key: #{response_data['iv_key']}")
f.puts("shop_name: #{response_data['shop_name']}") # f.puts("shop_name: #{response_data['shop_name']}")
f.puts("email: #{response_data['email']}") # f.puts("email: #{response_data['email']}")
f.puts("telephone: #{response_data['telephone']}") # f.puts("telephone: #{response_data['telephone']}")
f.puts("fax: #{response_data['fax']}") # f.puts("fax: #{response_data['fax']}")
f.puts("address: #{response_data['address']}") # f.puts("address: #{response_data['address']}")
f.puts("dbhost: #{response_data['dbhost']}") # f.puts("dbhost: #{response_data['dbhost']}")
f.puts("dbschema: #{response_data['dbschema']}") # f.puts("dbschema: #{response_data['dbschema']}")
f.puts("dbusername: #{response_data['dbusername']}") # f.puts("dbusername: #{response_data['dbusername']}")
f.puts("dbpassword: #{response_data['dbpassword']}") # f.puts("dbpassword: #{response_data['dbpassword']}")
f.puts("api_token: #{response_data['api_token']}") # f.puts("api_token: #{response_data['api_token']}")
f.puts("app_token: #{response_data['app_token']}") # f.puts("app_token: #{response_data['app_token']}")
f.puts("plan_sku: #{response_data['plan_sku']}") # f.puts("plan_sku: #{response_data['plan_sku']}")
f.puts("renewable_date: #{response_data['renewable_date']}") # f.puts("renewable_date: #{response_data['renewable_date']}")
f.puts("plan_name: #{response_data['plan_name']}") # f.puts("plan_name: #{response_data['plan_name']}")
end # 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 rescue IOError
response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"}
end end

View File

@@ -20,7 +20,8 @@ Rails.application.configure do
#config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? #config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS. # 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 # config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed. # Do not fallback to assets pipeline if a precompiled asset is missed.

View File

@@ -20,25 +20,25 @@ class ActionController::Base
end end
elsif request.subdomain.present? && request.subdomain != "www" || ENV["SERVER_MODE"] == "application" elsif request.subdomain.present? && request.subdomain != "www" || ENV["SERVER_MODE"] == "application"
# check for license file # check for license file
if check_license if check_license(request.host)
current_license(ENV["SX_PROVISION_URL"]) current_license(ENV["SX_PROVISION_URL"], request.host)
else else
redirect_to activate_path redirect_to activate_path
end end
else else
render_not_found not_found
end end
end end
def render_not_found def not_found
respond_to do |format| respond_to do |format|
format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found } format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
format.json { head :not_found } format.json { head :not_found }
end end
end end
def current_license(url) def current_license(url, lookup)
@license = License.new(url) @license = License.new(url, lookup)
flag = @license.detail_with_local_file() flag = @license.detail_with_local_file()
if (flag == 0) if (flag == 0)
flash[:notice] = 'Expired or No License!' flash[:notice] = 'Expired or No License!'
@@ -59,8 +59,8 @@ class ActionController::Base
end end
end end
def check_license def check_license(lookup)
License.check_license_file License.check_license_file(lookup)
end end
def check_installation def check_installation

View File

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

View File

@@ -24,7 +24,7 @@ test:
# instead read values from the environment. # instead read values from the environment.
production: production:
secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 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 server_mode: application
cipher_type: AES-256-CBC cipher_type: AES-256-CBC
sx_key: Wh@t1$C2L sx_key: Wh@t1$C2L

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
namespace :shop do namespace :shop do
desc "Create shop and seed data" 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) 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}" 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}, gateway_communication_type =Lookup.create([{lookup_type:'gateway_communication_type',name: 'API',value: 'api',shop_code: args.shop_code},