Laravel身份验证和过滤器
我需要帮助,有人可以告诉我,如果我的工作是正确的认证用户配置文件?我有以下文件: 文件routes.php(本例中我只使用了两个组)Laravel身份验证和过滤器,laravel,authentication,filter,Laravel,Authentication,Filter,我需要帮助,有人可以告诉我,如果我的工作是正确的认证用户配置文件?我有以下文件: 文件routes.php(本例中我只使用了两个组) file filters.php <?php Route::filter('adminFilter', function($route, $request) { if (Auth::user()->profile != 1) { return Redirect::to('/l
file filters.php
<?php
Route::filter('adminFilter', function($route, $request)
{
if (Auth::user()->profile != 1)
{
return Redirect::to('/logout');
}
});
Route::filter('commonUserFilter',function($route, $request)
{
if (Auth::user()->profile != 2)
{
return Redirect::to('/logout');
}
});
?>
文件AuthController.php
<?php
public function showLogin()
{
return View::make('login');
}
public function postLogin()
{
//Get user data from login form
$user = array(
'user' => Input::get('username'),
'password' => Input::get('password'));
if(Auth::attempt($user,true))
{
switch (Auth::user()->profile)
{
case 1:
//home admin
return Redirect::to('/adminHomePage');
break;
case 2:
//home common user
return Redirect::to('/commonUserPage');
break;
}
}
else
{
return Redirect::to('login')
->with('mensaje_error','Incorrect data.')
->withInput();
}
}
public function logOut()
{
Auth::logout();
return Redirect::to('/login')
->with('mensaje_error', 'Your session was closed.');
}
?>
一个安全问题(如果您使用的是Laravel 4+)
在routes.php中:
Route::post('name', Controller@class);
将其更改为:
Route::group(array('before' => 'csrf'), function() {
Route::post('name', Controller@class);
});
在表单中,必须添加以下内容:{{form::token()}
一个小提示:我更喜欢给你所有的路线起一个唯一的名字。。您可以找到它是如何工作的。为什么不测试一下,看看会发生什么?看起来很正确,当用户无法查看页面时,meI会将用户重定向到主页,而不是将其注销。当然,这取决于你在做什么。谢谢你的回答,我运行了这个例子,它工作正常。我被贴在这里是为了接收评论和建议,也许是为了展示一种管理个人资料的方法。谢谢你。我要用这个。
Route::group(array('before' => 'csrf'), function() {
Route::post('name', Controller@class);
});