add activation in license

This commit is contained in:
Yan
2017-11-15 19:10:56 +06:30
parent c2095b4a61
commit b1f98df4e0
3 changed files with 48 additions and 13 deletions

View File

@@ -23,13 +23,13 @@ class License
# @params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } }
end
def shop_code
if ( self.subdomain.length > 3)
return self.subdomain[0,3].upcase
else
return self.subdomain.upcase
end
end
# def shop_code
# if ( self.subdomain.length > 3)
# return self.subdomain[0,3].upcase
# else
# return self.subdomain.upcase
# end
# end
def detail_with_local_cache(lookup, key, iv)
##Check from local redis - if available load local otherwise get from remote
@@ -137,8 +137,18 @@ class License
# end
# License Activation
def license_activate
def license_activate (key, iv, license_key)
@params = { query: { lookup_type: self.server_mode, encrypted_key: key, iv_key: iv, license_key: license_key } }
response = self.class.get("/activate", @params)
@activate = response.parsed_response
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
if (@activate["status"])
return create_license_file(@activate)
else
response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"}
end
end
def verify_license
@@ -216,6 +226,30 @@ class License
private
# License File Creation
def create_license_file(response_data)
if check_license_file
delete_license_file
end
begin
# Licese File Creation
f = File.open("config/license.yml", "w")
f.write("name: #{response_data['name']}\n")
f.write("shopname: #{response_data['shopname']}\n")
f.write("dbhost: #{response_data['dbhost']}\n")
f.write("dbschema: #{response_data['dbschema']}\n")
f.write("dbusername: #{response_data['dbusername']}\n")
f.write("dbpassword: #{response_data['dbpassword']}\n")
f.write("api_token: #{response_data['api_token']}\n")
f.write("app_token: #{response_data['app_token']}\n")
f.close
rescue IOError
response = { "status": false, "message": "Can't create license file. Please contact code2lab call center!"}
end
response = { "status": true, "message": "License created"}
end
# Delete License File
def delete_license_file
File.delete("config/license.yml") if File.exist?("config/license.yml")