test-php-rest-api-user/engine/core/api/v1/getUser.php

34 lines
678 B
PHP
Raw Normal View History

2024-08-10 00:45:57 +08:00
<?php
2024-08-10 00:53:15 +08:00
if($_SERVER['REQUEST_METHOD'] == 'GET') {
if(!isset($_REQUEST['login'])) {
$data = [
'error' => true,
'message' => 'Не передано поле login',
];
}
elseif(!$user = User::get($_REQUEST['login'])) {
$data = [
'error' => true,
'message' => 'Пользователь не существует',
];
}
else {
$data = [
'error' => false,
2024-08-10 01:32:02 +08:00
'data' => [
'id' => $user->id,
'login' => $user->login,
'info' => $user->info,
'reg_dt' => $user->reg_dt,
'online_dt' => $user->online_dt,
],
2024-08-10 00:53:15 +08:00
];
}
2024-08-10 00:45:57 +08:00
}
else {
$data = [
2024-08-10 00:53:15 +08:00
'error' => true,
'message' => 'Только метод GET',
2024-08-10 00:45:57 +08:00
];
}