我有一個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