update
This commit is contained in:
1 parent
3583170c9f
commit
223c571608
4 files changed
+139
-19
No files matched your search
@@ -1,19 +1,20 @@
|
||||
<?php
|
||||
|
||||
class UserController {
|
||||
public function setUser($name, $nachname, $email, $passwort, $rolle, $admin) {
|
||||
public function setUser($name, $nachname, $email, $passwort, $rolle, $admin, $home_ip) {
|
||||
|
||||
$hashedPasswort = password_hash($passwort, PASSWORD_DEFAULT);
|
||||
|
||||
DatabaseInsert(
|
||||
"Benutzer",
|
||||
"NAME, NACHNAME, EMAIL, PASSWORD, ROLLE, ADMIN",
|
||||
"NAME, NACHNAME, EMAIL, PASSWORD, ROLLE, ADMIN, HOME_IP",
|
||||
$name,
|
||||
$nachname,
|
||||
$email,
|
||||
$hashedPasswort,
|
||||
$rolle,
|
||||
$admin,
|
||||
$home_ip,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -43,4 +44,8 @@ class UserController {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function UpdateUser() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ if (isset($_POST['save']) && ($_SESSION['logged_in'] ?? false)) {
|
||||
if (file_put_contents($configFile, $content)) {
|
||||
if (function_exists('opcache_invalidate')) { @opcache_invalidate($configFile, true); }
|
||||
$_SESSION['status_message'] = "✅ Konfiguration erfolgreich aktualisiert!";
|
||||
header("Location: " . $_SERVER['PHP_SELF']);
|
||||
header("Location: " . (new getSpecificData())->getReferer());
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,67 @@
|
||||
<?php
|
||||
// 1. Logik zum Verarbeiten des Formulars (bevor die Liste geladen wird)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_user'])) {
|
||||
// Nur Admins dürfen Benutzer hinzufügen (Sicherheitscheck)
|
||||
if ((new getSpecificData())->getIsAdmin()) {
|
||||
$controller = new UserController();
|
||||
$controller->setUser(
|
||||
$_POST['name'],
|
||||
$_POST['nachname'],
|
||||
$_POST['email'],
|
||||
$_POST['passwort'],
|
||||
$_POST['rolle'],
|
||||
$_POST['admin'] ?? 0, // Falls Checkbox nicht gesetzt, 0 senden
|
||||
$_POST['home_ip']
|
||||
);
|
||||
// Optional: Seite neu laden, um die Liste zu aktualisieren
|
||||
header("Location: " . (new getSpecificData())->getReferer());
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ((new getSpecificData())->getIsAdmin()) {
|
||||
// 2. Daten für die Tabelle holen (dein bestehender Code)
|
||||
$specificData = new getSpecificData();
|
||||
$isAdmin = $specificData->getIsAdmin();
|
||||
|
||||
if ($isAdmin) {
|
||||
$users = DatabaseShow("Benutzer", "NAME, NACHNAME, EMAIL, ROLLE, ADMIN, HOME_IP");
|
||||
} else {
|
||||
$users = DatabaseShow(
|
||||
"Benutzer",
|
||||
"NAME, NACHNAME, EMAIL, ROLLE, ADMIN, HOME_IP",
|
||||
"Benutzer",
|
||||
"NAME, NACHNAME, EMAIL, ROLLE, ADMIN, HOME_IP",
|
||||
"NAME = ?",
|
||||
$specificData->getUsername()
|
||||
);
|
||||
}
|
||||
|
||||
if (!(new getSpecificData())->getIsAdmin()) {
|
||||
$users = DatabaseShow(
|
||||
"Benutzer",
|
||||
"NAME, NACHNAME, EMAIL, ROLLE, ADMIN, HOME_IP",
|
||||
"NAME = ?",
|
||||
((new getSpecificData())->getUsername()),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="content">
|
||||
<h2>Benutzerverwaltung</h2>
|
||||
|
||||
<?php if ($isAdmin): ?>
|
||||
<div class="form-container">
|
||||
<h3>Neuen Benutzer anlegen</h3>
|
||||
<form method="POST" action="">
|
||||
<div class="user-form-grid">
|
||||
<input type="text" name="name" placeholder="Vorname" required>
|
||||
<input type="text" name="nachname" placeholder="Nachname" required>
|
||||
<input type="text" name="email" placeholder="E-Mail" required>
|
||||
<input type="text" name="passwort" placeholder="Passwort" required>
|
||||
<input type="text" name="rolle" placeholder="Rolle (z.B. User)">
|
||||
<input type="text" name="home_ip" placeholder="Home IP">
|
||||
|
||||
<label class="checkbox-group">
|
||||
<input type="checkbox" name="admin" value="1">
|
||||
<span>Admin-Rechte</span>
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" name="add_user" class="btn-submit">
|
||||
Benutzer speichern
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="table-container">
|
||||
<table class="user-table">
|
||||
<thead>
|
||||
@@ -27,7 +69,7 @@ if (!(new getSpecificData())->getIsAdmin()) {
|
||||
<th>Vorname</th>
|
||||
<th>Nachname</th>
|
||||
<th>E-Mail</th>
|
||||
<?php if ((new getSpecificData())->getIsAdmin()): ?>
|
||||
<?php if ($isAdmin): ?>
|
||||
<th>Rolle</th>
|
||||
<th>Admin</th>
|
||||
<th>Home IP</th>
|
||||
@@ -40,7 +82,7 @@ if (!(new getSpecificData())->getIsAdmin()) {
|
||||
<td><?= htmlspecialchars($user['NAME']) ?></td>
|
||||
<td><?= htmlspecialchars($user['NACHNAME']) ?></td>
|
||||
<td><?= htmlspecialchars($user['EMAIL']) ?></td>
|
||||
<?php if ((new getSpecificData())->getIsAdmin()): ?>
|
||||
<?php if ($isAdmin): ?>
|
||||
<td><?= htmlspecialchars($user['ROLLE']) ?></td>
|
||||
<td><?= htmlspecialchars($user['ADMIN']) ?></td>
|
||||
<td><?= htmlspecialchars($user['HOME_IP']) ?></td>
|
||||
|
||||
@@ -746,4 +746,77 @@ body.dark-mode .user-table .btn-primary {
|
||||
|
||||
body.dark-mode .user-table .btn-primary:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
/* ===== Formular für neue Benutzer ===== */
|
||||
|
||||
.form-container {
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--card-border);
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
margin-bottom: 30px;
|
||||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.form-container h3 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 20px;
|
||||
color: var(--btn-bg);
|
||||
/* Nutzt dein definiertes Blau */
|
||||
font-size: 1.2rem;
|
||||
border-bottom: 1px solid var(--card-border);
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
/* Grid-Layout für die Eingabefelder */
|
||||
.user-form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 15px;
|
||||
align-items: end;
|
||||
}
|
||||
|
||||
/* Checkbox-Bereich Styling */
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 0;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.checkbox-group input[type="checkbox"] {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Button Styling innerhalb des Formulars */
|
||||
.form-container .btn-submit {
|
||||
background-color: var(--btn-add-bg);
|
||||
/* Nutzt dein Success-Grün */
|
||||
color: white;
|
||||
padding: 12px 25px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s ease;
|
||||
margin-top: 10px;
|
||||
width: auto;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.form-container .btn-submit:hover {
|
||||
opacity: 0.9;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
/* Mobile Optimierung für das Formular */
|
||||
@media (max-width: 600px) {
|
||||
.user-form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user