This commit is contained in:
144 changed files with 20649 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
<?php
header('Access-Control-Allow-Origin:*');
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
// Здесь будет соединение с БД
// Файлы необходимые для соединения с БД
//include_once __DIR__."/Config/DatabasePGSQL.php";
include_once __DIR__."/Config/Database.php";
//include_once __DIR__."/Config/DatabasePGSQL.php";
include_once __DIR__."/Objects/User.php";
// Получаем соединение с базой данных
$database = new Database();
$db = $database->getConnection();
// Создание объекта "User"
$user = new User($db);
// Получаем данные
$data = json_decode(file_get_contents("php://input"));
// Устанавливаем значения
$user->email = $data->email;
$email_exists = $user->emailExists();
// Файлы для JWT будут здесь
// Подключение файлов JWT
include_once __DIR__."/Config/core.php";
include_once __DIR__."/libs/php-jwt/BeforeValidException.php";
include_once __DIR__."/libs/php-jwt/ExpiredException.php";
include_once __DIR__."/libs/php-jwt/SignatureInvalidException.php";
include_once __DIR__."/libs/php-jwt/JWT.php";
use \Firebase\JWT\JWT;
// Существует ли электронная почта и соответствует ли пароль тому, что находится в базе данных
if ($email_exists['result'] && password_verify($data->password, $user->password)) {
$token = array(
"iss" => $iss,
"aud" => $aud,
"iat" => $iat,
"nbf" => $nbf,
"data" => array(
"id" => $user->id,
"firstname" => $user->firstname,
"lastname" => $user->lastname,
"email" => $user->email
)
);
// Код ответа
http_response_code(200);
// Создание jwt
$jwt = JWT::encode($token, $key, 'HS256');
echo json_encode(
array(
"message" => "Успешный вход в систему",
"jwt" => $jwt
)
);
}
// Если электронная почта не существует или пароль не совпадает,
// Сообщим пользователю, что он не может войти в систему
else {
// Код ответа
// http_response_code(401);
// Скажем пользователю что войти не удалось
echo json_encode(array("message" => "Ошибка входа","error"=>$email_exists['error']));
}
?>