Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
90efaf2e
Commit
90efaf2e
authored
10 years ago
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding the filters to the core module
parent
92a92804
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
AdminFilter.php
Http/Filters/AdminFilter.php
+29
-0
CoreServiceProvider.php
Providers/CoreServiceProvider.php
+33
-0
No files found.
Http/Filters/AdminFilter.php
0 → 100644
View file @
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
This diff is collapsed.
Click to expand it.
Providers/CoreServiceProvider.php
View file @
90efaf2e
<?php
namespace
Modules\Core\Providers
;
use
Illuminate\Routing\Router
;
use
Illuminate\Support\ServiceProvider
;
use
Modules\User\Events\RegisterSidebarMenuItemEvent
;
...
...
@@ -12,6 +13,18 @@ class CoreServiceProvider extends ServiceProvider
*/
protected
$defer
=
false
;
/**
* The filters base class name.
*
* @var array
*/
protected
$filters
=
[
'Core'
=>
[
'permissions'
=>
'PermissionFilter'
,
'auth.admin'
=>
'AdminFilter'
,
]
];
public
function
boot
()
{
include
__DIR__
.
'/../start.php'
;
...
...
@@ -25,6 +38,9 @@ class CoreServiceProvider extends ServiceProvider
public
function
register
()
{
$this
->
loadModuleProviders
();
$this
->
app
->
booted
(
function
(
$app
)
{
$this
->
registerFilters
(
$app
[
'router'
]);
});
}
/**
...
...
@@ -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
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment