我仍然习惯于 Sentry,但如果我是正确的,那我就做对了。
问题是,当我对路由应用过滤器时,它并没有按照我想要的方式工作。它应该检查用户是否已登录,如果未登录,则将他/她重定向到登录页面。
我登录用户的方式:
public function postLogin()
{
$credentials = array(
'username' => $this->input->get('email_or_username'),
'password' => $this->input->get('password')
);
try
{
$user = $this->sentry->authenticate($credentials, false);
if ($user)
{
return $this->redirect->route('user.dashboard.index');
}
}
catch(\Exception $e)
{
return $this->redirect->route('login')->withErrors(array('login' => $e->getMessage()));
}
}
应该没问题吧?接下来我得到了我的路由(我只对它进行分组以测试这个特定路由资源上的过滤器):
Route::group(array('before'=>'Sentry'), function()
{
Route::resource('user', 'UserProfileController',
array('names' =>
array(
'index'=>'this.user.index',
'create'=>'this.user.create',
'store'=>'this.user.store',
'show'=>'this.user.show',
'edit'=>'this.user.edit',
'update'=>'this.user.update',
'destroy'=>'this.user.destroy'
)
)
);
// (index)show your profile info, (edit,update)Edit and update your profile
});
最后过滤器应该检查用户,如果他/她没有登录则重定向:
Route::filter('Sentry', function()
{
if (!Sentry::check()){
return Redirect::route('login');
}
});
我已经坚持了几天了,我已经让很多其他人看看它,他们都说同样的:“嗯,那很奇怪......”。所以,我希望这里有人可以给我一些意见。