2016-09-09 05:38:58 +02:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
DataValidator::with('CustomValidations', true);
|
|
|
|
|
2017-04-16 07:35:04 +02:00
|
|
|
/**
|
2017-05-12 06:58:40 +02:00
|
|
|
* @api {post} /user/get Get my information
|
2021-10-19 03:06:20 +02:00
|
|
|
* @apiVersion 4.10.0
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiName Get my Information
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
|
|
|
* @apiGroup User
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiDescription This path retrieves information about the logged user.
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiPermission user
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiUse NO_PERMISSION
|
|
|
|
* @apiUse INVALID_CREDENTIALS
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiSuccess {Object} data Information about an user
|
2018-11-15 20:11:28 +01:00
|
|
|
* @apiSuccess {String} data.name Name of the user
|
2017-04-22 03:33:17 +02:00
|
|
|
* @apiSuccess {String} data.email Email of the user
|
|
|
|
* @apiSuccess {Boolean} data.verified Indicates if the user is verified
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiSuccess {Object} data Information about an user
|
2017-04-22 03:33:17 +02:00
|
|
|
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data.tickets Array of tickets of the user
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-09-09 05:38:58 +02:00
|
|
|
class GetUserController extends Controller {
|
|
|
|
const PATH = '/get';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-09-09 05:38:58 +02:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'user',
|
|
|
|
'requestData' => []
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
2020-07-21 11:52:34 +02:00
|
|
|
|
2016-09-25 06:16:10 +02:00
|
|
|
if (Controller::isStaffLogged()) {
|
2018-11-20 23:41:00 +01:00
|
|
|
throw new RequestException(ERRORS::INVALID_CREDENTIALS);
|
2016-09-25 06:16:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-09 05:38:58 +02:00
|
|
|
$user = Controller::getLoggedUser();
|
|
|
|
$parsedTicketList = [];
|
|
|
|
$ticketList = $user->sharedTicketList;
|
|
|
|
|
|
|
|
foreach($ticketList as $ticket) {
|
2018-11-15 20:11:28 +01:00
|
|
|
$parsedTicketList[] = $ticket->toArray(true);
|
2016-09-09 05:38:58 +02:00
|
|
|
}
|
2020-07-21 11:52:34 +02:00
|
|
|
|
2016-09-09 05:38:58 +02:00
|
|
|
Response::respondSuccess([
|
|
|
|
'name' => $user->name,
|
|
|
|
'email' => $user->email,
|
2019-10-10 23:22:04 +02:00
|
|
|
'staff' => false,
|
2017-01-10 17:19:36 +01:00
|
|
|
'verified' => !$user->verificationToken,
|
2019-02-03 20:47:29 +01:00
|
|
|
'tickets' => $parsedTicketList,
|
|
|
|
'customfields' => $user->xownCustomfieldvalueList->toArray(),
|
2020-07-21 11:52:34 +02:00
|
|
|
'users' => $user->supervisedrelation ? $user->supervisedrelation->sharedUserList->toArray() : null
|
2016-09-09 05:38:58 +02:00
|
|
|
]);
|
|
|
|
}
|
2018-11-15 20:11:28 +01:00
|
|
|
}
|