Commit 6c9175ab authored by Nicolas Widart's avatar Nicolas Widart

Adding a filter service provider and a permissions filter

parent 618e536a
......@@ -25,6 +25,7 @@ class RolesController extends AdminBaseController
parent::__construct();
$this->roles = Sentinel::getRoleRepository()->createModel();
$this->permissions = $permissions;
$this->beforeFilter('permissions');
}
/**
......
......@@ -24,6 +24,8 @@ class UserController extends AdminBaseController
{
parent::__construct();
$this->beforeFilter('permissions');
$this->users = Sentinel::getUserRepository();
$this->roles = Sentinel::getRoleRepository()->createModel();
}
......
<?php namespace Modules\User\Http\Filters;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
use Laracasts\Flash\Flash;
class PermissionFilter
{
public function filter($route, $request)
{
$action = $route->getActionName();
$actionMethod = substr($action, strpos($action, "@") + 1);
if (Sentinel::hasAccess("{$request->segment(2)}.$actionMethod"))
{
return;
}
Flash::error('Permission denied.');
return Redirect::to('/' . Config::get('core::core.admin-prefix'));
}
}
\ No newline at end of file
<?php namespace Modules\User\Providers;
use Illuminate\Routing\FilterServiceProvider as ServiceProvider;
class UserFiltersServiceProvider extends ServiceProvider
{
protected $filters = [
'permissions' => 'Modules\User\Http\Filters\PermissionFilter',
];
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment