[英]Laravel 4 login redirect
在laravel 4中登錄后,我不想顯示登錄頁面。如果登錄的用戶想要訪問登錄頁面,則應重定向到homepage('/')。 我正在使用Sentry進行身份驗證。
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', 'AuthController@postLogin');
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');
}
}
成功登錄后,如果仍要求登錄頁面,則仍顯示登錄頁面
如果您使用的是Laravel的默認guest
過濾器,它將無法使用,因為默認guest
過濾器不會檢查您的Sentry用戶是否已登錄。
嘗試以下方法:
Route::filter(
'filter', function () {
if (Sentry::check()) {
return Redirect::to('/');
}
}
在您的routes.php中,過濾器已經被應用到登錄路由,因此事情應該以這種方式進行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.