diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 833b49d6..5f19ddaf 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,7 +7,8 @@ class ApplicationController < ActionController::Base # lookup domain for db from provision # before_action :set_locale - helper_method :current_company,:current_login_employee,:current_user + # helper_method :current_company,:current_login_employee,:current_user + # alias_method :current_user, :current_login_employee,:current_user #this is base api base controller to need to inherit. #all token authentication must be done here @@ -18,6 +19,7 @@ class ApplicationController < ActionController::Base redirect_to root_path end + private def current_user @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] end @@ -36,7 +38,7 @@ class ApplicationController < ActionController::Base end - def current_login_employee + def current_login_employee if (!session[:session_token].nil?) @employee = Employee.find_by_token_session(session[:session_token]) end diff --git a/app/controllers/base_crm_controller.rb b/app/controllers/base_crm_controller.rb index 91da2a72..d7c008f6 100755 --- a/app/controllers/base_crm_controller.rb +++ b/app/controllers/base_crm_controller.rb @@ -9,19 +9,4 @@ class BaseCrmController < ActionController::Base flash[:warning] = exception.message redirect_to root_path 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 - - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] - end - end diff --git a/app/controllers/base_inventory_controller.rb b/app/controllers/base_inventory_controller.rb index 2fe167c0..fc9c0c47 100755 --- a/app/controllers/base_inventory_controller.rb +++ b/app/controllers/base_inventory_controller.rb @@ -9,9 +9,4 @@ class BaseInventoryController < ActionController::Base flash[:warning] = exception.message redirect_to root_path end - - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] - end - end diff --git a/app/controllers/base_oqs_controller.rb b/app/controllers/base_oqs_controller.rb index db9f8231..19b01ea3 100755 --- a/app/controllers/base_oqs_controller.rb +++ b/app/controllers/base_oqs_controller.rb @@ -9,19 +9,4 @@ class BaseOqsController < ActionController::Base flash[:warning] = exception.message redirect_to root_path 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 - - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] - end - end diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index ec415bad..a67aa58f 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -6,16 +6,9 @@ class BaseOrigamiController < ActionController::Base #before_action :check_installation protect_from_forgery with: :exception + rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message redirect_to origami_root_path end - - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] - end - - # def checkin_process - # CheckinJob.set(wait: 1.minute).perform_later() - # end end diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 733e48f9..154a0bbb 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -5,15 +5,13 @@ class BaseReportController < ActionController::Base #before_action :check_installation protect_from_forgery with: :exception + helper_method :current_company,:current_login_employee,:current_user + rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message redirect_to root_path end - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] - end - PERIOD = { "today" => 0, "yesterday" => 1, @@ -83,8 +81,30 @@ class BaseReportController < ActionController::Base end return from, to - - end - + + private + def current_user + @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + end + + # Get current Cashier + def get_cashier + @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + end + + def current_company + begin + return Company.first + rescue + return nil + end + + end + + def current_login_employee + if (!session[:session_token].nil?) + @employee = Employee.find_by_token_session(session[:session_token]) + end + end end diff --git a/app/controllers/base_waiter_controller.rb b/app/controllers/base_waiter_controller.rb index ca4622db..32ae0853 100755 --- a/app/controllers/base_waiter_controller.rb +++ b/app/controllers/base_waiter_controller.rb @@ -4,4 +4,31 @@ class BaseWaiterController < ActionController::Base #before_action :check_installation protect_from_forgery with: :exception + + helper_method :current_company,:current_login_employee,:current_user + + private + def current_user + @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + end + + # Get current Cashier + def get_cashier + @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + end + + def current_company + begin + return Company.first + rescue + return nil + end + + end + + def current_login_employee + if (!session[:session_token].nil?) + @employee = Employee.find_by_token_session(session[:session_token]) + end + end end diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index fa588574..a82a5c7f 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -2,8 +2,8 @@ module LoginVerification extend ActiveSupport::Concern included do - before_action :authenticate - helper_method :current_company,:current_login_employee + before_action :authenticate_session_token + helper_method :current_company, :current_login_employee, :current_user, :get_cashier end #this is base api base controller to need to inherit. @@ -15,16 +15,24 @@ module LoginVerification rescue return nil end - end def current_login_employee @employee = Employee.find_by_token_session(session[:session_token]) end + def current_user + @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + end + + # Get current Cashiers + def get_cashier + @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + end + protected # Authenticate the user with token based authentication - def authenticate + def authenticate authenticate_session_token || render_unauthorized end @@ -38,9 +46,9 @@ module LoginVerification if @user return true #Maybe log - login? - else - flash[:notice] = 'Invalid Access!' - # return false + # else + # flash[:notice] = 'Invalid Access!' + # # return false end end end diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index f33ebfed..7cabe7f7 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -1,17 +1,15 @@ -# ActionController::Base are used by both Peatio controllers and -# Doorkeeper controllers. class ActionController::Base - before_action :lookup_domain, :set_language + before_action :lookup_domain, :set_locale private - def lookup_domain + 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 + logger.info "Location - " + @license.dbhost ActiveRecord::Base.establish_connection(website_connection(@license)) # authenticate_session_token # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema