Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into adminbsb_ui_changes

This commit is contained in:
phyusin
2018-04-11 17:59:48 +06:30
9 changed files with 72 additions and 30 deletions

2
.gitignore vendored
View File

@@ -36,6 +36,8 @@ pickle-email-*.html
/gems/*
._*.*
.rbenv-version
/config/initializers/*
config/deploy/config/*
config/puma.rb
#config/shops.json

View File

@@ -1,7 +1,8 @@
class Api::ApiController < ActionController::API
include TokenVerification
helper_method :current_token, :current_login_employee, :get_cashier
before_action :lookup_domain
helper_method :current_token, :current_login_employee, :get_cashier
private
#this is base api base controller to need to inherit.
@@ -21,4 +22,32 @@ class Api::ApiController < ActionController::API
def current_login_employee
@employee = Employee.find_by_token_session(current_token)
end
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.dbhost
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
end
end
def cache_license(url, lookup)
@license = License.new(url, lookup)
if (@license.detail_with_local_cache(lookup) == true)
return @license
else
return nil
end
end
end

View File

@@ -13,10 +13,17 @@ module TokenVerification
authenticate_token || render_unauthorized
end
def authenticate_token
authenticate_with_http_token do |token, options|
#@current_user = User.find_by(api_key: token)
Rails.logger.debug "token - " + token.to_s
def authenticate_token
authenticate_with_http_token do |token, options|
# Rails.logger.debug "token - " + token.to_s
if(options.length !=0 && options["from"] == "DOEMAL")
if(ENV["SERVER_MODE"] === "cloud")
from = request.subdomain.downcase + "." + request.domain.downcase
aes = MyAesCrypt.new
return aes.checkKeyForAuth(from, token)
end
end
@user = Employee.authenticate_by_token(token)
if @user
return true

View File

@@ -56,6 +56,21 @@ class MyAesCrypt
return aes_key, aes_iv
end
def checkKeyForAuth(from,token)
file_path = "config/shops.json"
shop_data = File.read(file_path)
shop_json = JSON.parse(shop_data)
shop_json["data"].each do |j|
if j["lookup"] == from
if(j["value"]["key"] == token)
return true
end
end
end
return false
end
private
def encrypt(data)
cipher.encrypt

View File

@@ -429,7 +429,7 @@
<input type="hidden" name="sale_receipt_no" id="sale_receipt_no">
<input type="hidden" name="filename" id="filename">
<input type="hidden" name="printer_name" id="printer_name">
<div class="text-center">
<div class="text-center">
<iframe id="receipt_pdf" src="" class="pdf-iframe" scrolling="no"></iframe>
</div>
</div>

View File

@@ -3,7 +3,7 @@ class ActionController::Base
private
def lookup_domain
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
@@ -20,11 +20,11 @@ class ActionController::Base
end
else
#check for license file
if check_license
current_license(ENV["SX_PROVISION_URL"])
else
redirect_to activate_path
end
# if check_license
# current_license(ENV["SX_PROVISION_URL"])
# else
# redirect_to activate_path
# end
end
end

View File

@@ -1,15 +0,0 @@
iv_key: rwOZKWcQho6fE4V+A2zFuQ==
shop_name: AMZ_Test
email: aungmyo.zaw@code2lab.com
telephone:
fax:
address:
dbhost: dNzh66R80remB694OEds96OpuyZ4wmHeHFdQh0KwjYFvTInK6+pCN/y6HdbyIlqqjcBHkqPjkjzw45PznLn7hA==
dbschema: 4vooJDxgWdFv/8V7Qx8tzR/8B8T2c5U4XvYcF+2KOoA=
dbusername: Xc8ELRsW7N/f8KsVikMBlg==
dbpassword: HMg+TbLxmfYrDFI4IIAd4g==
api_token: bisryXiEnbTJlZwghAnIByQpiRUMouu
app_token: LycQXJYBZGeCygjIEKdlBXnjIGMiMzgmt
plan_sku: 84hdnSCgkfhvItY7uB/pPQ==
renewable_date: 8E6Ecz8QXAMSlKZnIzn0pQ==
plan_name: 4cMIO0n/JzGFPIccXM6u5A==

View File

@@ -12,8 +12,8 @@
development:
secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61
sx_provision_url: connect.smartsales.dev/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api
server_mode: application
sx_provision_url: https://connect.pos-myanmar.com/bensai/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api
server_mode: cloud
cipher_type: AES-256-CBC
sx_key: Wh@t1$C2L

View File

@@ -1,7 +1,11 @@
{
"data": [
{
"lookup": "local",
"value": {
"key": "999d675168d813d5e1c7",
"iv": "999d675168d813d5e1c7"
}
}
]
}