douqiang3768 2013-08-30 13:37
浏览 28
已采纳

Laravel 4登录重定向

I do not want to show login page after login in laravel 4. If a logged in user want to visit login page it should redirect to homepage('/'). I am using Sentry for authentication.

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');
    }
}

After successful login if, if login page is requested it still shows the login page

  • 写回答

1条回答 默认 最新

  • dsebywql016137 2013-09-01 16:18
    关注

    If you're using Laravel's default guest filter, it will not work, because the default guest filter does not check if your Sentry user is logged in.

    Try this instead:

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

    In your routes.php, the filter is already being applied to the login route, so things should work this way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址