From 0b869ccb89547f066cf7cfaceddb83f5419b396c Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 6 Apr 2018 12:00:45 +0630 Subject: [PATCH 1/7] cehck mobile --- app/controllers/base_origami_controller.rb | 29 +++++++++++++++------- app/controllers/origami/home_controller.rb | 1 - 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index b627ae01..64441590 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -16,8 +16,23 @@ class BaseOrigamiController < ActionController::Base end def check_user - if current_user.nil? - redirect_to root_path + token_status = false + authenticate_with_http_token do |token, options| + if token + token_status = true + session[:webview] = true + session[:session_token] = token + end + end + + if token_status + if current_user.nil? + redirect_to root_path + end + else + if current_user.nil? + redirect_to root_path + end end end @@ -38,13 +53,9 @@ class BaseOrigamiController < ActionController::Base #check webview def check_mobile status = false - authenticate_with_http_token do |token, options| - if token - session[:webview] = true - end - session[:session_token] = token - end - + puts "check mobile" + puts session[:session_token] + puts session[:webview] if session[:webview] && request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i status = true end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 5ed006a1..79a86ea9 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -7,7 +7,6 @@ class Origami::HomeController < BaseOrigamiController if check_mobile @webview = true end - @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) From 818f441529e41959d2e118fa1a6efbe4f1c23213 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 6 Apr 2018 13:15:32 +0630 Subject: [PATCH 2/7] check mobile --- app/controllers/base_origami_controller.rb | 6 +----- app/controllers/origami/home_controller.rb | 10 ++-------- app/views/origami/home/index.html.erb | 4 ++++ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index 64441590..86fb4ec3 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -25,11 +25,7 @@ class BaseOrigamiController < ActionController::Base end end - if token_status - if current_user.nil? - redirect_to root_path - end - else + if !token_status if current_user.nil? redirect_to root_path end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 79a86ea9..8e00ef80 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -3,10 +3,7 @@ class Origami::HomeController < BaseOrigamiController before_action :set_dining, only: [:show] def index - @webview = false - if check_mobile - @webview = true - end + @webview = check_mobile @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @@ -18,10 +15,7 @@ class Origami::HomeController < BaseOrigamiController # origami table detail def show - @webview = false - if check_mobile - @webview = true - end + @webview = check_mobile @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 38f0cc79..5e280697 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -140,7 +140,11 @@