ringfinger/backend/classes/controller/UserEmailGetController.php

39 lines
825 B
PHP

<?php
declare(strict_types=1);
final class UserEmailGetController extends AbstractController
{
protected string $route = '/api/v1/user/{userId}/email';
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;
}
parent::handle();
if (!$this->hasUserPermission($this->userId)) {
return;
}
try {
$user = new User($this->userId);
$this->response->setParameter('email', $user->getEmail());
} catch (Throwable $e) {
$this->response->setParameter('success', false);
$this->response->setMessage($e->getMessage());
$this->response->setStatus($e->getCode() !== 0 ? $e->getCode() : ServerStatus::BAD_REQUEST);
}
}
}