From 37ff82ae5d2cbb46ae02deac9937cf8f2258b697 Mon Sep 17 00:00:00 2001 From: Zin Moe Date: Tue, 14 Jan 2020 15:34:02 +0630 Subject: [PATCH] modify generate auth token method --- app/models/employee.rb | 2 ++ config/initializers/action_controller.rb | 44 ++++++++++++------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/models/employee.rb b/app/models/employee.rb index 69b41fd2..907aa9ad 100755 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -100,5 +100,7 @@ class Employee < ApplicationRecord def generate_auth_token return if self.role != 'app' self.auth_token = SecureRandom.hex(10) + rescue ActiveRecord::RecordNotUnique + retry end end diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index b0bed108..091abd33 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -4,28 +4,28 @@ class ActionController::Base private def lookup_domain - # if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_CODE"] = "cloud" - # from = request.host - # @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase - # if (!@license.nil?) - # logger.info "Location - " + @license.dbschema - # 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 - # else - # # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end - # end + if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_CODE"] = "cloud" + from = request.host + @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase + if (!@license.nil?) + logger.info "Location - " + @license.dbschema + 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 + else + # check for license file + if check_license + current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path + end + end end