【问题标题】:Lumen session not working流明会话不起作用
【发布时间】:2015-05-22 11:15:42
【问题描述】:

我有一个简单的身份验证系统,描述为here

我有Auth::attempt 工作以检查用户的凭据是否正常。我从Auth::user() 取回用户。

if (Auth::attempt(array('email' => $email, 'password' => $password),true)) {
    // everything is fine and user is logged
    return view('login', ['user' => Auth::user()]);
}

然后,如果我在另一个控制器中尝试 Auth::check(),它总是返回 false

我发现我的会话不工作。简单的事情,例如 put 或 get describe here

那么如何激活 lumen 使用的会话呢?

我正在使用 nginx + php-fpm。

nginx/error.loglumen.log 没有错误。

谢谢

【问题讨论】:

    标签: session authentication lumen


    【解决方案1】:

    在您的 bootstrap/app.php 中,确保您已取消注释这些行:

    /*
    |--------------------------------------------------------------------------
    | Register Middleware
    |--------------------------------------------------------------------------
    |
    | Next, we will register the middleware with the application. These can
    | be global middleware that run before and after each request into a
    | route or middleware that'll be assigned to some specific routes.
    |
    */
    
    $app->middleware([
        'Illuminate\Cookie\Middleware\EncryptCookies',
        'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
        'Illuminate\Session\Middleware\StartSession',
        'Illuminate\View\Middleware\ShareErrorsFromSession',
        'Laravel\Lumen\Http\Middleware\VerifyCsrfToken',
    ]);
    

    【讨论】:

    • 谢谢。中间件是空的......现在即使在清除客户端 cookie 之后,VerifyCsrfToken.php 第 46 行中也有一个 TokenMismatchException。
    • 可能您忘记了表单中的 CSRF 令牌输入。阅读本文档laravel.com/docs/4.2/security
    • 是的,我的令牌是空的,我刚刚从您的链接中添加了 在文档中的 value 属性中。它的工作原理谢谢:)
    猜你喜欢
    • 2016-03-26
    • 2018-10-30
    • 1970-01-01
    • 2010-11-04
    • 2014-07-09
    • 2013-11-19
    相关资源
    最近更新 更多