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

37 lines
800 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 метод',
];
}