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
6c9175ab
Commit
6c9175ab
authored
Sep 26, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a filter service provider and a permissions filter
parent
618e536a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
0 deletions
+36
-0
RolesController.php
Http/Controllers/Admin/RolesController.php
+1
-0
UserController.php
Http/Controllers/Admin/UserController.php
+2
-0
PermissionFilter.php
Http/Filters/PermissionFilter.php
+23
-0
UserFiltersServiceProvider.php
Providers/UserFiltersServiceProvider.php
+10
-0
No files found.
Http/Controllers/Admin/RolesController.php
View file @
6c9175ab
...
...
@@ -25,6 +25,7 @@ class RolesController extends AdminBaseController
parent
::
__construct
();
$this
->
roles
=
Sentinel
::
getRoleRepository
()
->
createModel
();
$this
->
permissions
=
$permissions
;
$this
->
beforeFilter
(
'permissions'
);
}
/**
...
...
Http/Controllers/Admin/UserController.php
View file @
6c9175ab
...
...
@@ -24,6 +24,8 @@ class UserController extends AdminBaseController
{
parent
::
__construct
();
$this
->
beforeFilter
(
'permissions'
);
$this
->
users
=
Sentinel
::
getUserRepository
();
$this
->
roles
=
Sentinel
::
getRoleRepository
()
->
createModel
();
}
...
...
Http/Filters/PermissionFilter.php
0 → 100644
View file @
6c9175ab
<?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
Providers/UserFiltersServiceProvider.php
0 → 100644
View file @
6c9175ab
<?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
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