简体   繁体   中英

Laravel redirect dilemma after login

In route i have group of route , that are protected with filter backend_login

Route::group(array('prefix' => 'backend', 'before' => 'backend_auth'), function() {

    Route::get('/','AdminMainController@index');
    Route::get('/main', 'AdminMainController@index');
    Route::get('/logout', 'UserMainController');
});


Route::any('backend/login', array('as' => 'backend_login', 'uses' =>'AdminUserController@login'));

in filter.php i have a filter

Route::filter('backend_auth', function(){
    if ( ! Sentry::check()) return Redirect::route('backend_login');
});

The problem is when user is already loginned , he can still go back to login page. I tried to prevent it by adding to filter 'backend_auth'

Route::filter('backend_auth', function(){
    if ( ! Sentry::check()) return Redirect::route('backend_login');
    else {
         return Redirect::to('backend/main');
    }
});

But then i got an redirect loop. Actually , redirecting to backend/main after login is what i want, but i can't make it work properly. Any idea how to solve this problem ?

I have found the answer. In the filter.php i just have to check if the user is loginned, to show him login page. Then in the start of login function in AdminUserController, i will decide if i want to redirect him to backend/main or not. So the problem with infinite redirect loop would be solved.

  if (Sentry::check()) return Redirect::route('backend_main');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM