Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into adminbsb_ui_changes
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -36,6 +36,8 @@ pickle-email-*.html
|
|||||||
/gems/*
|
/gems/*
|
||||||
._*.*
|
._*.*
|
||||||
.rbenv-version
|
.rbenv-version
|
||||||
|
|
||||||
|
/config/initializers/*
|
||||||
config/deploy/config/*
|
config/deploy/config/*
|
||||||
config/puma.rb
|
config/puma.rb
|
||||||
#config/shops.json
|
#config/shops.json
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class Api::ApiController < ActionController::API
|
class Api::ApiController < ActionController::API
|
||||||
include TokenVerification
|
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
|
private
|
||||||
#this is base api base controller to need to inherit.
|
#this is base api base controller to need to inherit.
|
||||||
@@ -21,4 +22,32 @@ class Api::ApiController < ActionController::API
|
|||||||
def current_login_employee
|
def current_login_employee
|
||||||
@employee = Employee.find_by_token_session(current_token)
|
@employee = Employee.find_by_token_session(current_token)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -15,8 +15,15 @@ module TokenVerification
|
|||||||
|
|
||||||
def authenticate_token
|
def authenticate_token
|
||||||
authenticate_with_http_token do |token, options|
|
authenticate_with_http_token do |token, options|
|
||||||
#@current_user = User.find_by(api_key: token)
|
# Rails.logger.debug "token - " + token.to_s
|
||||||
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)
|
@user = Employee.authenticate_by_token(token)
|
||||||
if @user
|
if @user
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -56,6 +56,21 @@ class MyAesCrypt
|
|||||||
return aes_key, aes_iv
|
return aes_key, aes_iv
|
||||||
end
|
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
|
private
|
||||||
def encrypt(data)
|
def encrypt(data)
|
||||||
cipher.encrypt
|
cipher.encrypt
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ class ActionController::Base
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
#check for license file
|
#check for license file
|
||||||
if check_license
|
# if check_license
|
||||||
current_license(ENV["SX_PROVISION_URL"])
|
# current_license(ENV["SX_PROVISION_URL"])
|
||||||
else
|
# else
|
||||||
redirect_to activate_path
|
# redirect_to activate_path
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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==
|
|
||||||
@@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
development:
|
development:
|
||||||
secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61
|
secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61
|
||||||
sx_provision_url: connect.smartsales.dev/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api
|
sx_provision_url: https://connect.pos-myanmar.com/bensai/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api
|
||||||
server_mode: application
|
server_mode: cloud
|
||||||
cipher_type: AES-256-CBC
|
cipher_type: AES-256-CBC
|
||||||
sx_key: Wh@t1$C2L
|
sx_key: Wh@t1$C2L
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
{
|
{
|
||||||
"data": [
|
"data": [
|
||||||
{
|
{
|
||||||
|
"lookup": "local",
|
||||||
|
"value": {
|
||||||
|
"key": "999d675168d813d5e1c7",
|
||||||
|
"iv": "999d675168d813d5e1c7"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user