php - Laravel 4 conditional route filter -
i have group of routes want allow user access if in department or id in route trying access matches logged in id.
i have:
route::group(array('before' => 'auth.department:6|auth.me'), function () { route::get('users/{id}/outofoffice', ['as' => 'users.outofoffice.form', 'uses' => 'rackspacecontroller@outofofficeform']); route::post('users/{id}/outofoffice', ['as' => 'users.outofoffice.save', 'uses' => 'rackspacecontroller@outofofficesave']); route::get('users', ['as' => 'users.list', 'uses' => 'usercontroller@index']); route::get('users/{id}/edit', ['as' => 'users.edit', 'uses' => 'usercontroller@edit']); route::post('users/{id}', ['as' => 'users.update', 'uses' => 'usercontroller@update']); });
but not working, 'auth.department:6' works expected, when change 'auth.department:6|auth.me', user still denied access. filters defined as:
route::filter('auth.department', function($route, $request) { if(auth::level() > 5) return null; $departmentids = array_slice(func_get_args(), 2); if(!in_array(auth::dept(), $departmentids)) { if (request::ajax()) { return response::make('unauthorized', 401); } else { return response::make('unauthorized', 401); } } }); route::filter('auth.me', function(\illuminate\routing\route $route, $request){ if($route->getparameter('id') == auth::id()) { return null; } else { return basecontroller::failed(['authorization' => ['unauthorized']], 401); } });
i did this:
route::filter('auth.dept-6-or-me', function(\illuminate\routing\route $route, $request){ if(auth::level() > 5) return null; $departmentids = array_slice(func_get_args(), 2); if($route->getparameter('id') == auth::id()) { return null; } elseif(!in_array(auth::dept(), $departmentids)) { if (request::ajax()) { return response::make('unauthorized', 401); } else { return response::make('unauthorized', 401); } } else { if (request::ajax()) { return response::make('unauthorized', 401); } else { return response::make('unauthorized', 401); } } });
not solution, maybe someone.
same thing, work around mentioned here how apply multiple filters on laravel 4 route group?
also i've tested right because had same problem. so, | sign means and, works on principle, using sentry plugin.
route::post('/insert', array('as' => 'insertkom', 'uses' => 'kommunikationcontroller@insertkom', 'before' => 'hasaccess:admin|hasaccess:contact.insert'));
for example 2 permissions are:
hasaccess:admin: 1 hasaccess:contact.insert: 1
this solution passed, user can access route.
than changed permission to:
hasaccess:admin: 0 hasaccess:contact.insert: 1
still, solution somehow passed. user accessed route. not sure why.
than changed permission to:
hasaccess:admin: 1 hasaccess:contact.insert: 0
and 1 didn't pass. user has no access route. interesting thing, it's checking last permission.
Comments
Post a Comment