注销使用HTTP基本认证在Laravel [英] Logging out with HTTP Basic Auth in Laravel

查看:382
本文介绍了注销使用HTTP基本认证在Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它由两种类型的用户的一个用户类,并且要允许不同的用户转到不同的页面。

I have one user class which consists of two types of users and want to allow different users to go to different pages.

我创建了一个过滤器如下:

I have created a filter as follows

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

这个想法是这样的:如果不是专家,它会注销并重定向到登录页面。如果是,它将简单地继续。
然而,验证::注销();不过注销用户。

The thought is this: If it's not an expert, it will logout and redirect to login page. If it is, it will simply continue. However, Auth::logout(); doesn't ever log out the user.

为什么不AUTH ::注销()的工作?我试着在应用程序放置在任何地方都无济于事。

Why is not Auth::logout() working? I've tried placing it anywhere in the app to no avail.

欢呼声

推荐答案

我有同样的问题,我真的无法注销当前用户......答案是简单的:Laravel不支持退出()验证::基本的()。

I had the same problem, I really couldn't logout the current user... And the answer is simple: Laravel doesn't support logout() with Auth::basic().

有办法解决它,但它不是很干净; <一href=\"https://www.google.nl/search?q=logout+basic\">https://www.google.nl/search?q=logout+basic

There are ways to fix it, but it's not very clean; https://www.google.nl/search?q=logout+basic

这篇关于注销使用HTTP基本认证在Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆