Fix getUser endpoint

This commit is contained in:
BitHeaven 2024-08-09 21:53:15 +05:00
parent 0bcd0f8483
commit 44cb07fe0b
1 changed files with 21 additions and 13 deletions

View File

@ -1,19 +1,27 @@
<?php <?php
if(!isset($_GET['login'])) { if($_SERVER['REQUEST_METHOD'] == 'GET') {
$data = [ if(!isset($_REQUEST['login'])) {
'error' => true, $data = [
'message' => 'Не передано поле login', 'error' => true,
]; 'message' => 'Не передано поле login',
} ];
elseif(!$user = User::get($_GET['login'])) { }
$data = [ elseif(!$user = User::get($_REQUEST['login'])) {
'error' => true, $data = [
'message' => 'Пользователь не существует', 'error' => true,
]; 'message' => 'Пользователь не существует',
];
}
else {
$data = [
'error' => false,
'data' => $user,
];
}
} }
else { else {
$data = [ $data = [
'error' => false, 'error' => true,
'data' => $user, 'message' => 'Только метод GET',
]; ];
} }