72 lines
2.6 KiB
PHP
72 lines
2.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require __DIR__ . '/app/bootstrap.php';
|
|
require __DIR__ . '/app/views.php';
|
|
|
|
if ($pdo && isInstalled($pdo)) {
|
|
header('Location: ' . appPath(''));
|
|
exit;
|
|
}
|
|
|
|
if (!$pdo) {
|
|
renderHeader('Installation');
|
|
?>
|
|
<div class="container-tight py-4">
|
|
<div class="alert alert-danger">Keine Datenbankverbindung vorhanden. Prüfe DB_HOST, DB_NAME, DB_USER und DB_PASS.</div>
|
|
</div>
|
|
<?php
|
|
renderFooter();
|
|
exit;
|
|
}
|
|
|
|
$installError = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'setup_admin' && $pdo) {
|
|
try {
|
|
$stmt = $pdo->prepare('INSERT INTO users (firstname, lastname, email, password_hash, role) VALUES (?, ?, ?, ?, "admin")');
|
|
$stmt->execute([
|
|
trim((string)$_POST['firstname']),
|
|
trim((string)$_POST['lastname']),
|
|
trim((string)$_POST['email']),
|
|
password_hash((string)$_POST['password'], PASSWORD_DEFAULT),
|
|
]);
|
|
header('Location: ' . appPath('?page=login'));
|
|
exit;
|
|
} catch (Throwable $e) {
|
|
$installError = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
renderHeader('Installation');
|
|
?>
|
|
<div class="container-tight py-4">
|
|
<div class="text-center mb-4">
|
|
<h1>Installation</h1>
|
|
<p class="text-secondary">Erstes Admin-Konto anlegen</p>
|
|
</div>
|
|
<?php if ($installError): ?>
|
|
<div class="alert alert-danger"><?= htmlspecialchars($installError) ?></div>
|
|
<?php endif; ?>
|
|
<?php if (!$pdo): ?>
|
|
<div class="alert alert-danger">Keine Datenbankverbindung vorhanden. Prüfe DB_HOST, DB_NAME, DB_USER und DB_PASS.</div>
|
|
<?php else: ?>
|
|
<div class="card card-md">
|
|
<div class="card-body">
|
|
<form method="post">
|
|
<input type="hidden" name="action" value="setup_admin">
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3"><label class="form-label">Vorname</label><input class="form-control" name="firstname" required></div>
|
|
<div class="col-md-6 mb-3"><label class="form-label">Nachname</label><input class="form-control" name="lastname" required></div>
|
|
</div>
|
|
<div class="mb-3"><label class="form-label">E-Mail</label><input class="form-control" name="email" type="email" required></div>
|
|
<div class="mb-3"><label class="form-label">Passwort</label><input class="form-control" name="password" type="password" required></div>
|
|
<button class="btn btn-success w-100" type="submit">Admin anlegen</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php
|
|
renderFooter();
|