license and local move to base action and update other base
This commit is contained in:
@@ -7,7 +7,8 @@ class ApplicationController < ActionController::Base
|
|||||||
# lookup domain for db from provision
|
# lookup domain for db from provision
|
||||||
# before_action :set_locale
|
# 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
|
# alias_method :current_user, :current_login_employee,:current_user
|
||||||
#this is base api base controller to need to inherit.
|
#this is base api base controller to need to inherit.
|
||||||
#all token authentication must be done here
|
#all token authentication must be done here
|
||||||
@@ -18,6 +19,7 @@ class ApplicationController < ActionController::Base
|
|||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
def current_user
|
def current_user
|
||||||
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
|
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
|
||||||
end
|
end
|
||||||
@@ -36,7 +38,7 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_login_employee
|
def current_login_employee
|
||||||
if (!session[:session_token].nil?)
|
if (!session[:session_token].nil?)
|
||||||
@employee = Employee.find_by_token_session(session[:session_token])
|
@employee = Employee.find_by_token_session(session[:session_token])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,19 +9,4 @@ class BaseCrmController < ActionController::Base
|
|||||||
flash[:warning] = exception.message
|
flash[:warning] = exception.message
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -9,9 +9,4 @@ class BaseInventoryController < ActionController::Base
|
|||||||
flash[:warning] = exception.message
|
flash[:warning] = exception.message
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_user
|
|
||||||
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,19 +9,4 @@ class BaseOqsController < ActionController::Base
|
|||||||
flash[:warning] = exception.message
|
flash[:warning] = exception.message
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -6,16 +6,9 @@ class BaseOrigamiController < ActionController::Base
|
|||||||
|
|
||||||
#before_action :check_installation
|
#before_action :check_installation
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
rescue_from CanCan::AccessDenied do |exception|
|
rescue_from CanCan::AccessDenied do |exception|
|
||||||
flash[:warning] = exception.message
|
flash[:warning] = exception.message
|
||||||
redirect_to origami_root_path
|
redirect_to origami_root_path
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -5,15 +5,13 @@ class BaseReportController < ActionController::Base
|
|||||||
#before_action :check_installation
|
#before_action :check_installation
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
|
helper_method :current_company,:current_login_employee,:current_user
|
||||||
|
|
||||||
rescue_from CanCan::AccessDenied do |exception|
|
rescue_from CanCan::AccessDenied do |exception|
|
||||||
flash[:warning] = exception.message
|
flash[:warning] = exception.message
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_user
|
|
||||||
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
|
|
||||||
end
|
|
||||||
|
|
||||||
PERIOD = {
|
PERIOD = {
|
||||||
"today" => 0,
|
"today" => 0,
|
||||||
"yesterday" => 1,
|
"yesterday" => 1,
|
||||||
@@ -83,8 +81,30 @@ class BaseReportController < ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
return from, to
|
return from, to
|
||||||
|
|
||||||
|
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -4,4 +4,31 @@ class BaseWaiterController < ActionController::Base
|
|||||||
|
|
||||||
#before_action :check_installation
|
#before_action :check_installation
|
||||||
protect_from_forgery with: :exception
|
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
|
end
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ module LoginVerification
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
before_action :authenticate
|
before_action :authenticate_session_token
|
||||||
helper_method :current_company,:current_login_employee
|
helper_method :current_company, :current_login_employee, :current_user, :get_cashier
|
||||||
end
|
end
|
||||||
|
|
||||||
#this is base api base controller to need to inherit.
|
#this is base api base controller to need to inherit.
|
||||||
@@ -15,16 +15,24 @@ module LoginVerification
|
|||||||
rescue
|
rescue
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_login_employee
|
def current_login_employee
|
||||||
@employee = Employee.find_by_token_session(session[:session_token])
|
@employee = Employee.find_by_token_session(session[:session_token])
|
||||||
end
|
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
|
protected
|
||||||
# Authenticate the user with token based authentication
|
# Authenticate the user with token based authentication
|
||||||
def authenticate
|
def authenticate
|
||||||
authenticate_session_token || render_unauthorized
|
authenticate_session_token || render_unauthorized
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -38,9 +46,9 @@ module LoginVerification
|
|||||||
if @user
|
if @user
|
||||||
return true
|
return true
|
||||||
#Maybe log - login?
|
#Maybe log - login?
|
||||||
else
|
# else
|
||||||
flash[:notice] = 'Invalid Access!'
|
# flash[:notice] = 'Invalid Access!'
|
||||||
# return false
|
# # return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
# ActionController::Base are used by both Peatio controllers and
|
|
||||||
# Doorkeeper controllers.
|
|
||||||
class ActionController::Base
|
class ActionController::Base
|
||||||
|
|
||||||
before_action :lookup_domain, :set_language
|
before_action :lookup_domain, :set_locale
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def lookup_domain
|
def lookup_domain
|
||||||
if request.subdomain.present? && request.subdomain != "www"
|
if request.subdomain.present? && request.subdomain != "www"
|
||||||
from = request.subdomain.downcase + "." + request.domain.downcase
|
from = request.subdomain.downcase + "." + request.domain.downcase
|
||||||
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
|
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
|
||||||
if (!@license.nil?)
|
if (!@license.nil?)
|
||||||
# logger.info "Location - " + @license.name
|
logger.info "Location - " + @license.dbhost
|
||||||
ActiveRecord::Base.establish_connection(website_connection(@license))
|
ActiveRecord::Base.establish_connection(website_connection(@license))
|
||||||
# authenticate_session_token
|
# authenticate_session_token
|
||||||
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
|
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
|
||||||
|
|||||||
Reference in New Issue
Block a user