From df82627bd1058289dffc7b331e075f0f0e558b2d Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Tue, 20 May 2014 15:47:00 +1000 Subject: [PATCH] Starting to rework login behaviour when hitting /admin --- app/controllers/checkout_controller.rb | 6 +++++- .../spree/admin/base_controller_decorator.rb | 2 +- .../spree/admin/overview_controller_decorator.rb | 15 ++++++++++++++- config/routes.rb | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 2bedcf5b6b..3879f16741 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -26,7 +26,11 @@ class CheckoutController < Spree::CheckoutController if @order.next state_callback(:after) else - flash[:error] = @order.errors.full_messages.to_sentence + unless @order.errors.empty? + flash[:error] = @order.errors.full_messages.to_sentence + else + flash[:error] = t(:payment_processing_failed) + end update_failed return end diff --git a/app/controllers/spree/admin/base_controller_decorator.rb b/app/controllers/spree/admin/base_controller_decorator.rb index 8e876513fa..df7076345f 100644 --- a/app/controllers/spree/admin/base_controller_decorator.rb +++ b/app/controllers/spree/admin/base_controller_decorator.rb @@ -11,4 +11,4 @@ Spree::Admin::BaseController.class_eval do authorize! :admin, record authorize! action, record end -end \ No newline at end of file +end diff --git a/app/controllers/spree/admin/overview_controller_decorator.rb b/app/controllers/spree/admin/overview_controller_decorator.rb index dd53294f6f..5c96901c1d 100644 --- a/app/controllers/spree/admin/overview_controller_decorator.rb +++ b/app/controllers/spree/admin/overview_controller_decorator.rb @@ -4,4 +4,17 @@ Spree::Admin::OverviewController.class_eval do @product_count = Spree::Product.active.managed_by(spree_current_user).count @order_cycle_count = OrderCycle.active.managed_by(spree_current_user).count end -end \ No newline at end of file + + # This is in Spree::Core::ControllerHelpers::Auth + # But you can't easily reopen modules in Ruby + def unauthorized + if try_spree_current_user + flash[:error] = t(:authorization_failure) + redirect_to '/unauthorized' + else + store_location + url = respond_to?(:spree_login_path) ? spree_login_path : root_path + redirect_to url + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 69a3c99d56..310d1d9e4d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Openfoodnetwork::Application.routes.draw do root :to => 'home#index' + get "/#/login", to: "home#index", as: :spree_login + resource :shop, controller: "shop" do get :products post :order_cycle