php - 在 Laravel 中使用 HTTP Basic Auth 注销

标签 php laravel laravel-4 authorization basic-authentication

我有一个用户类,它由两种类型的用户组成,我想允许不同的用户访问不同的页面。

我创建了一个过滤器如下

Route::filter('isExpert', function()
{
    $userIsExpert = 0;
    $userIsLoggedIn = Auth::check();
    if ($userIsLoggedIn && Auth::user()->role == 'expert') {
    $userIsExpert = 1;
    }

    Log::info('Logged in: ' . $userIsLoggedIn . ' && Expert: ' . $userIsExpert);
    if ($userIsExpert == 0)
    {
        Log::info('should be logging out now.');
        Auth::logout();
        return Auth::basic();
    }
});

像这样路由

Route::get('/winners', array('before' => 'isExpert', function()
{
    $winners = DB::select('select * from winners');
    return View::make('winners.index')->with('winners',$winners);
}));

思路是这样的:如果不是专家,它会注销并重定向到登录页面。如果是,它将继续。 但是, Auth::logout();永远不会注销用户。

问题

为什么 Auth::logout() 不工作?我试过将它放在应用程序中的任何位置,但无济于事。

干杯

最佳答案

我遇到了同样的问题,我真的无法注销当前用户...答案很简单:Laravel 不支持使用 Auth::basic() 的 logout()。

修复方法有,但不是很干净; https://www.google.nl/search?q=logout+basic

关于php - 在 Laravel 中使用 HTTP Basic Auth 注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18295994/

相关文章:

php - 如果成员不再属于组,则从数据库中删除行

regex - 如何在 Laravel 4 中为 Route::group 设置正则表达式参数约束?

php - 使用准备语句时如何创建多维数组?

php - 日期时间计算标准化

laravel - 由命令/计划触发时找不到通知图像

Laravel 工作台 Composer 更新

php - Laravel 4 - 在构建集合时将 where 子句附加到关系的 Eloquent 方式

php - 将确认密码与散列密码进行比较 |拉维尔 4

php - Laravel 4 多对多从两个表中获取所有数据

php - CodeSniffer 嗅探用于为 PHP 代码生成依赖关系图?