Add authUser API endpoint

This commit is contained in:
BitHeaven 2024-08-09 22:02:25 +05:00
parent 77b9785dc0
commit 129c0c1264
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(!isset($_REQUEST['login'])) {
$data = [
'error' => true,
'message' => 'Не передано поле login',
];
}
elseif(!isset($_REQUEST['password'])) {
$data = [
'error' => true,
'message' => 'Не передано поле password',
];
}
elseif(!$token = User::auth($_REQUEST['login'], $_REQUEST['password'])) {
$data = [
'error' => true,
'message' => 'Не вверно введены логин и/или пароль',
];
}
else {
$data = [
'error' => false,
'message' => 'Вход успешно совершен',
'data' => [
'token' => $token,
],
];
}
}
else {
$data = [
'error' => true,
'message' => 'Только POST метод',
];
}