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
423332d8
Unverified
Commit
423332d8
authored
Oct 12, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creating the Api user controller
parent
03e6af5f
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19462 additions
and
17716 deletions
+19462
-17716
UserController.php
Modules/User/Http/Controllers/Api/UserController.php
+105
-0
apiRoutes.php
Modules/User/Http/apiRoutes.php
+5
-0
app.js
public/js/app.js
+19352
-17716
No files found.
Modules/User/Http/Controllers/Api/UserController.php
0 → 100644
View file @
423332d8
<?php
namespace
Modules\User\Http\Controllers\Api
;
use
Illuminate\Http\Request
;
use
Illuminate\Routing\Controller
;
use
Modules\User\Contracts\Authentication
;
use
Modules\User\Entities\Sentinel\User
;
use
Modules\User\Events\UserHasBegunResetProcess
;
use
Modules\User\Http\Requests\CreateUserRequest
;
use
Modules\User\Http\Requests\UpdateUserRequest
;
use
Modules\User\Permissions\PermissionManager
;
use
Modules\User\Repositories\UserRepository
;
use
Modules\User\Transformers\FullUserTransformer
;
use
Modules\User\Transformers\UserTransformer
;
class
UserController
extends
Controller
{
/**
* @var UserRepository
*/
private
$user
;
/**
* @var PermissionManager
*/
private
$permissions
;
public
function
__construct
(
UserRepository
$user
,
PermissionManager
$permissions
)
{
$this
->
user
=
$user
;
$this
->
permissions
=
$permissions
;
}
public
function
index
(
Request
$request
)
{
return
UserTransformer
::
collection
(
$this
->
user
->
serverPaginationFilteringFor
(
$request
));
}
public
function
find
(
User
$user
)
{
return
new
FullUserTransformer
(
$user
->
load
(
'roles'
));
}
public
function
findNew
(
User
$user
)
{
return
(
new
FullUserTransformer
(
$user
))
->
additional
([
'data'
=>
[
'is_new'
=>
true
]]);
}
public
function
store
(
CreateUserRequest
$request
)
{
$data
=
$this
->
mergeRequestWithPermissions
(
$request
);
$this
->
user
->
createWithRoles
(
$data
,
$request
->
get
(
'roles'
),
$request
->
get
(
'is_activated'
));
return
response
()
->
json
([
'errors'
=>
false
,
'message'
=>
trans
(
'user::messages.user created'
),
]);
}
public
function
update
(
User
$user
,
UpdateUserRequest
$request
)
{
$data
=
$this
->
mergeRequestWithPermissions
(
$request
);
$this
->
user
->
updateAndSyncRoles
(
$user
->
id
,
$data
,
$request
->
get
(
'roles'
));
return
response
()
->
json
([
'errors'
=>
false
,
'message'
=>
trans
(
'user::messages.user updated'
),
]);
}
public
function
destroy
(
User
$user
)
{
$this
->
user
->
delete
(
$user
->
id
);
return
response
()
->
json
([
'errors'
=>
false
,
'message'
=>
trans
(
'user::messages.user deleted'
),
]);
}
public
function
sendResetPassword
(
User
$user
,
Authentication
$auth
)
{
$code
=
$auth
->
createReminderCode
(
$user
);
event
(
new
UserHasBegunResetProcess
(
$user
,
$code
));
return
response
()
->
json
([
'errors'
=>
false
,
'message'
=>
trans
(
'user::auth.reset password email was sent'
),
]);
}
/**
* @param Request $request
* @return array
*/
private
function
mergeRequestWithPermissions
(
Request
$request
)
:
array
{
$permissions
=
$this
->
permissions
->
clean
(
$request
->
get
(
'permissions'
));
return
array_merge
(
$request
->
all
(),
[
'permissions'
=>
$permissions
]);
}
}
Modules/User/Http/apiRoutes.php
View file @
423332d8
...
...
@@ -74,6 +74,11 @@ $router->group(['prefix' => '/user', 'middleware' => ['api.token', 'auth.admin']
'uses'
=>
'UserController@update'
,
'middleware'
=>
'token-can:user.users.edit'
,
]);
$router
->
get
(
'{user}/sendResetPassword'
,
[
'as'
=>
'api.user.user.sendResetPassword'
,
'uses'
=>
'UserController@sendResetPassword'
,
'middleware'
=>
'token-can:user.users.edit'
,
]);
$router
->
delete
(
'{user}'
,
[
'as'
=>
'api.user.user.destroy'
,
'uses'
=>
'UserController@destroy'
,
...
...
public/js/app.js
View file @
423332d8
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