我有一个视图来输入一个帐户,然后将其称为控制器,在该控制器中验证数据,然后使用身份验证方法将其保存
public function doLogin(){
$rules = array(
'email' => 'required|email',
'password' => 'required'
);
$validator = Validator::make(Input::all(), $rules);
//dd(Input::all());
if($validator->fails()){
return Redirect::to('usuarios')->withErrors($validator)->withInput(Input::except('password'));
}else{
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if(Auth::attempt($userdata)){
return View::make('principal');
}else{
return Redirect::to('usuarios');
}
}
}
我也有退出会议的功能
Route::get('usuarios/logout', function(){
Auth::logout();
return Redirect::to('usuarios'); //login page
})->before('auth');
问题是,当我按下浏览器的后退按钮时,我可以毫无问题地使用应用程序,而无需进行身份验证。
路线
Route::get('usuarios', function(){
return View::make('login');
})->before('guest');
Route::get('usuarios/view', function(){
$usuarios = Usuario::paginate(5);
return View::make('viewusuario', array('usuarios' => $usuarios));
})->before('auth');
Route::get('usuario/create', function(){
return View::make('formusuario');
})->before('auth');
筛选
Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::guest('usuarios'); //login page
});
Route::filter('guest', function()
{
if (Auth::check()){
return View::make('principal'); //home page
}
});
我该如何解决?
问题与浏览器缓存有关,与Laravel没有关系。
要处理浏览器缓存,您可以在一个启动文件或服务提供商中使用以下代码:
App::after(function($request, $response)
{
$response->headers->set('Cache-Control','nocache, no-store, max-age=0, must-revalidate');
$response->headers->set('Pragma','no-cache');
$response->headers->set('Expires','Fri, 01 Jan 1990 00:00:00 GMT');
});
在这里,我们只是使用应用程序事件在Laravel中修改每个响应。
有人说这适用于所有Web浏览器,但不适用于IE。因此,对于IE,您应该在布局中添加一堆meta标签:
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="cache-control" content="must-revalidate" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句