[英]Doing more than just user+password protection in Laravel
I'm using the standard auth method, which works great to keep people who are not logged in out of my "/my" controller. 我正在使用标准的auth方法,该方法非常有用,可以使未登录的人员退出我的“ / my”控制器。 Here's my code for that:
这是我的代码:
Route::group(array('before' => 'auth'), function(){
Route::get('my', array('as' => 'my', 'uses' => 'MyController@getIndex'));
});
But, now lets say I want to make sure they're logged in AND have activated set to 1 instead of 0. How do I add that rule to this code to make the controller protected from both guests AND logged in users that aren't set to active? 但是,现在让我说,我想确保他们已登录并且已将激活设置为1而不是0。如何将该规则添加到此代码中,以使控制器免受来宾和未登录用户的保护设置为活动状态?
Assuming you don't want to modify your auth
filter, just add a new one 假设您不想修改
auth
过滤器,只需添加一个新的
Route::filter('authActive', function()
{
if (!Auth::user()->active) return Redirect::guest('login');
});
And add the filter to your route group's before
, after your standard auth
(separated by a pipe): 并将过滤器添加到标准
auth
(由管道分隔) before
,之后的路由组中:
Route::group(array('before' => 'auth|authActive'), function(){
Route::get('my', array('as' => 'my', 'uses' => 'MyController@getIndex'));
});
A benefit of having two separate filters for this would be that if it passes auth
, but not authActive
, you could send them to a different view with an option to re-send an activation email. 为此有两个单独的过滤器的好处是,如果它传递
auth
而不是authActive
,则可以将它们发送到另一个视图,并带有重新发送激活电子邮件的选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.