openstamanager/modules/utenti/api/v1/Logout.php

27 lines
691 B
PHP
Raw Normal View History

2019-07-19 15:23:00 +02:00
<?php
namespace Modules\Utenti\API\v1;
use API\Interfaces\CreateInterface;
2019-07-19 16:51:52 +02:00
use API\Resource;
2019-07-19 15:23:00 +02:00
2019-07-19 16:51:52 +02:00
class Logout extends Resource implements CreateInterface
2019-07-19 15:23:00 +02:00
{
public function create($request)
{
$database = database();
2019-07-19 16:51:52 +02:00
$user = $this->getUser();
2019-07-19 15:23:00 +02:00
if (!empty($request['token']) && !empty($user)) {
// Cancellazione della chiave
$database->query('DELETE FROM `zz_tokens` WHERE `token` = '.prepare($request['token']).' AND `id_utente` = '.prepare($user['id']));
} else {
$response = [
'status' => API\Response::getStatus()['unauthorized']['code'],
];
}
return $response;
}
}