2013-08-30 198 views
1

我不想在laravel 4登錄後顯示登錄頁面。如果登錄用戶想訪問登錄頁面,它應該重定向到主頁('/')。我正在使用Sentry進行身份驗證。Laravel 4登錄重定向

filter.php

Route::filter(
    'auth', function() { 
    if (!Sentry::check()) { 
     return Redirect::to('login'); 
    } 
} 

routes.php文件

Route::get('login', array('as' => 'login', function() { 
return View::make('login'); 
}))->before('guest'); 

Route::post('login', '[email protected]'); 

AuthController.php

function postLogin() { 
    try { 
     // Set login credentials 
     $credentials = array(
      'email' => Input::get('email'), 'password' => Input::get('password') 
     ); 

     // Try to authenticate the user 
     $user = Sentry::authenticate($credentials, false); 
     if ($user) { 
      return Redirect::to('/'); 
     } 
    } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { 
     return Redirect::to('login')->withErrors('Login field is required'); 
    } 
} 

成功登錄後,如果,如果請求登錄頁面,它仍然顯示登錄頁面

+0

請出示您的'客人'過濾器。 – ciruvan

+0

它的laravel的默認值。 –

回答

5

如果喲你就像使用Laravel默認guest過濾器,它不會工作,因爲如果你的哨兵用戶登錄默認guest過濾器不檢查

試試這個:

Route::filter(
    'filter', function() { 
    if (Sentry::check()) { 
     return Redirect::to('/'); 
    } 
} 

在你routes.php文件,過濾器已經被應用到登錄路線,所以事情應該這樣工作。