Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用Desive直接链接登录,但已停止筛选链_Ruby On Rails_Ruby On Rails 3_Session_Devise - Fatal编程技术网

Ruby on rails 使用Desive直接链接登录,但已停止筛选链

Ruby on rails 使用Desive直接链接登录,但已停止筛选链,ruby-on-rails,ruby-on-rails-3,session,devise,Ruby On Rails,Ruby On Rails 3,Session,Devise,因此,我尝试使用身份验证令牌进行直接登录链接,但我在服务器日志中得到了过滤器链暂停,原因是:在\u令牌\u身份验证呈现或重定向后 class ApplicationController < ActionController::Base protect_from_forgery before_filter :store_location before_filter :authenticate_user! before_filter :a

因此,我尝试使用身份验证令牌进行直接登录链接,但我在服务器日志中得到了
过滤器链暂停,原因是:在\u令牌\u身份验证呈现或重定向后

    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

此消息仅表示在一个before筛选器中呈现了模板或发生了重定向。在您的情况下,
after\u token\u authentication
过滤器重定向到
contractor\u list\u galleries\u path
,从而结束了before过滤器链。此消息不是错误,显示此消息只是为了告诉您重定向发生在before筛选器中,而不是实际操作。

此消息仅表示在before筛选器中的一个筛选器中呈现了模板或发生了重定向。在您的情况下,
after\u token\u authentication
过滤器重定向到
contractor\u list\u galleries\u path
,从而结束了before过滤器链。此消息不是错误,显示此消息只是为了告诉您重定向发生在before筛选器中,而不是实际操作。

将其从
@user
更改为
@current\u user
中的
@after\u token\u authentication
。你是
authenticate\u用户
调用需要根据此处设置
@current\u user

在\u令牌\u身份验证后将其从
@user
更改为
@current\u user
。你是
authenticate\u用户
调用需要根据此处设置
@current\u user

,但为什么用户被重定向到登录屏幕?我确信,在重定向之前,用户已通过身份验证,但他仍然获得401未经授权。重定向发生在从
承包商列表\u画廊\u路径
页面重定向之后,因此我无法确定到底发生了什么。可能未设置approved属性,因为我没有看到对
@user.save
行执行另一个更新sql查询。approved已在0处。所以它不会更新它。但我不明白为什么在重定向中,用户不必获得进入画廊的权限,即使我登录了他,然后第二次是after_token_身份验证方法,他不再登录,但为什么用户被重定向到登录屏幕?我确信,在重定向之前,用户已通过身份验证,但他仍然获得401未经授权。重定向发生在从
承包商列表\u画廊\u路径
页面重定向之后,因此我无法确定到底发生了什么。可能未设置approved属性,因为我没有看到对
@user.save
行执行另一个更新sql查询。approved已在0处。所以它不会更新它。但我不明白为什么在重定向中,用户不必获得进入画廊的权限,即使我登录了他,然后第二次它是after_token_身份验证方法,他没有登录,所以我必须添加:
sign_in@current_user,:bypass=>true
,所以我必须添加:
sign_in@current_user,:bypass=>true
请检查@current_user.save是否返回真值或假值,如果返回假值,请检查返回假值的原因。这应该是真的,然后它就会工作。请检查@current_user.save是否返回真值或假值,如果是假值,请检查为什么返回假值。这应该是真的,然后它就会起作用。
    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)