neonail-database/fix-admin-role.php
2025-08-10 18:09:07 +02:00

55 lines
1.8 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
// Admin-Rolle zur Datenbank hinzufügen
// Führen Sie dies direkt auf dem Webspace aus
try {
// Datenbankverbindung
$pdo = new PDO('sqlite:database.sqlite');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "🔧 Admin-Rolle hinzufügen...\n";
// 1. Prüfe ob is_admin Spalte existiert
$stmt = $pdo->query("PRAGMA table_info(users)");
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
$hasAdminColumn = false;
foreach ($columns as $column) {
if ($column['name'] === 'is_admin') {
$hasAdminColumn = true;
break;
}
}
if (!$hasAdminColumn) {
// 2. Füge is_admin Spalte hinzu
$pdo->exec("ALTER TABLE users ADD COLUMN is_admin BOOLEAN DEFAULT 0");
echo "✅ is_admin Spalte hinzugefügt\n";
} else {
echo " is_admin Spalte existiert bereits\n";
}
// 3. Markiere bestehende Admin-User
$stmt = $pdo->prepare("UPDATE users SET is_admin = 1 WHERE email IN (?, ?)");
$stmt->execute(['admin@neonail.com', 'neueradmin@neonail.com']);
echo "✅ Admin-User aktualisiert\n";
// 4. Zeige alle User
echo "\n📋 Alle User:\n";
$stmt = $pdo->query("SELECT id, name, email, is_admin FROM users");
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($users as $user) {
$adminStatus = $user['is_admin'] ? '👑 Admin' : '👤 User';
echo "- {$user['name']} ({$user['email']}) - {$adminStatus}\n";
}
echo "\n✅ Admin-Rolle erfolgreich aktiviert!\n";
echo "🔗 Gehen Sie zu: https://neonail.vogt.de.com/admin/users\n";
echo "📝 Bearbeiten Sie einen User und aktivieren Sie die 'Admin-Rechte gewähren' Checkbox\n";
} catch (Exception $e) {
echo "❌ Fehler: " . $e->getMessage() . "\n";
}
?>