diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3c061feb..833b49d6 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,11 +1,11 @@ class ApplicationController < ActionController::Base - include LicenseVerification + include LoginVerification #before_action :check_installation protect_from_forgery with: :exception # lookup domain for db from provision - before_action :set_locale + # before_action :set_locale helper_method :current_company,:current_login_employee,:current_user # alias_method :current_user, :current_login_employee,:current_user @@ -13,16 +13,6 @@ class ApplicationController < ActionController::Base #all token authentication must be done here #response format must be set to JSON - #change locallization - def set_locale - I18n.locale = params[:locale] || I18n.default_locale - end - - # RESTful url for localize - def default_url_options - { locale: I18n.locale } - end - rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message redirect_to root_path diff --git a/app/controllers/base_crm_controller.rb b/app/controllers/base_crm_controller.rb index 5c412fcf..91da2a72 100755 --- a/app/controllers/base_crm_controller.rb +++ b/app/controllers/base_crm_controller.rb @@ -1,4 +1,5 @@ -class BaseCrmController < ApplicationController +class BaseCrmController < ActionController::Base + include LoginVerification layout "CRM" #before_action :check_installation diff --git a/app/controllers/base_inventory_controller.rb b/app/controllers/base_inventory_controller.rb index f44747d3..2fe167c0 100755 --- a/app/controllers/base_inventory_controller.rb +++ b/app/controllers/base_inventory_controller.rb @@ -1,4 +1,5 @@ -class BaseInventoryController < ApplicationController +class BaseInventoryController < ActionController::Base + include LoginVerification layout "inventory" #before_action :check_installation diff --git a/app/controllers/base_oqs_controller.rb b/app/controllers/base_oqs_controller.rb index f1f2831a..db9f8231 100755 --- a/app/controllers/base_oqs_controller.rb +++ b/app/controllers/base_oqs_controller.rb @@ -1,4 +1,5 @@ -class BaseOqsController < ApplicationController +class BaseOqsController < ActionController::Base + include LoginVerification layout "OQS" #before_action :check_installation diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index 58d9b801..ec415bad 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -1,4 +1,5 @@ -class BaseOrigamiController < ApplicationController +class BaseOrigamiController < ActionController::Base + include LoginVerification layout "origami" # before_action :checkin_process diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index f7551f22..733e48f9 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,10 +1,11 @@ -class BaseReportController < ApplicationController - layout "application" +class BaseReportController < ActionController::Base + include LoginVerification + layout "application" - #before_action :check_installation - protect_from_forgery with: :exception + #before_action :check_installation + protect_from_forgery with: :exception - rescue_from CanCan::AccessDenied do |exception| + rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message redirect_to root_path end diff --git a/app/controllers/base_waiter_controller.rb b/app/controllers/base_waiter_controller.rb index 248e32a6..ca4622db 100755 --- a/app/controllers/base_waiter_controller.rb +++ b/app/controllers/base_waiter_controller.rb @@ -1,4 +1,5 @@ -class BaseWaiterController < ApplicationController +class BaseWaiterController < ActionController::Base + include LoginVerification layout "waiter" #before_action :check_installation diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index aa9d8319..fa588574 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -2,7 +2,7 @@ module LoginVerification extend ActiveSupport::Concern included do - before_action :authenticate_session_token + before_action :authenticate helper_method :current_company,:current_login_employee end diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb new file mode 100644 index 00000000..f33ebfed --- /dev/null +++ b/config/initializers/action_controller.rb @@ -0,0 +1,81 @@ +# ActionController::Base are used by both Peatio controllers and +# Doorkeeper controllers. +class ActionController::Base + + before_action :lookup_domain, :set_language + + private + + 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)) + # 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 + + 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 + + #change locallization + def set_locale + I18n.locale = params[:locale] || I18n.default_locale + end + + # RESTful url for localize + def default_url_options + { locale: I18n.locale } + end + +end