Rails + HTTPS:过滤链停止为:ensure_proper_protocol呈现或重定向

时间:2013-09-04 15:46:03

标签: ruby-on-rails session https

我认为我的会话等因为我最近添加的代码以确保正确的协议(某些页面上的https和其他页面上的http)而搞砸了。我不确定。但我一直在我的日志中看到Filter chain halted as :ensure_proper_protocol rendered or redirected

`:ensure_proper_protocol方法指的是我在应用程序控制器中使用的方法:

    class ApplicationController < ActionController::Base

      CONTROLLERS_THAT_REQUIRE_SSL = ['check_out', 'users', 'sessions', 'registrations', 'addresses', 'catalog_requests', 'wine_club/orders']

      def ensure_proper_protocol
        unless Rails.env.development? || Rails.env.test?
          if request.format == "text/html" && request.protocol["https"] && !CONTROLLERS_THAT_REQUIRE_SSL.include?(params[:controller])
            redirect_to "http://" + request.host + request.path
          end
        end
      end

对于CONTROLLERS_THAT_REQUIRE_SSL中的控制器,我这样添加force_ssl

class CheckOutController < ApplicationController

   force_ssl
   ...

但是,我想知道协议中的切换是否会阻碍我的会话。我的会话问题和此错误有关吗?如何修复“过滤链暂停”错误?

我遇到的会话问题是设计和身份验证。我有一个前过滤器:authenticate_user!虽然我设法登录,但它似乎没有保持登录状态。问题是没有错误消息。它只是出于某种原因退出,我很确定这是因为重定向,因为我的应用程序控制器中有一个前置过滤器,看看用户是否已登录,并且它使用了设计辅助方法{{1}查看用户是否已登录。查看我的日志:

user_signed_in?

登录后我将其重定向到主页,这没关系,但之后它从http:// ... /重定向到https:// ... /,导致用户无法登录了。这可能是因为我的会话没有存储在数据库中,因为我将它们配置为?我在config / initializers / session_store.rb中有这一行:

Cache read: https://mysite-rc-preview.mysite.com/users/sign_in? Started POST "/users/sign_in" for 69.193.194.58 at 2013-09-04 12:09:38 -0400 Processing by SessionsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"bSYhk5t7VPBUTGkQuVyix8cb7Et7yojPE5m0V/g+do8=", "user"=>{"email"=>"emai@mysite.com", "password"=>"[FILTERED]"}, "commit"=>"Log in"} inside setup_cart. current_cart_id is 55005260 55005260 request.session_options[:id] = eecb979b4d7db5bfd28a3684ef7288d3 User Load (2.9ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'emai@mysite.com' LIMIT 1 (1.9ms) BEGIN (2.2ms) UPDATE "users" SET "last_sign_in_at" = '2013-09-04 16:07:44.987529', "current_sign_in_at" = '2013-09-04 16:09:39.171144', "sign_in_count" = 34, "updated_at" = '2013-09-04 16:09:39.174358' WHERE "users"."id" = 350492 (10.6ms) COMMIT begining get_or_create_cart session[:current_cart_id] is 55005260 Cart Load (2.3ms) SELECT "carts".* FROM "carts" WHERE "carts"."user_id" = 350492 AND "carts"."id" = 55005260 LIMIT 1 Cart Load (2.2ms) SELECT "carts".* FROM "carts" WHERE "carts"."user_id" = 350492 end of get_or_create_cart session[:current_cart_id] is 54993421 SeoContent Load (2.2ms) SELECT "seo_contents".* FROM "seo_contents" WHERE "seo_contents"."for_section" = 'default' LIMIT 1 There's no session[:cvv] variable Cart Load (2.2ms) SELECT "carts".* FROM "carts" WHERE "carts"."web_cart_session" = 'eecb979b4d7db5bfd28a3684ef7288d3' Cart Load (2.4ms) SELECT "carts".* FROM "carts" WHERE "carts"."user_id" = 350492 AND "carts"."name" = 'My Cart' LIMIT 1 CartItem Load (2.2ms) SELECT "cart_items".* FROM "cart_items" WHERE "cart_items"."cart_id" = 55005260 ORDER BY created_at (1.9ms) BEGIN SQL (2.4ms) DELETE FROM "carts" WHERE "carts"."id" = $1 [["id", 55005260]] (6.5ms) COMMIT Redirected to https://mysite-rc-preview.mysite.com/ Completed 302 Found in 408ms (ActiveRecord: 42.0ms) Cache read: https://mysite-rc-preview.mysite.com/? Started GET "/" for 69.193.194.58 at 2013-09-04 12:09:39 -0400 Processing by SiteController#index as HTML Redirected to http://mysite-rc-preview.mysite.com/ Filter chain halted as :ensure_proper_protocol rendered or redirected Completed 302 Found in 1ms (ActiveRecord: 0.0ms) Cache read: http://mysite-rc-preview.mysite.com/? Started GET "/" for 69.193.194.58 at 2013-09-04 12:09:39 -0400 Processing by SiteController#index as HTML inside setup_cart. current_cart_id is 54993421 54993421 request.session_options[:id] = 4bec2bbc42e8213be89aaf6431b41535 inside not user_signed_in? clause of setup_cart

0 个答案:

没有答案