ringfinger/backend/classes/controller/UserDeleteController.php

42 lines
897 B
PHP
Raw Normal View History

2020-08-20 15:45:59 +02:00
<?php
declare(strict_types=1);
final class UserDeleteController extends AbstractController
{
protected string $route = '/api/v1/user/{userId}';
private int $userId;
public function __construct(string $url)
{
parent::__construct($url);
$this->userId = (int)$this->getUrlParamInt('userId');
}
public function handle(): void
{
if (!$this->isUserLoggedIn()) {
return;
}
2020-08-20 15:45:59 +02:00
parent::handle();
if ($this->response->getStatus() !== ServerStatus::OK || !$this->hasUserPermission($this->userId)) {
2020-08-20 15:45:59 +02:00
return;
}
try {
$user = new User($this->userId);
$user->Delete();
$this->response = new ApiJsonResponse();
$this->response->setParameter('success', true);
} catch (Throwable $e) {
$this->response = new ApiJsonResponse(ServerStatus::BAD_REQUEST);
$this->response->setParameter('success', false);
$this->response->setMessage($e->getMessage());
}
}
}