opensupports/server/controllers/ticket/check.php

72 lines
2.0 KiB
PHP

<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
/**
* @api {post} /ticket/check Check if a ticket was or not readed.
*
* @apiName Check
*
* @apiGroup Ticket
*
* @apiDescription This path check if a ticket was or not readed.
*
* @apiPermission any
*
* @apiParam {number} ticketNumber The number of a ticket.
*
* @apiParam {string} email Email of the person who created the ticket.
*
* @apiParam {string} captcha Encrypted value generated by google captcha client.
*
* @apiError {String} message
*
* @apiSuccess {Object} data
*
*/
class CheckTicketController extends Controller {
const PATH = '/check';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'any',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
],
'email' => [
'validation' => DataValidator::email(),
'error' => ERRORS::INVALID_EMAIL
],
'captcha' => [
'validation' => DataValidator::captcha(),
'error' => ERRORS::INVALID_CAPTCHA
]
]
];
}
public function handler() {
if (Controller::isUserSystemEnabled() || Controller::isStaffLogged()) {
throw new Exception(ERRORS::NO_PERMISSION);
}
$email = Controller::request('email');
$ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
if($ticket->authorEmail === $email) {
$session = Session::getInstance();
$session->createTicketSession($ticket->ticketNumber);
Response::respondSuccess([
'token' => $session->getToken(),
'ticketNumber' => $ticket->ticketNumber
]);
} else {
throw new Exception(ERRORS::NO_PERMISSION);
}
}
}