简体   繁体   English

登录后Laravel重定向困境

[英]Laravel redirect dilemma after login

In route i have group of route , that are protected with filter backend_login 在路由中,我有一组路由,受过滤器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 在filter.php我有一个过滤器

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' 我试图通过添加到过滤器“ 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. 在filter.php中,我只需要检查用户是否已登录即可显示他的登录页面。 Then in the start of login function in AdminUserController, i will decide if i want to redirect him to backend/main or not. 然后在AdminUserController中的登录功能开始时,我将决定是否要将他重定向到后端/主要。 So the problem with infinite redirect loop would be solved. 因此,无限重定向循环的问题将得到解决。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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