cloud for api and doemal
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -36,6 +36,7 @@ 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
|
||||||
|
else8
|
||||||
|
# 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.from.nil? && options.from == "DOEMAL"){
|
||||||
|
if(ENV["SERVER_MODE"] === "cloud"){
|
||||||
|
from = request.subdomain.downcase + "." + request.domain.downcase
|
||||||
|
aes = MyAesCrypt.new
|
||||||
|
return aes.checkKeyForAuth(from, token)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user