This commit is contained in:
Jester
2026-01-19 08:35:00 +03:00
parent cbbc605336
commit 55b3d5f088
27 changed files with 183 additions and 841 deletions

37
api/login.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
header('Content-Type: application/json; charset=utf-8');
require_once '../config/db.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
$login = trim($data['username'] ?? '');
$password = $data['password'] ?? '';
// Поиск пользователя по username
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$login]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user['password_hash'])) {
// Успешная авторизация
session_start();
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
echo json_encode([
'success' => true,
'message' => 'Вход выполнен успешно',
'user' => [
'id' => $user['id'],
'username' => $user['username'],
]
]);
} else {
echo json_encode(['success' => false, 'message' => 'Неверные учетные данные']);
}
}
?>