You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
4.2 KiB
PHP

<?php
// 1. Włączenie raportowania błędów (na czas testów)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// 2. Start sesji - musi być na samym początku, przed jakimkolwiek znakiem!
session_start();
// 3. Połączenie z bazą danych
require_once 'includes/db.php';
$error = '';
$logo_path = '';
// Pobranie ścieżki do logo z bazy danych
try {
$stmt = $pdo->query("SELECT setting_value FROM " . DB_PREFIX . "settings WHERE setting_key = 'logo_path'");
if ($stmt) {
$logo_path = $stmt->fetchColumn();
}
} catch (PDOException $e) {
// Ignorujemy błąd, jeśli tabela jeszcze nie istnieje itp.
}
// 4. Obsługa logowania
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = trim($_POST['username']);
$password = $_POST['password'];
if (!empty($username) && !empty($password)) {
try {
// Pobieranie użytkownika z bazy (uwzględniając prefix)
$stmt = $pdo->prepare("SELECT * FROM " . DB_PREFIX . "users WHERE username = ?");
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user) {
// Weryfikacja hasła
if (password_verify($password, $user['password'])) {
// Logowanie udane - zapis do sesji
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['role'] = $user['role'];
// Przekierowanie do index.php
header("Location: index.php");
exit();
} else {
$error = "Błędne hasło. Upewnij się, że hasło jest poprawne).";
}
} else {
$error = "Użytkownik '$username' nie istnieje w bazie.";
}
} catch (PDOException $e) {
$error = "Błąd bazy danych: " . $e->getMessage();
}
} else {
$error = "Proszę wypełnić oba pola.";
}
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Logowanie - <?php echo defined('APP_NAME') ? APP_NAME : 'System Zamówień'; ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { background-color: #f4f7f6; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
.login-card { width: 100%; max-width: 400px; padding: 2rem; border-radius: 15px; background: white; box-shadow: 0 10px 25px rgba(0,0,0,0.1); }
.btn-primary { background-color: #007bff; border: none; }
.login-logo { max-height: 80px; max-width: 100%; margin-bottom: 15px; object-fit: contain; }
</style>
</head>
<body>
<div class="login-card">
<div class="text-center mb-4">
<?php if ($logo_path && file_exists($logo_path)): ?>
<img src="<?php echo htmlspecialchars($logo_path); ?>" alt="Logo" class="login-logo">
<?php else: ?>
<h3>💻 Logowanie</h3>
<?php endif; ?>
<p class="text-muted small">Wpisz dane, aby zarządzać zamówieniami</p>
</div>
<?php if ($error): ?>
<div class="alert alert-danger p-2 small"><?php echo $error; ?></div>
<?php endif; ?>
<form method="POST" action="login.php">
<div class="mb-3">
<label for="username" class="form-label small">Użytkownik</label>
<input type="text" name="username" id="username" class="form-control" required autofocus>
</div>
<div class="mb-3">
<label for="password" class="form-label small">Hasło</label>
<input type="password" name="password" id="password" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary w-100">Zaloguj się</button>
</form>
<div class="mt-4 text-center border-top pt-3">
<p class="text-muted" style="font-size: 0.8rem;">
Aplikacja: <strong>goral.edu.pl/zeszyt</strong><br>
Serwer: <strong>OVH PHP 8.x</strong>
</p>
</div>
</div>
</body>
</html>