直接链接登录与设计,但过滤链停止

时间:2013-09-21 04:28:15

标签: ruby-on-rails ruby-on-rails-3 session devise

所以,我尝试使用身份验证令牌进行直接登录链接,但我在服务器日志中获取Filter chain halted as :after_token_authentication rendered or redirected

    class ApplicationController < ActionController::Base
      protect_from_forgery
      before_filter :store_location
      before_filter :authenticate_user!
      before_filter :after_token_authentication
      check_authorization :unless => :devise_controller?

      rescue_from CanCan::AccessDenied do |exception|
        session[:previous_url] = nil
        redirect_to root_url
      end


      def store_location
        # reset_session
        # store last url - this is needed for post-login redirect to whatever the user last visited.

        if (request.fullpath != "/user/sign_in" && \
            request.fullpath != "/user/sign_up" && \
            request.fullpath != "/user/password" && \
            !request.fullpath.include?("/user") && \
            !request.fullpath.include?("/admin") && \
            !request.xhr?) # don't store ajax calls
          session[:previous_url] = request.fullpath
        end
      end

      def after_sign_in_path_for(resource)
        if current_user.admin?
          admin_dashboard_path
        elsif current_user.contractor?
          if current_user.contractor.business_name == 'Test Devise'
            'url'
          else
            contractor_dashboard_path
          end
        else
          session[:previous_url] || homeowner_service_requests_path
        end
      end

      #generates 6-digit random password (a-z, 0-9) for sending to users when BuildZoom creates user account after they express interest in a service request, leave a review
      def generate_temporary_password
        rand(36**6).to_s(36)
      end




      protected


      def after_token_authentication
    if params[:authentication_key].present?
      @user = User.find_by_authentication_token(params[:authentication_key])
      sign_in @user if @user
      welcome = @user.approved.eql?(7) and @user.type.eql?(2)
      @user.approved = 0
      @user.save
      unless welcome
        redirect_to root_path
      else
        redirect_to contractor_welcome_path
      end
    elsif params[:auth_token].present? && params[:location] == "galleries"
       @current_user = User.find_by_authentication_token(params[:auth_token])
        sign_in @current_user if @current_user
        @current_user.approved = 0
        @current_user.save
        debugger
      redirect_to contractor_list_galleries_path
    end
  end

      def after_sign_out_path_for(resource)
        'url'
      end
    end

这是服务器日志:

    Started GET "/?auth_token=uN8QFMsocpDyhWKCx9QN&location=galleries" for 127.0.0.1 at 2013-09-20 22:38:37 -0700
Processing by PagesController#home as HTML
  Parameters: {"auth_token"=>"uN8QFMsocpDyhWKCx9QN", "location"=>"galleries"}
Geokit is using the domain:
  User Load (189.2ms)  SELECT `users`.* FROM `users` WHERE `users`.`authentication_token` = 'uN8QFMsocpDyhWKCx9QN' LIMIT 1
   (109.5ms)  BEGIN
   (111.7ms)  UPDATE `users` SET `last_sign_in_at` = '2013-09-21 05:38:28', `current_sign_in_at` = '2013-09-21 05:38:38', `sign_in_count` = 61, `updated_at` = '2013-09-21 05:38:38' WHERE `users`.`uid` = 149407
   (95.6ms)  COMMIT
  User Load (184.3ms)  SELECT `users`.* FROM `users` WHERE `users`.`authentication_token` = 'uN8QFMsocpDyhWKCx9QN' LIMIT 1
   (93.3ms)  BEGIN
   (109.5ms)  COMMIT
Redirected to http://0.0.0.0:3000/contractor/galleries
Filter chain halted as :after_token_authentication rendered or redirected
Completed 302 Found in 10884ms (ActiveRecord: 893.2ms)


Started GET "/contractor/galleries" for 127.0.0.1 at 2013-09-20 22:38:48 -0700
Processing by Contractor::ContractorGalleriesController#index as HTML
Geokit is using the domain:
Completed 401 Unauthorized in 1ms


Started GET "/contractor/galleries" for 127.0.0.1 at 2013-09-20 22:38:49 -0700
Processing by Contractor::ContractorGalleriesController#index as HTML
Geokit is using the domain:
Completed 401 Unauthorized in 1ms


Started GET "/user/sign_in" for 127.0.0.1 at 2013-09-20 22:38:49 -0700
Processing by Devise::SessionsController#new as HTML
Geokit is using the domain:
  Rendered devise/shared/_links.erb (0.5ms)
  Rendered devise/sessions/new.html.erb within layouts/application (3.7ms)
  Rendered shared/_mixpanel.html.erb (0.2ms)
  Rendered layouts/_head.html.erb (12.4ms)
  Rendered layouts/_navigation.html.erb (0.6ms)
  Rendered layouts/_messages.html.erb (0.1ms)
  Rendered shared/_olark (0.0ms)
  Rendered layouts/_footer.html.erb (1.2ms)
Completed 200 OK in 64ms (Views: 62.5ms | ActiveRecord: 0.0ms)


Started GET "/user/sign_in" for 127.0.0.1 at 2013-09-20 22:38:49 -0700
Processing by Devise::SessionsController#new as HTML
Geokit is using the domain:
  Rendered devise/shared/_links.erb (0.5ms)
  Rendered devise/sessions/new.html.erb within layouts/application (4.8ms)
  Rendered shared/_mixpanel.html.erb (0.1ms)
  Rendered layouts/_head.html.erb (11.5ms)
  Rendered layouts/_navigation.html.erb (0.6ms)
  Rendered layouts/_messages.html.erb (0.0ms)
  Rendered shared/_olark (0.0ms)
  Rendered layouts/_footer.html.erb (1.1ms)
Completed 200 OK in 113ms (Views: 111.4ms | ActiveRecord: 0.0ms)

2 个答案:

答案 0 :(得分:1)

@user中将其从@current_user更改为after_token_authentication。您需要authenticate_user!@current_user来电{{1}}来设置where is devise implementation of "authenticate_user!" method?

答案 1 :(得分:0)

此消息仅表示在您之前的一个过滤器中呈现模板或发生重定向。在您的情况下,after_token_authentication过滤器重定向到contractor_list_galleries_path,结束了过滤器之前的链。此消息不是错误,只是显示它告诉您重定向发生在前一个过滤器而不是实际操作。