license update for token
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
include LoginVerification
|
||||
include LicenseVerification
|
||||
|
||||
#before_action :check_installation
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
# lookup domain for db from provision
|
||||
before_action :lookup_domain, :set_locale
|
||||
before_action :set_locale
|
||||
|
||||
helper_method :current_company,:current_login_employee,:current_user
|
||||
# alias_method :current_user, :current_login_employee,:current_user
|
||||
@@ -22,68 +23,6 @@ class ApplicationController < ActionController::Base
|
||||
{ locale: I18n.locale }
|
||||
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.name
|
||||
ActiveRecord::Base.establish_connection(website_connection(@license))
|
||||
authentication
|
||||
# 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
|
||||
|
||||
def current_license(url)
|
||||
@license = License.new(url)
|
||||
flag = @license.detail_with_local_file()
|
||||
if (flag == 0)
|
||||
flash[:notice] = 'Expired or No License!'
|
||||
elsif (flag == 2)
|
||||
flash[:notice] = 'Expiring! Please, License extend...'
|
||||
else
|
||||
puts "RUN SAY BYAR"
|
||||
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
|
||||
|
||||
def website_connection(license)
|
||||
default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase,
|
||||
:username => license.dbusername, :password => license.dbpassword)
|
||||
|
||||
end
|
||||
|
||||
def reconnect_default_db
|
||||
ActiveRecord::Base.establish_connection(Rails.env)
|
||||
end
|
||||
|
||||
# Regular database.yml configuration hash
|
||||
def default_connection
|
||||
@default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup
|
||||
end
|
||||
|
||||
rescue_from CanCan::AccessDenied do |exception|
|
||||
flash[:warning] = exception.message
|
||||
redirect_to root_path
|
||||
@@ -112,14 +51,6 @@ class ApplicationController < ActionController::Base
|
||||
@employee = Employee.find_by_token_session(session[:session_token])
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def check_license
|
||||
if License.check_license_file
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user