This commit is contained in:
Myat Zin Wai Maw
2019-11-19 14:59:45 +06:30
parent 8b2da5e3da
commit 5a3f328789
16 changed files with 299 additions and 238 deletions

View File

@@ -1,6 +1,5 @@
module LoginVerification
extend ActiveSupport::Concern
included do
before_action :authenticate_session_token
helper_method :current_company,:current_shop, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :shop_detail
@@ -19,34 +18,37 @@ module LoginVerification
def current_shop
begin
return Shop.first
shop_code ='262'
@shop =Shop.find_by_shop_code(shop_code)
return @shop
rescue
return nil
end
end
def current_login_employee
@employee = Employee.find_by_token_session(session[:session_token])
@employee = @shop.employees.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]
@current_user ||= @shop.employees.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 <> ''")
@cashier = @shop.employees.where("role = 'cashier' AND token_session <> ''")
end
#Shop Name in Navbor
def shop_detail
@shop = Shop.first
shop_code ='262'
@shop = Shop.find_by_shop_code(shop_code)
end
#check order reservation used
def order_reservation
order_reserve = Lookup.collection_of('order_reservation')
order_reserve = @shop.lookups.collection_of('order_reservation')
status = false
if !order_reserve.empty?
order_reserve.each do |order|
@@ -62,7 +64,7 @@ module LoginVerification
#check bank integration used
def bank_integration
bank_integration = Lookup.collection_of('bank_integration')
bank_integration = @shop.lookups.collection_of('bank_integration')
status = false
if !bank_integration.empty?
bank_integration.each do |bank|
@@ -78,17 +80,17 @@ module LoginVerification
protected
# Authenticate the user with token based authentication
def authenticate
authenticate_session_token || render_unauthorized
def authenticate
authenticate_session_token || render_unauthorized
end
def authenticate_session_token
def authenticate_session_token
token = session[:session_token]
if (token)
#@current_user = User.find_by(api_key: token)
#Rails.logger.debug "token - " + token.to_s
@user = Employee.authenticate_by_token(token)
@user =Employee.authenticate_by_token(token,current_shop)
if @user
return true
#Maybe log - login?