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
c24b6541
Commit
c24b6541
authored
Sep 27, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decoupling the controller fron sentinel
parent
5c738fd3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
303 additions
and
76 deletions
+303
-76
UserController.php
Http/Controllers/Admin/UserController.php
+17
-39
UserFiltersServiceProvider.php
Providers/UserFiltersServiceProvider.php
+0
-10
UsersServiceProvider.php
Providers/UsersServiceProvider.php
+66
-27
RoleRepository.php
Repositories/RoleRepository.php
+16
-0
SentinelRoleRepository.php
Repositories/Sentinel/SentinelRoleRepository.php
+35
-0
SentinelUserRepository.php
Repositories/Sentinel/SentinelUserRepository.php
+110
-0
UserRepository.php
Repositories/UserRepository.php
+59
-0
No files found.
Http/Controllers/Admin/UserController.php
View file @
c24b6541
...
...
@@ -9,6 +9,8 @@ use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use
Modules\Core\Permissions\PermissionManager
;
use
Modules\User\Http\Requests\CreateUserRequest
;
use
Modules\User\Http\Requests\UpdateUserRequest
;
use
Modules\User\Repositories\RoleRepository
;
use
Modules\User\Repositories\UserRepository
;
class
UserController
extends
AdminBaseController
{
...
...
@@ -16,25 +18,24 @@ class UserController extends AdminBaseController
* @var PermissionManager
*/
private
$permissions
;
/**
* @var
\Modules\Session\Entities\User
* @var
UserRepository
*/
pr
otected
$users
;
pr
ivate
$user
;
/**
* @var
\Cartalyst\Sentinel\Roles\EloquentRole
* @var
RoleRepository
*/
pr
otected
$roles
;
pr
ivate
$role
;
public
function
__construct
(
PermissionManager
$permissions
)
public
function
__construct
(
PermissionManager
$permissions
,
UserRepository
$user
,
RoleRepository
$role
)
{
parent
::
__construct
();
$this
->
beforeFilter
(
'permissions'
);
$this
->
users
=
Sentinel
::
getUserRepository
();
$this
->
roles
=
Sentinel
::
getRoleRepository
()
->
createModel
();
$this
->
permissions
=
$permissions
;
$this
->
user
=
$user
;
$this
->
role
=
$role
;
}
/**
...
...
@@ -44,7 +45,7 @@ class UserController extends AdminBaseController
*/
public
function
index
()
{
$users
=
$this
->
user
s
->
createModel
()
->
all
();
$users
=
$this
->
user
->
all
();
return
View
::
make
(
'user::admin.users.index'
,
compact
(
'users'
));
}
...
...
@@ -56,7 +57,7 @@ class UserController extends AdminBaseController
*/
public
function
create
()
{
$roles
=
$this
->
role
s
->
all
();
$roles
=
$this
->
role
->
all
();
return
View
::
make
(
'user::admin.users.create'
,
compact
(
'roles'
));
}
...
...
@@ -70,26 +71,13 @@ class UserController extends AdminBaseController
public
function
store
(
CreateUserRequest
$request
)
{
$data
=
array_merge
(
$request
->
all
(),
[
'permissions'
=>
$this
->
permissions
->
clean
(
$request
->
permissions
)]);
$user
=
$this
->
users
->
create
(
$data
);
$user
->
roles
()
->
attach
(
$request
->
roles
);
$code
=
Activation
::
create
(
$user
);
Activation
::
complete
(
$user
,
$code
);
$this
->
user
->
createWithRoles
(
$data
,
$request
->
roles
);
Flash
::
success
(
'User created.'
);
return
Redirect
::
route
(
'dashboard.user.index'
);
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public
function
show
(
$id
)
{
}
/**
* Show the form for editing the specified resource.
*
...
...
@@ -98,11 +86,11 @@ class UserController extends AdminBaseController
*/
public
function
edit
(
$id
)
{
if
(
!
$user
=
$this
->
user
s
->
createModel
()
->
find
(
$id
))
{
if
(
!
$user
=
$this
->
user
->
find
(
$id
))
{
Flash
::
error
(
'User not found'
);
return
Redirect
::
route
(
'dashboard.user.index'
);
}
$roles
=
$this
->
role
s
->
all
();
$roles
=
$this
->
role
->
all
();
return
View
::
make
(
'user::admin.users.edit'
,
compact
(
'user'
,
'roles'
));
}
...
...
@@ -116,11 +104,9 @@ class UserController extends AdminBaseController
*/
public
function
update
(
$id
,
UpdateUserRequest
$request
)
{
$user
=
$this
->
users
->
createModel
()
->
find
(
$id
);
$data
=
array_merge
(
$request
->
all
(),
[
'permissions'
=>
$this
->
permissions
->
clean
(
$request
->
permissions
)]);
$this
->
users
->
update
(
$user
,
$data
);
$
user
->
roles
()
->
sync
(
$request
->
roles
);
$
this
->
user
->
updateAndSyncRoles
(
$id
,
$data
,
$request
->
roles
);
Flash
::
success
(
'User updated.'
);
return
Redirect
::
route
(
'dashboard.user.index'
);
...
...
@@ -134,17 +120,9 @@ class UserController extends AdminBaseController
*/
public
function
destroy
(
$id
)
{
if
(
$user
=
$this
->
users
->
createModel
()
->
find
(
$id
))
{
$user
->
delete
();
Flash
::
success
(
'User deleted'
);
return
Redirect
::
to
(
'users'
);
}
Flash
::
error
(
'User not found'
);
$this
->
user
->
delete
(
$id
);
Flash
::
success
(
'User deleted'
);
return
Redirect
::
to
(
'users'
);
}
...
...
Providers/UserFiltersServiceProvider.php
deleted
100644 → 0
View file @
5c738fd3
<?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
Providers/UsersServiceProvider.php
View file @
c24b6541
<?php
namespace
Modules\User
s
\Providers
;
<?php
namespace
Modules\User\Providers
;
use
Illuminate\Routing\Router
;
use
Illuminate\Support\ServiceProvider
;
class
UsersServiceProvider
extends
ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected
$defer
=
false
;
/**
* Register the service provider.
*
* @return void
*/
public
function
register
()
{
//
}
class
UsersServiceProvider
extends
ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected
$defer
=
false
;
/**
* The filters base class name.
*
* @var array
*/
protected
$filters
=
[
'permissions'
=>
'PermissionFilter'
];
/**
* Register the service provider.
*
* @return void
*/
public
function
register
()
{
$this
->
app
->
booted
(
function
(
$app
)
{
$this
->
registerFilters
(
$app
[
'router'
]);
$this
->
registerBindings
();
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public
function
provides
()
/**
* Get the services provided by the provider.
*
* @return array
*/
public
function
provides
()
{
return
array
();
}
/**
* Register the filters.
*
* @param Router $router
* @return void
*/
public
function
registerFilters
(
Router
$router
)
{
foreach
(
$this
->
filters
as
$name
=>
$filter
)
{
$class
=
'Modules\\User\\Http\\Filters\\'
.
$filter
;
$router
->
filter
(
$name
,
$class
);
}
}
private
function
registerBindings
()
{
return
array
();
$this
->
app
->
bind
(
'Modules\User\Repositories\UserRepository'
,
'Modules\User\Repositories\Sentinel\SentinelUserRepository'
);
$this
->
app
->
bind
(
'Modules\User\Repositories\RoleRepository'
,
'Modules\User\Repositories\Sentinel\SentinelRoleRepository'
);
}
}
Repositories/RoleRepository.php
0 → 100644
View file @
c24b6541
<?php
namespace
Modules\User\Repositories
;
interface
RoleRepository
{
/**
* Return all the roles
* @return mixed
*/
public
function
all
();
/**
* Create a role resource
* @return mixed
*/
public
function
create
(
$data
);
}
\ No newline at end of file
Repositories/Sentinel/SentinelRoleRepository.php
0 → 100644
View file @
c24b6541
<?php
namespace
Modules\User\Repositories\Sentinel
;
use
Cartalyst\Sentinel\Laravel\Facades\Sentinel
;
use
Modules\User\Repositories\RoleRepository
;
class
SentinelRoleRepository
implements
RoleRepository
{
/**
* @var \Cartalyst\Sentinel\Roles\EloquentRole
*/
protected
$role
;
public
function
__construct
()
{
$this
->
role
=
Sentinel
::
getRoleRepository
()
->
createModel
();
}
/**
* Return all the roles
* @return mixed
*/
public
function
all
()
{
return
$this
->
role
->
all
();
}
/**
* Create a role resource
* @return mixed
*/
public
function
create
(
$data
)
{
// TODO: Implement create() method.
}
}
\ No newline at end of file
Repositories/Sentinel/SentinelUserRepository.php
0 → 100644
View file @
c24b6541
<?php
namespace
Modules\User\Repositories\Sentinel
;
use
Cartalyst\Sentinel\Laravel\Facades\Activation
;
use
Cartalyst\Sentinel\Laravel\Facades\Sentinel
;
use
Modules\Session\Exceptions\UserNotFoundException
;
use
Modules\User\Repositories\UserRepository
;
class
SentinelUserRepository
implements
UserRepository
{
/**
* @var \Modules\Session\Entities\User
*/
protected
$user
;
/**
* @var \Cartalyst\Sentinel\Roles\EloquentRole
*/
protected
$role
;
public
function
__construct
()
{
$this
->
user
=
Sentinel
::
getUserRepository
()
->
createModel
();
$this
->
role
=
Sentinel
::
getRoleRepository
()
->
createModel
();
}
/**
* Returns all the users
* @return object
*/
public
function
all
()
{
return
$this
->
user
->
all
();
}
/**
* Create a user resource
* @return mixed
*/
public
function
create
(
$data
)
{
return
$this
->
user
->
create
(
$data
);
}
/**
* Create a user and assign roles to it
* @param array $data
* @param array $roles
* @return void
*/
public
function
createWithRoles
(
$data
,
$roles
)
{
$user
=
$this
->
user
->
create
(
$data
);
$user
->
roles
()
->
attach
(
$roles
);
$code
=
Activation
::
create
(
$user
);
Activation
::
complete
(
$user
,
$code
);
}
/**
* Find a user by its ID
* @param $id
* @return mixed
*/
public
function
find
(
$id
)
{
return
$this
->
user
->
find
(
$id
);
}
/**
* Update a user
* @param $user
* @param $data
* @return mixed
*/
public
function
update
(
$user
,
$data
)
{
return
$this
->
user
->
update
(
$user
,
$data
);
}
/**
* @param $userId
* @param $data
* @param $roles
* @internal param $user
* @return mixed
*/
public
function
updateAndSyncRoles
(
$userId
,
$data
,
$roles
)
{
$user
=
$this
->
user
->
find
(
$userId
);
$user
=
$user
->
fill
(
$data
);
$user
->
save
();
$user
->
roles
()
->
sync
(
$roles
);
}
/**
* Deletes a user
* @param $id
* @throws UserNotFoundException
* @return mixed
*/
public
function
delete
(
$id
)
{
if
(
$user
=
$this
->
user
->
find
(
$id
))
{
return
$user
->
delete
();
};
throw
new
UserNotFoundException
;
}
}
\ No newline at end of file
Repositories/UserRepository.php
0 → 100644
View file @
c24b6541
<?php
namespace
Modules\User\Repositories
;
/**
* Interface UserRepository
* @package Modules\User\Repositories
*/
interface
UserRepository
{
/**
* Returns all the users
* @return object
*/
public
function
all
();
/**
* Create a user resource
* @return mixed
*/
public
function
create
(
$data
);
/**
* Create a user and assign roles to it
* @param array $data
* @param array $roles
* @return void
*/
public
function
createWithRoles
(
$data
,
$roles
);
/**
* Find a user by its ID
* @param $id
* @return mixed
*/
public
function
find
(
$id
);
/**
* Update a user
* @param $user
* @param $data
* @return mixed
*/
public
function
update
(
$user
,
$data
);
/**
* Update a user and sync its roles
* @param $user
* @param $data
* @param $roles
* @return mixed
*/
public
function
updateAndSyncRoles
(
$user
,
$data
,
$roles
);
/**
* Deletes a user
* @param $id
* @return mixed
*/
public
function
delete
(
$id
);
}
\ 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