Add role assignment for new users during registration and update admin panel role selection to use a dropdown
This commit is contained in:
parent
7a33971df0
commit
f404ca305e
@ -124,14 +124,14 @@ $usersResult = $conn->query("
|
||||
<?php if (!$isSelf): ?>
|
||||
<form method="post" action="admin_users.php" style="margin: 0; display: flex; flex-direction: column; gap: 5px;">
|
||||
<input type="hidden" name="update_roles_user_id" value="<?= $user['userID'] ?>">
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
|
||||
<select name="roles[]" multiple size="3" style="background: #0f172a; color: #f8fafc; border: 1px solid #334155; padding: 5px; border-radius: 4px; font-size: 0.85rem; width: 100%;">
|
||||
<?php foreach ($allRoles as $role): ?>
|
||||
<label style="font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 4px;">
|
||||
<input type="checkbox" name="roles[]" value="<?= $role['roleID'] ?>" <?= in_array($role['roleID'], $userRoles) ? 'checked' : '' ?>>
|
||||
<option value="<?= $role['roleID'] ?>" <?= in_array($role['roleID'], $userRoles) ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($role['name']) ?>
|
||||
</label>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</select>
|
||||
<p style="font-size: 0.7rem; color: #94a3b8; margin: 0;">Strg/Cmd für Mehrfachauswahl</p>
|
||||
<button type="submit" style="background-color: #3b82f6; color: white; border: none; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 0.75rem; width: fit-content; margin-top: 5px;">Speichern</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
|
||||
24
register.php
24
register.php
@ -124,15 +124,37 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
||||
{
|
||||
mysqli_stmt_bind_param($stmt, 'ssss', $email, $hash, $displayName, $profilePicture);
|
||||
$ok = mysqli_stmt_execute($stmt);
|
||||
mysqli_stmt_close($stmt);
|
||||
|
||||
if ($ok)
|
||||
{
|
||||
$newUserId = mysqli_insert_id($conn);
|
||||
|
||||
// Get USER roleID
|
||||
$roleStmt = mysqli_prepare($conn, "SELECT roleID FROM roles WHERE name = 'USER' LIMIT 1");
|
||||
if ($roleStmt) {
|
||||
mysqli_stmt_execute($roleStmt);
|
||||
$roleResult = mysqli_stmt_get_result($roleStmt);
|
||||
if ($roleRow = mysqli_fetch_assoc($roleResult)) {
|
||||
$userRoleId = $roleRow['roleID'];
|
||||
|
||||
$insertRoleStmt = mysqli_prepare($conn, "INSERT INTO userRoles (userID, roleID) VALUES (?, ?)");
|
||||
if ($insertRoleStmt) {
|
||||
mysqli_stmt_bind_param($insertRoleStmt, 'ii', $newUserId, $userRoleId);
|
||||
mysqli_stmt_execute($insertRoleStmt);
|
||||
mysqli_stmt_close($insertRoleStmt);
|
||||
}
|
||||
}
|
||||
mysqli_stmt_close($roleStmt);
|
||||
}
|
||||
|
||||
mysqli_stmt_close($stmt);
|
||||
|
||||
mysqli_close($conn);
|
||||
header('Location: login.php?registered=1');
|
||||
exit;
|
||||
}
|
||||
|
||||
mysqli_stmt_close($stmt);
|
||||
$errors[] = 'Registrierung fehlgeschlagen.';
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user