我有一个Laravel 4.1应用程序使用雄辩的身份验证驱动程序和数据库会话驱动程序。我的身份验证控制器正在成功运行Auth :: attempt并重定向到新页面。但是,一旦在新页面上认证会话数据似乎消失了。我有一个auth过滤器在重定向页面上运行,并且失败,然后再次将用户重定向到登录页面。用户永远不会通过登录页面。Laravel 4.1身份验证会话数据不会持续请求
这里是我的session.php文件:
<?php
return array(
'driver' => 'database',
'lifetime' => 120,
'expire_on_close' => true,
'files' => storage_path().'/sessions',
'connection' => 'mysql',
'table' => 'sessions',
'lottery' => array(2, 100),
'cookie' => 'laravel_session',
'path' => '/',
'domain' => null,
'secure' => false,
);
我的课程表模式:
CREATE TABLE `sessions` (
`id` varchar(32) NOT NULL,
`payload` text NOT NULL,
`last_activity` int(11) NOT NULL,
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
我的身份验证过滤器:
Route::filter('auth', function()
{
if (Auth::guest()) {
if (Request::ajax()) {
return Response::make("Your session has timed out. Please sign in again.", 401);
} else {
return Redirect::guest('login');
}
}
});
的Auth::guest()
调用的身份验证过滤器总是返回false。
我在Illuminate/Auth/Guard.php的user()
方法中添加了一些日志记录,发现在登录表单的POST中,认证数据在调用user()方法时处于会话中。但是,当从重定向的auth筛选器调用它时(Auth :: guest()间接调用user()方法),会话数据不见了。
这里是用户()方法,以供参考:
public function user()
{
if ($this->loggedOut) return;
// If we have already retrieved the user for the current request we can just
// return it back immediately. We do not want to pull the user data every
// request into the method because that would tremendously slow an app.
if (! is_null($this->user))
{
return $this->user;
}
$id = $this->session->get($this->getName());
// First we will try to load the user using the identifier in the session if
// one exists. Otherwise we will check for a "remember me" cookie in this
// request, and if one exists, attempt to retrieve the user using that.
$user = null;
if (! is_null($id))
{
$user = $this->provider->retrieveByID($id);
}
// If the user is null, but we decrypt a "recaller" cookie we can attempt to
// pull the user data on that cookie which serves as a remember cookie on
// the application. Once we have a user we can return it to the caller.
$recaller = $this->getRecaller();
if (is_null($user) && ! is_null($recaller))
{
$user = $this->getUserByRecaller($recaller);
}
return $this->user = $user;
}
当用户()从AUTH滤波器调用,$this->loggedOut
是假的,但$this->user
为空并$this->session->get($this->getName())
返回NULL。
在任何时候都不会出现Auth :: logout()被调用。
你刚刚救了我一天,你是怎么找到它的? –
如果我没有记错,这已经得到了对垃圾邮件日志消息遍布Laravel代码点,并注意到,被记录的会话ID比在我的分贝会话ID长... – ralbatross