adding license activation

This commit is contained in:
Yan
2017-11-15 17:55:51 +06:30
parent 50bf67f5e5
commit c2095b4a61
3 changed files with 55 additions and 37 deletions

View File

@@ -2,13 +2,19 @@ class InstallController < BaseController
def index def index
end end
def create def activate
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]
admin_password = params[:admin_password] admin_password = params[:admin_password]
db_user = params[:db_user]
db_password = params[:db_password]
end end
def lookup_domain def lookup_domain
if request.subdomain.present? && request.subdomain != "www" if request.subdomain.present? && request.subdomain != "www"
@license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase)

View File

@@ -80,6 +80,7 @@ class License
if has_license if has_license
puts "VERIFIED" puts "VERIFIED"
end end
end
# if cache_license.nil? # if cache_license.nil?
# ##change the d/e key # ##change the d/e key
@@ -119,26 +120,31 @@ class License
# return false # return false
end end
def detail # def detail
response = self.class.get("/subdomain", @options) # response = self.class.get("/subdomain", @options)
@license = response.parsed_response # @license = response.parsed_response
Rails.logger.debug "License - " + response.parsed_response.to_s # Rails.logger.debug "License - " + response.parsed_response.to_s
if (@license["status"] == true) # if (@license["status"] == true)
assign() # assign()
return true # return true
end # end
# return false
# end
# License Activation
def license_activate
return false
end end
def verify_license def verify_license
api_token = read_license("api_token") api_token = read_license("api_token")
@options = { query: {lookup_type: "application", token: api_token} } @params = { query: {lookup_type: "application", token: api_token} }
response = self.class.get("/verify", @options) response = self.class.get("/verify", @params)
@varified = response.parsed_response @varified = response.parsed_response
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
@@ -152,37 +158,36 @@ class License
return false return false
end end
def check_remote_license(license_key) # def check_remote_license(license_key)
# @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} } # # @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} }
@options = { query: {lookup_type: "application", encrypted_key: @secret, token: SECRETS_CONFIG['provision_key']} } # @options = { query: {lookup_type: "application", encrypted_key: @secret, token: SECRETS_CONFIG['provision_key']} }
response = self.class.get("/license", @options) # response = self.class.get("/license", @options)
@license = response.parsed_response # @license = response.parsed_response
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s # Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
if (@license["status"]) # if (@license["status"])
assign() # assign()
end # end
return @license["status"] # return @license["status"]
# end
end # def verify_by_api_token(api_token)
# @options = { query: {device: "SX", api_token: api_token, skey: @secret, token: SECRETS_CONFIG['provision_key']} }
# response = self.class.get("/verify_token", @options)
def verify_by_api_token(api_token) # @license = response.parsed_response
@options = { query: {device: "SX", api_token: api_token, skey: @secret, token: SECRETS_CONFIG['provision_key']} }
response = self.class.get("/verify", @options)
@license = response.parsed_response # Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
# if (@license["status"])
# assign()
# end
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s # return @license["status"]
if (@license["status"]) # end
assign()
end
return @license["status"]
end
#Load License is remove from the cloud license because - this license is must be validated against subdmain instead of license.data from file. #Load License is remove from the cloud license because - this license is must be validated against subdmain instead of license.data from file.
# Check License expired date from PROVISION SERVER
def check_expired(renewal_date) def check_expired(renewal_date)
if (renewal_date < Date.today) if (renewal_date < Date.today)
return true return true
@@ -191,6 +196,7 @@ class License
end end
end end
# Check License File exists
def self.check_license_file def self.check_license_file
return File.exist?("config/license.yml") return File.exist?("config/license.yml")
end end
@@ -209,6 +215,13 @@ class License
end end
private private
# Delete License File
def delete_license_file
File.delete("config/license.yml") if File.exist?("config/license.yml")
end
# Assign db info for Cloud
def assign def assign
# self.name = @license["name"] # self.name = @license["name"]
# self.address_1 = @license["address_1"] # self.address_1 = @license["address_1"]
@@ -228,7 +241,6 @@ class License
## self.plan_activation_date = Date.strptime(@license["plan_activation_date"], "%Y-%m-%d") ## self.plan_activation_date = Date.strptime(@license["plan_activation_date"], "%Y-%m-%d")
## self.plan_next_renewal_date = Date.strptime(@license["plan_next_renewal_date"], "%Y-%m-%d") ## self.plan_next_renewal_date = Date.strptime(@license["plan_next_renewal_date"], "%Y-%m-%d")
# self.plan_max_products = @license["plan_max_products"].to_i # self.plan_max_products = @license["plan_max_products"].to_i
# self.plan_max_customers = @license["plan_max_customers"].to_i # self.plan_max_customers = @license["plan_max_customers"].to_i
# self.plan_active_connections = @license["plan_active_connections"].to_i # self.plan_active_connections = @license["plan_active_connections"].to_i

View File

@@ -11,7 +11,7 @@ scope "(:locale)", locale: /en|mm/ do
#--------- SmartSales Installation ------------# #--------- SmartSales Installation ------------#
get 'install' => 'install#index' get 'install' => 'install#index'
post 'install' => 'install#create' post 'install' => 'install#activate'
#--------- Login/Authentication ------------# #--------- Login/Authentication ------------#
get 'auth/:emp_id' => 'home#show', as: :emp_login get 'auth/:emp_id' => 'home#show', as: :emp_login