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 end #this is base api base controller to need to inherit. #all token authentication must be done here #response format must be set to JSON def current_company begin return Company.first rescue return nil end end def current_shop @current_shop end def current_login_employee @employee = Employee.find_by_token_session_and_shop_code(session[:session_token],@current_shop.shop_code) end def current_user @current_user ||= Employee.find_by_token_session_and_shop_code(session[:session_token],@current_shop.shop_code) if session[:session_token] end # Get current Cashiers def get_cashier @cashier = Employee.where("shop_code='#{@current_shop.shop_code}' and role = 'cashier' AND token_session <> ''") end #Shop Name in Navbor def shop_detail # shop_code ='262' # @shop = Shop.find_by_shop_code(shop_code) return @current_shop end #check order reservation used def order_reservation order_reserve = Lookup.where("shop_code='#{@current_shop.shop_code}'").collection_of('order_reservation') status = false if !order_reserve.empty? order_reserve.each do |order| if order[0] == 'OrderReservation' if order[1] == '1' status = true end end end end return status end #check bank integration used def bank_integration bank_integration = Lookup.where("shop_code='#{@current_shop.shop_code}'").collection_of('bank_integration') status = false if !bank_integration.empty? bank_integration.each do |bank| if bank[0] == 'Bank Integration' if bank[1] == '1' status = true end end end end return status end protected # Authenticate the user with token based authentication def authenticate authenticate_session_token || render_unauthorized end 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,@current_shop) if @user return true #Maybe log - login? end end end def authenticate_session_token shop_code = 262 if (shop_code) #@current_user = User.find_by(api_key: token) #Rails.logger.debug "token - " + token.to_s @current_shop = Shop.find_by_shop_code(shop_code) if @current_shop return true #Maybe log - login? end else @current_shop = Shop.first end end def render_unauthorized redirect_to root_path end end