Files
site_for_glpi/index.php

59 lines
2.0 KiB
PHP
Raw Permalink 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
require_once __DIR__ . '/config.php';
// Если пользователь уже авторизован, перенаправляем на dashboard
$user = checkAuth($pdo);
if ($user) {
redirect('dashboard.php');
}
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
if ($username && $password) {
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$username]);
$user = $stmt->fetch();
// Проверка пароля (предполагается хеширование password_hash)
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
redirect('dashboard.php');
} else {
$error = 'Неверное имя пользователя или пароль';
}
} else {
$error = 'Заполните все поля';
}
}
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Вход в систему</title>
<link rel="stylesheet" href="style.css">
</head>
<body class="login-page">
<div class="login-container">
<h1 class="centreee" >ВХОД В СИСТЕМУ</h1>
<?php if ($error): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="post">
<div class="form-group">
<label for="username">Логин</label>
<input type="text" id="username" name="username" required autofocus>
</div>
<div class="form-group">
<label for="password">Пароль</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit" class="btn-primary logbt">Войти</button>
</form>
</div>
</body>
</html>