2014-09-23 95 views
0

我在嘗試創建自定義過濾器時遇到了一些問題。我的目標是在允許他們訪問組內定義的路由之前,確保已通過身份驗證的用戶符合特定條件。自定義路由過濾器忽略重定向

現在它只是繼續/頁面沒有問題,即使我已經確認滿足這些條件之一。它忽略了我的重定向。

routes.php文件

Route::group(array('before' => 'registered'), function() 
{ 
    Route::get('/page', array('as' => 'page', 'uses' => '[email protected]')); 
}); 

filters.php

Route::filter('registered', function() 
{ 
    if(Auth::check()) 
    { 
     if(!Auth::user()->confirmed()) 
     { 
      return Redirect::route('signup.send.confirmation')->with('alert-warning', 'You must confirm your email address before continuing. Fill out the form below if you need a new activation email. Thank you!'); 
     } 

     if(!Auth::user()->registered) 
     { 
      return Redirect::route('signup.profile')->with('alert-warning', 'You must fill out the following information before continuing. Thank you!'); 
     } 
    } 
}); 

任何幫助,不勝感激!謝謝!

回答

0

我認爲你的過濾器存在一些問題。看來你允許未註冊的用戶去這條路線。我想你需要的是:

Route::filter('registered', function() 
{ 
    if(!Auth::check()) { 
      return Redirect::route('signup.profile')->with('alert-warning', 'You must fill out the following information before continuing. Thank you!'); 
    } 

    else 
    { 
     if(!Auth::user()->confirmed()) 
     { 
      return Redirect::route('signup.send.confirmation')->with('alert-warning', 'You must confirm your email address before continuing. Fill out the form below if you need a new activation email. Thank you!'); 
     } 
    } 
}); 

如果不解決這個問題,你應該提供更多的細節,你特別是如何檢查這些條件都爲真,如果你確定這個過濾器被觸發。

0

我不知道如何解釋它,但現在它正在工作,因爲它是寫在我原來的帖子。我一定忽略了某個地方的測試。

訪問/頁面不需要認證。但是,如果他們通過身份驗證,我想確保他們已經完成了完成賬戶/配置文件所需的所有步驟。這是過濾器的原因,如果它們未經過身份驗證,則不會重定向它們。

如果您正在尋找自定義過濾器,我的原始問題的作品!對不起浪費任何人時間。