opensupports/server/controllers/user/get.php

66 lines
1.9 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
2017-04-16 07:35:04 +02:00
/**
* @api {post} /user/get Get my information
* @apiVersion 4.10.0
2017-04-16 07:35:04 +02:00
*
* @apiName Get my Information
2017-04-16 07:35:04 +02:00
*
* @apiGroup User
*
* @apiDescription This path retrieves information about the logged user.
2017-04-16 07:35:04 +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
*
* @apiSuccess {Object} data Information about an user
* @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
* @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
*
*/
class GetUserController extends Controller {
const PATH = '/get';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'user',
'requestData' => []
];
}
public function handler() {
if (Controller::isStaffLogged()) {
2018-11-20 23:41:00 +01:00
throw new RequestException(ERRORS::INVALID_CREDENTIALS);
return;
}
$user = Controller::getLoggedUser();
$parsedTicketList = [];
$ticketList = $user->sharedTicketList;
foreach($ticketList as $ticket) {
$parsedTicketList[] = $ticket->toArray(true);
}
Response::respondSuccess([
'name' => $user->name,
'email' => $user->email,
'staff' => false,
'verified' => !$user->verificationToken,
2019-02-03 20:47:29 +01:00
'tickets' => $parsedTicketList,
'customfields' => $user->xownCustomfieldvalueList->toArray(),
'users' => $user->supervisedrelation ? $user->supervisedrelation->sharedUserList->toArray() : null
]);
}
}