first stable
This commit is contained in:
parent
841109d995
commit
5a5136dd05
3 changed files with 13 additions and 117 deletions
|
|
@ -5,7 +5,16 @@
|
|||
"mcp__visualize__show_widget",
|
||||
"Bash(git init *)",
|
||||
"Bash(git add *)",
|
||||
"Bash(git commit *)"
|
||||
"Bash(git commit *)",
|
||||
"Bash(git mv *)",
|
||||
"Bash(php -l api.php)",
|
||||
"Bash(php -l auth.php)",
|
||||
"Bash(php -l migrate.php)",
|
||||
"Bash(php -l setup.php)",
|
||||
"PowerShell(php -l \"C:\\\\Users\\\\danie\\\\Desktop\\\\guessTheLiar\\\\api.php\")",
|
||||
"PowerShell(php -l \"C:\\\\Users\\\\danie\\\\Desktop\\\\guessTheLiar\\\\auth.php\")",
|
||||
"PowerShell(php -l \"C:\\\\Users\\\\danie\\\\Desktop\\\\guessTheLiar\\\\migrate.php\")",
|
||||
"Bash(grep -v \"^\\\\s*//\")"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ declare(strict_types=1);
|
|||
*/
|
||||
return [
|
||||
'host' => 'localhost',
|
||||
'dbname' => 'DEINE_DATENBANK',
|
||||
'user' => 'DEIN_DB_USER',
|
||||
'pass' => 'DEIN_DB_PASSWORT',
|
||||
'dbname' => 'guess_appform',
|
||||
'user' => 'guess_appform',
|
||||
'pass' => 'Z_O9Vcpidy!ot1f7',
|
||||
'charset' => 'utf8mb4',
|
||||
];
|
||||
|
|
|
|||
113
setup.php
113
setup.php
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Einmalige Admin-Einrichtung.
|
||||
* Aufruf: https://yourdomain.com/setup.php
|
||||
* Nach dem ersten Aufruf diese Datei löschen oder per .htaccess sperren!
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
$cfg = require __DIR__ . '/config.php';
|
||||
|
||||
function db(array $cfg): PDO
|
||||
{
|
||||
$dsn = sprintf('mysql:host=%s;dbname=%s;charset=%s', $cfg['host'], $cfg['dbname'], $cfg['charset']);
|
||||
return new PDO($dsn, $cfg['user'], $cfg['pass'], [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
]);
|
||||
}
|
||||
|
||||
$error = $success = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$adminUser = trim($_POST['username'] ?? '');
|
||||
$adminPass = $_POST['password'] ?? '';
|
||||
$adminPass2 = $_POST['password2'] ?? '';
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9_\-]{2,40}$/', $adminUser)) {
|
||||
$error = 'Username: 2–40 Zeichen, nur Buchstaben/Zahlen/_/-';
|
||||
} elseif (strlen($adminPass) < 8) {
|
||||
$error = 'Passwort muss mindestens 8 Zeichen haben.';
|
||||
} elseif ($adminPass !== $adminPass2) {
|
||||
$error = 'Passwörter stimmen nicht überein.';
|
||||
} else {
|
||||
try {
|
||||
$pdo = db($cfg);
|
||||
$check = $pdo->prepare("SELECT id FROM gtl_users WHERE role = 'admin' LIMIT 1");
|
||||
$check->execute();
|
||||
if ($check->fetch()) {
|
||||
$error = 'Admin-Konto existiert bereits. Setup-Datei löschen!';
|
||||
} else {
|
||||
$hash = password_hash($adminPass, PASSWORD_DEFAULT);
|
||||
$now = time();
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO gtl_users (username, credential_hash, role, created_at)
|
||||
VALUES (?, ?, 'admin', ?)"
|
||||
);
|
||||
$ins->execute([$adminUser, $hash, $now]);
|
||||
$uid = $pdo->lastInsertId();
|
||||
$pdo->prepare("INSERT INTO gtl_user_stats (user_id) VALUES (?)")->execute([$uid]);
|
||||
|
||||
// Create uploads directory
|
||||
$dir = __DIR__ . '/uploads/avatars';
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
|
||||
$success = 'Admin-Konto „' . htmlspecialchars($adminUser) . '" erfolgreich angelegt! Lösche diese Datei jetzt.';
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$error = 'DB-Fehler: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
?><!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Setup – Guess the Liar</title>
|
||||
<style>
|
||||
*{box-sizing:border-box;margin:0;padding:0}
|
||||
body{font-family:system-ui,sans-serif;background:#16100c;color:#f6ede4;
|
||||
min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}
|
||||
.box{background:#241a13;border:1px solid #3a2b1f;border-radius:16px;padding:32px;width:100%;max-width:400px}
|
||||
h1{font-size:22px;font-weight:800;margin-bottom:6px;color:#FF7F4D}
|
||||
p.sub{color:#a8978a;font-size:13px;margin-bottom:24px}
|
||||
label{display:block;font-size:12px;color:#a8978a;font-weight:600;text-transform:uppercase;letter-spacing:.6px;margin-bottom:6px}
|
||||
input{width:100%;background:#16100c;border:1.5px solid #3a2b1f;color:#f6ede4;
|
||||
border-radius:10px;padding:12px 14px;margin-bottom:16px;font-size:15px;outline:none}
|
||||
input:focus{border-color:#FF7F4D}
|
||||
button{width:100%;background:#FF7F4D;color:#2a160c;border:none;border-radius:10px;
|
||||
padding:14px;font-weight:700;font-size:15px;cursor:pointer}
|
||||
.err{background:rgba(232,93,92,.15);border:1px solid rgba(232,93,92,.4);color:#f0a0a0;
|
||||
padding:11px 14px;border-radius:10px;font-size:13px;margin-bottom:16px}
|
||||
.ok{background:rgba(43,181,133,.15);border:1px solid rgba(43,181,133,.4);color:#5fd3a8;
|
||||
padding:11px 14px;border-radius:10px;font-size:13px;margin-bottom:16px}
|
||||
.warn{margin-top:16px;font-size:12px;color:#ffcf6e;background:rgba(255,207,110,.1);
|
||||
border:1px solid rgba(255,207,110,.3);border-radius:8px;padding:10px 12px}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="box">
|
||||
<h1>🎭 Admin-Setup</h1>
|
||||
<p class="sub">Legt das erste Admin-Konto an. Danach diese Datei löschen!</p>
|
||||
<?php if($error): ?><div class="err"><?= htmlspecialchars($error) ?></div><?php endif; ?>
|
||||
<?php if($success): ?><div class="ok"><?= htmlspecialchars($success) ?></div>
|
||||
<?php else: ?>
|
||||
<form method="POST">
|
||||
<label>Admin-Username</label>
|
||||
<input type="text" name="username" value="<?= htmlspecialchars($_POST['username']??'admin') ?>" maxlength="40" autocomplete="off">
|
||||
<label>Passwort (min. 8 Zeichen)</label>
|
||||
<input type="password" name="password" autocomplete="new-password">
|
||||
<label>Passwort bestätigen</label>
|
||||
<input type="password" name="password2" autocomplete="new-password">
|
||||
<button type="submit">Admin anlegen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<div class="warn">⚠️ Diese Datei nach dem Setup löschen oder per .htaccess sperren!</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue