当用户检查选项并登录时,我正在尝试更改记住我的 cookie 的到期时间,但是当我运行此代码时,到期时间不会改变。在 Laravel 4 中我需要做什么来解决这个问题?
更具体地说,我想要做的是将过期时间设置为 12 小时。我尝试了 App:after 方法,但每次运行该代码时,它都会将现有的 cookie 刷新回原来的 12 小时。我将如何让它运行以使其不会那样做?
登录控制器.php
class LoginController extends BaseController {
public function __construct()
{
$this->beforeFilter('csrf', array('on' => 'post'));
}
public function getIndex()
{
if (Auth::check()) {
return Redirect::action('HomeController@usersIndex')
->with('message', 'You are already logged in.');
}
return View::make('guests.login');
}
public function postIndex()
{
$validation = User::validateForm(Input::all());
if ($validation->passes()) {
$user = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
// Try to log the user in.
if (Auth::attempt($user, Input::has('remember_me'))) {
return Redirect::to('/');
}
return Redirect::to('login')
->withErrors(array('password' => 'The username or password you entered is incorrect.'))
->withInput(Input::except('password'));
}
return Redirect::to('login')
->withErrors($validation)
->withInput(Input::except('password'));
}
}
过滤器.php
App::after(function($request, $response) {
if ( Auth::check()){
$ckname=Auth::getRecallerName(); //Get the name of the cookie, where remember me expiration time is stored
$ckval=Cookie::get($ckname); //Get the value of the cookie
return $response->withCookie(Cookie::make($ckname,$ckval,720)); //change the expiration time
}
});
路由.php
Route::get('/', 'HomeController@usersIndex');
Route::get('logout', 'HomeController@logout');
Route::controller('login', 'LoginController');
Route::controller('register', 'RegistrationController');
Route::controller('password', 'PasswordController');