From 121338677c9b8e4978133319311495d0eb50af87 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 9 Nov 2017 14:41:35 +0630 Subject: [PATCH] add license --- app/controllers/application_controller.rb | 7 +++++-- app/helpers/application_helper.rb | 16 +--------------- app/models/license.rb | 8 ++++---- config/sx.yml | 3 ++- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ce00dda9..956c90d0 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception # lookup domain for db from provision - before_action :lookup_domain, :set_locale + before_action :check_license, :lookup_domain, :set_locale helper_method :current_company,:current_login_employee,:current_user # alias_method :current_user, :current_login_employee,:current_user @@ -94,7 +94,10 @@ class ApplicationController < ActionController::Base private def check_license - if current_company.nil? + # if current_company.nil? + # redirect_to install_path + # end + if !File.directory?("/config/license.yml") redirect_to install_path end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 037767c9..27024d75 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -6,19 +6,5 @@ module ApplicationHelper when :error then "alert alert-error fade-in" when :alert then "alert alert-error fade-in" end - end - - # For Pageless - # def pageless(total_pages, url=nil, container=nil) - # opts = { - # :totalPages => total_pages, - # :url => url, - # :loaderMsg => 'Loading more pages...', - # :loaderImage => image_path('load.gif') - # } - - # container && opts[:container] ||= container - - # javascript_tag("$('#{container}').pageless(#{opts.to_json});") - # end + end end diff --git a/app/models/license.rb b/app/models/license.rb index b2682213..b7e2a9bb 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -13,14 +13,14 @@ class License def initialize(server = "", lookup = "") #this code is hard-code to reflect server mode - Very important. - self.server_mode = "cloud" + self.server_mode = ENV["server_mode"] if (server != "") self.class.base_uri server end @secret = SecureRandom.hex(10) - @params = { query: { device: "SXlite", token: SECRETS_CONFIG['provision_key'] } } + @params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } } end def shop_code @@ -106,7 +106,7 @@ class License def check_remote_license(license_key) # @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} } - @options = { query: {device: "SXlite", key: license_key, skey: @secret, token: SECRETS_CONFIG['provision_key']} } + @options = { query: {device: "SX", key: license_key, skey: @secret, token: SECRETS_CONFIG['provision_key']} } response = self.class.get("/license", @options) @license = response.parsed_response @@ -120,7 +120,7 @@ class License end def verify_by_api_token(api_token) - @options = { query: {device: "SXlite", api_token: api_token, skey: @secret, token: SECRETS_CONFIG['provision_key']} } + @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 diff --git a/config/sx.yml b/config/sx.yml index 1fc3a186..4dca50a2 100755 --- a/config/sx.yml +++ b/config/sx.yml @@ -1,6 +1,7 @@ development: - server_mode: cloud #local + server_mode: local sx_provision_url: http://192.168.1.162:3005/api + expired_date: 2017-11-09 05:02:33 test: