2016-10-28 2 views
0

私のサーバ上のある特定のユーザアカウントでログインしようとすると、デバッグ方法を実際には理解できない302 Redirectが表示されます。ここでRailsログインで302リダイレクトを診断する

がログ出力されます:だから

I, [2016-10-28T11:58:44.863837 #29152] INFO -- : Processing by Devise::SessionsController#create as HTML 
I, [2016-10-28T11:58:44.864715 #29152] INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"uWIySEF1QN/2wg+0YpOzGDOPBcFKYtdiJAvuvwrZ5uE=", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}} 
I, [2016-10-28T11:58:45.349905 #29152] INFO -- : Redirected to https://www.myserver.com/ 
I, [2016-10-28T11:58:45.350241 #29152] INFO -- : Completed 302 Found in 485ms (ActiveRecord: 247.6ms) 
I, [2016-10-28T11:58:45.669553 #29152] INFO -- : Started GET "/" for 12.228.244.22 at 2016-10-28 11:58:45 -0500 
I, [2016-10-28T11:58:45.673424 #29152] INFO -- : Processing by PagesController#home as HTML 
I, [2016-10-28T11:58:46.044037 #29152] INFO -- : Redirected to https://www.myserver.com/ 
I, [2016-10-28T11:58:46.044249 #29152] INFO -- : Completed 302 Found in 371ms (ActiveRecord: 70.1ms) 
I, [2016-10-28T11:58:46.315053 #29152] INFO -- : Started GET "/" for 12.228.244.22 at 2016-10-28 11:58:46 -0500 
I, [2016-10-28T11:58:46.317108 #29152] INFO -- : Processing by PagesController#home as HTML 
I, [2016-10-28T11:58:46.516814 #29152] INFO -- : Redirected to https://www.myserver.com/ 
I, [2016-10-28T11:58:46.517015 #29152] INFO -- : Completed 302 Found in 200ms (ActiveRecord: 48.6ms) 
I, [2016-10-28T11:58:46.727266 #29152] INFO -- : Started GET "/" for 12.228.244.22 at 2016-10-28 11:58:46 -0500 

、ユーザーがログインすることができます表示され、障害は本当にトンを持っていないPagesController#home方法、である:

def get_company_and_locations 
    @company = current_user.company 
    @devices = Device.where(company_id: @company.id).order(name: :asc) 
    @locations = if @company 
     current_user.company_locations.order(:name) 
    else 
     [] 
    end 
end 

def get_network_hosts 
    get_company_and_locations 
    @network_hosts = [] 
    @company.locations.each do |l| 
     l.network_hosts.each do |h| 
     @network_hosts.push(h) 
     end 
    end 
end 

def get_network_hosts_at_risk 
    get_company_and_locations 
    @network_hosts_at_risk = [] 
    @company.locations.each do |l| 
     l.network_hosts.each do |h| 
     next if h.security_percentage == nil 
     if h.security_percentage < 99 
      @network_hosts_at_risk.push(h) 
     end 
     end 
    end 
end 

def get_company_issues 
    get_company_and_locations 
    get_network_hosts_at_risk 

    @issues = Set.new 
    @network_hosts_at_risk.each do |h| 
     if h.last_test 
     results = h.last_test.results 
     results.each do |r| 
      if r.ignore_date == nil 
      r.ignore_date = 30.days.from_now 
      r.save 
      @issues.add?(r.issue) 
      else 
      @issues.add?(r.issue) 
      end 
     end 
     end 
    end 
end 
class PagesController < ApplicationController 

    def home 
    if current_user && current_user.company 
     get_company_and_locations 
     get_network_hosts 
     get_network_hosts_at_risk 
     @network_hosts_snip = @network_hosts_at_risk.sort_by{ |h| -h.security_percentage }.first(5) 
     get_company_issues 
     @issues = @issues.sort_by{ |i| -i.cvss_score }.first(5) 
     @deferred_issues = @company.deferred_issues.last(5) 
     @deferred_hosts = @company.deferred_hosts.last(5) 
    else 
     redirect_to new_company_path 
    end 
    end 

    def vm_download 
    get_company_and_locations 
    end 
end 

方法はPagesController#homeのトップですが、いくつかの時間のための場所にされていると前に問題を起こしたことがないヘルパーです

views/pages/home.html.erbは比較的長いので、誰かがそれが問題ではないと思わない限り、ここで投稿を延期します。

だから、どこからここに行きますか?302

+0

ユーザーがログインした後はどうなりますか?彼らは無限のリダイレクトループなどで立ち往生しますか? – SomeSchmo

+0

@Roccoはい、それは最終的にタイムアウトし、ブラウザウィンドウに「リダイレクトされた回数が多い」というメッセージが表示されます – Godzilla74

+0

私はあなたが明らかに何かを除外し、current_userに会社があり、 'redirect_to new_company_path' - それはifブロックに入りますか? – David

答えて

0

することができますこれを解決するためにすべての人のコラボレーションをまとめると:

  • は、ユーザーの資格情報が正しいことを確認してください。
  • 承認ハンドラを使用している場合は、ユーザーが現在のリソースにアクセスできることを確認してください。たとえば、 'cancancan'宝石を使用する場合は、あなたのability.rbファイルをチェックする必要があります。問題は
0

工夫宝石は302がスローされます、特定の環境でのみ再現可能である場合

  • このような「てこ」、「byebug」または「better_errors」
  • チェックENV変数としてデバッグ宝石の問題を解決して下さい複数のケースでのリダイレクト。

    (たとえば、確認されていないユーザーは302のリダイレクトを取得します)

  • 関連する問題