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.

117 lines
4.0 KiB
PHP

<?php
ini_set('display_errors', '0');
ini_set('display_startup_errors', '0');
error_reporting(E_ALL);
require_once 'includes/db.php';
require_once 'includes/auth.php';
require_once 'includes/oauth_microsoft.php';
$error = '';
$logo_path = '';
if (isset($_GET['oauth_error'])) {
$error = trim((string)$_GET['oauth_error']);
}
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) {
error_log($e->getMessage());
}
if ($_SERVER["REQUEST_METHOD"] === "POST") {
requireCsrfToken();
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
if ($username !== '' && $password !== '') {
try {
$stmt = $pdo->prepare("SELECT * FROM " . DB_PREFIX . "users WHERE username = ?");
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
session_regenerate_id(true);
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['role'] = $user['role'];
header("Location: index.php");
exit();
}
$error = "Nieprawidłowy login lub hasło.";
} catch (PDOException $e) {
error_log($e->getMessage());
$error = "Nie udało się zalogować. Spróbuj ponownie później.";
}
} 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 e(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 e($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 e($error); ?></div>
<?php endif; ?>
<form method="POST" action="login.php">
<?php echo csrfInput(); ?>
<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>
<?php if (isMicrosoftOAuthConfigured()): ?>
<div class="text-center my-3 text-muted small">lub</div>
<a href="oauth_login.php" class="btn btn-outline-dark w-100">Zaloguj przez Microsoft 365</a>
<?php endif; ?>
<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>