Развитие бека
1. Создание БД 2. Создание бека 3. Пока создали класс юзера
This commit is contained in:
64
backend/api/user.php
Normal file
64
backend/api/user.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
if ($method === 'POST') {
|
||||
$data = RestApi::getInput();
|
||||
$action = $data['action'] ?? null;
|
||||
|
||||
// Авторизация
|
||||
if ($action === 'auth_login') {
|
||||
$account = new Account();
|
||||
$result = $account->create_session(
|
||||
$data['username'] ?? null,
|
||||
$data['password'] ?? null
|
||||
);
|
||||
RestApi::response($result);
|
||||
}
|
||||
|
||||
// Проверка сессии
|
||||
if ($action === 'check_session') {
|
||||
$account = new Account();
|
||||
$keycookies = $data['keycookies'] ?? $_COOKIE['session'] ?? null;
|
||||
$result = $account->check_session($keycookies);
|
||||
RestApi::response($result);
|
||||
}
|
||||
|
||||
// Выход (удаление всех сессий)
|
||||
if ($action === 'logout') {
|
||||
$account = new Account();
|
||||
$keycookies = $data['keycookies'] ?? $_COOKIE['session'] ?? null;
|
||||
$result = $account->logout($keycookies);
|
||||
RestApi::response($result);
|
||||
}
|
||||
|
||||
// Создание пользователя
|
||||
if ($action === 'create_user') {
|
||||
$account = new Account();
|
||||
$account->name = $data['name'] ?? null;
|
||||
$account->username = $data['username'] ?? null;
|
||||
$account->password = $data['password'] ?? null;
|
||||
$account->id_department = $data['id_department'] ?? null;
|
||||
$account->avatar_url = $data['avatar_url'] ?? null;
|
||||
$account->telegram = $data['telegram'] ?? null;
|
||||
|
||||
$result = $account->create();
|
||||
RestApi::response($result);
|
||||
}
|
||||
|
||||
// Проверяем, что метод не пустой
|
||||
if (!$action) {
|
||||
RestApi::response(['success' => false, 'error' => 'Укажите метод'], 400);
|
||||
}
|
||||
}
|
||||
|
||||
if ($method === 'GET') {
|
||||
// Получение всех пользователей
|
||||
$account = new Account();
|
||||
$users = $account->getAll();
|
||||
|
||||
RestApi::response(['success' => true, 'data' => $users]);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user