Commit 739090ee authored by Nicolas Widart's avatar Nicolas Widart

Merge branch 'develop'

* develop:
  Adding the filters to the core module
parents cc0f7375 90efaf2e
<?php namespace Modules\Core\Http\Filters;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Session;
class AdminFilter
{
public function filter()
{
// Check if the user is logged in
if (!Sentinel::check()) {
// Store the current uri in the session
Session::put('loginRedirect', Request::url());
// Redirect to the login page
return Redirect::route('login');
}
// Check if the user has access to the dashboard page
if ( ! Sentinel::getUser()->hasAccess('dashboard.index'))
{
// Show the insufficient permissions page
return App::abort(403);
}
}
}
\ No newline at end of file
<?php namespace Modules\Core\Providers; <?php namespace Modules\Core\Providers;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Modules\User\Events\RegisterSidebarMenuItemEvent; use Modules\User\Events\RegisterSidebarMenuItemEvent;
...@@ -12,6 +13,18 @@ class CoreServiceProvider extends ServiceProvider ...@@ -12,6 +13,18 @@ class CoreServiceProvider extends ServiceProvider
*/ */
protected $defer = false; protected $defer = false;
/**
* The filters base class name.
*
* @var array
*/
protected $filters = [
'Core' => [
'permissions' => 'PermissionFilter',
'auth.admin' => 'AdminFilter',
]
];
public function boot() public function boot()
{ {
include __DIR__ . '/../start.php'; include __DIR__ . '/../start.php';
...@@ -25,6 +38,9 @@ class CoreServiceProvider extends ServiceProvider ...@@ -25,6 +38,9 @@ class CoreServiceProvider extends ServiceProvider
public function register() public function register()
{ {
$this->loadModuleProviders(); $this->loadModuleProviders();
$this->app->booted(function ($app) {
$this->registerFilters($app['router']);
});
} }
/** /**
...@@ -54,4 +70,21 @@ class CoreServiceProvider extends ServiceProvider ...@@ -54,4 +70,21 @@ class CoreServiceProvider extends ServiceProvider
} }
}); });
} }
/**
* Register the filters.
*
* @param Router $router
* @return void
*/
public function registerFilters(Router $router)
{
foreach ($this->filters as $module => $filters) {
foreach ($filters as $name => $filter) {
$class = "Modules\\{$module}\\Http\\Filters\\{$filter}";
$router->filter($name, $class);
}
}
}
} }
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