Skip to content

Commit

Permalink
Enhanced user list page with groups, roles and status
Browse files Browse the repository at this point in the history
  • Loading branch information
glewe committed May 1, 2023
1 parent 8a3350e commit 2ae8271
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,12 @@ public function usersEditDo($id = null)
//
$emailChange = true;
if ($this->request->getPost('email') == $user->email) {

$rules['email'] = 'required|valid_email';
$emailChange = false;
}

$usernameChange = true;
if ($this->request->getPost('username') == $user->username) {

$rules['username'] = 'required|alpha_numeric_space|min_length[3]|max_length[30]';
$usernameChange = false;
}
Expand Down Expand Up @@ -313,6 +311,13 @@ public function usersEditDo($id = null)
else $user->setAttribute('active', 0);
$users->update($id, $user);

//
// Get the Banned switch.
//
if ($this->request->getPost('swi_banned')) $user->setAttribute('status', 'banned');
else $user->setAttribute('banned', 0);
$users->update($id, $user);

//
// Handle the Groups tab
//
Expand Down
23 changes: 21 additions & 2 deletions src/Helpers/bs5_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,16 @@ function bs5_formrow($data)
<span>' . $data['desc'] . '</span>
</label>
<div class="col">
<input type="' . $data['type'] . '" class="form-control' . ($data['errors'] ? ' is-invalid' : '') . '" name="' . $data['name'] . '" autocomplete="off"' . ($data['disabled'] ? ' disabled' : '') . '>
<input
type="' . $data['type'] . '"
class="form-control' . ($data['errors'] ? ' is-invalid' : '') . '"
name="' . $data['name'] . '"
autocomplete=off
readonly
onfocus="this.removeAttribute(\'readonly\');"
onblur="this.setAttribute(\'readonly\',\'\');"' .
($data['disabled'] ? ' disabled' : '') . '
>
<div class="invalid-feedback">' . $data['errors'] . '</div>
</div>
</div>
Expand All @@ -306,7 +315,17 @@ function bs5_formrow($data)
</label>
<div class="col">
<div class="form-check form-switch">
<input type="checkbox" class="form-check-input" id="' . $data['name'] . '" name="swi_' . $data['name'] . '" value="swi_' . $data['name'] . '"' . ((intval($data['value'])) ? " checked" : "") . '>
<div class="form-check form-switch">
<input
type="checkbox"
class="form-check-input"
id="' . $data['name'] . '"
name="swi_' . $data['name'] . '"
value="swi_' . $data['name'] . '"' .
((intval($data['value'])) ? " checked" : "") .
($data['disabled'] ? ' disabled' : '') . '
>
<div class="invalid-feedback">' . $data['errors'] . '</div>
<div class="invalid-feedback">' . $data['errors'] . '</div>
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/Language/de/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
'warning' => 'Warnung',
],

//
// Account
//
'account' => [
'active' => 'Konto aktiv',
'banned' => 'Konto gebannt',
'inactive' => 'Konto nicht aktiv',
],

//
// Activation
//
Expand Down Expand Up @@ -250,6 +259,8 @@
'user' => [
'active' => 'Aktiv',
'active_desc' => 'Aktiviere oder deaktiviere diesen Nutzer.',
'banned' => 'Gebannt',
'banned_desc' => 'Banne oder unbanne diesen Nutzer.',
'create_success' => 'Neuer Benutzer anegelegt: {0} ({1})',
'delete_confirm' => 'Bist du sicher, dass du diesen Benutzer l&ouml;schen willst?',
'delete_success' => 'Benutzer gel&ouml;scht: {0}',
Expand Down
11 changes: 11 additions & 0 deletions src/Language/en/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
'warning' => 'Warning',
],

//
// Account
//
'account' => [
'active' => 'Account active',
'banned' => 'Account banned',
'inactive' => 'Account not active',
],

//
// Activation
//
Expand Down Expand Up @@ -250,6 +259,8 @@
'user' => [
'active' => 'Active',
'active_desc' => 'Activate or deactivate this user.',
'banned' => 'Banned',
'banned_desc' => 'Ban or unban this user.',
'create_success' => 'New user created: {0} ({1})',
'delete_confirm' => 'Are you sure you want to delete this user?',
'delete_success' => 'User deleted: {0} ({1})',
Expand Down
11 changes: 11 additions & 0 deletions src/Language/es/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
'warning' => 'Aviso',
],

//
// Account
//
'account' => [
'active' => 'Cuenta activa',
'banned' => 'Cuenta prohibida',
'inactive' => 'Cuenta no activa',
],

//
// Activation
//
Expand Down Expand Up @@ -250,6 +259,8 @@
'user' => [
'active' => 'Activo',
'active_desc' => 'Activado o desactivado el usario.',
'banned' => 'Proscrito',
'banned_desc' => 'Prohibir o anular la prohibición de este usuario.',
'create_success' => 'Nuevo usuario creado: {0} ({1})',
'delete_confirm' => '¿Seguro que quieres borrar este usuario?',
'delete_success' => 'Usuario borrado: {0} ({1})',
Expand Down
6 changes: 5 additions & 1 deletion src/Views/_footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>

<!-- Show Bootstrap Toasts -->
<script>
<!-- Show Bootstrap Toasts -->
var toastElList = [].slice.call(document.querySelectorAll('.toast'))
var toastList = toastElList.map(function (toastEl) {
return new bootstrap.Toast(toastEl)
});
toastList.forEach(toast => toast.show());
console.log(toastList);

<!-- Enable Bootstrap Tooltips -->
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
</script>

</body>
Expand Down
15 changes: 15 additions & 0 deletions src/Views/_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@
text-align: center;
width: 20px;
}
.tooltip-danger {
--bs-tooltip-bg: var(--bs-danger);
}
.tooltip-info {
--bs-tooltip-bg: var(--bs-info);
}
.tooltip-primary {
--bs-tooltip-bg: var(--bs-primary);
}
.tooltip-success {
--bs-tooltip-bg: var(--bs-success);
}
.tooltip-warning {
--bs-tooltip-bg: var(--bs-warning);
}
</style>

</head>
Expand Down
14 changes: 13 additions & 1 deletion src/Views/users/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,19 @@
'title' => lang('Auth.user.active'),
'desc' => lang('Auth.user.active_desc'),
'errors' => session('errors.active'),
'value' => $user->active
'value' => $user->active,
'disabled' => ($user->id==1) ? true : false
]);

echo bs5_formrow([
'type' => 'switch',
'mandatory' => false,
'name' => 'banned',
'title' => lang('Auth.user.banned'),
'desc' => lang('Auth.user.banned_desc'),
'errors' => session('errors.banned'),
'value' => $user->banned,
'disabled' => ($user->id==1) ? true : false
]);

?>
Expand Down
28 changes: 24 additions & 4 deletions src/Views/users/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
<div class="col-lg-1 text-end"><?= lang('Auth.btn.action') ?></div>
</div>

<?php foreach ($users as $user) : ?>
<?php foreach ($users as $user) :

$userGroups = $user->getGroups();
$userRoles = $user->getRoles();
?>

<form name="form_<?= $user->id ?>" action="<?= base_url() ?>/users" method="post">
<?= csrf_field() ?>
Expand All @@ -49,9 +53,25 @@
<div class="col-lg-1"><?= $i++; ?></div>
<div class="col-lg-2"><?= $user->username ?></div>
<div class="col-lg-3"><?= $user->email ?></div>
<div class="col-lg-2">...</div>
<div class="col-lg-2">...</div>
<div class="col-lg-1">...</div>
<div class="col-lg-2">
<?php foreach ($userGroups as $group) :
echo $group . '<br>';
endforeach; ?>
</div>
<div class="col-lg-2">
<?php foreach ($userRoles as $role) :
echo $role . '<br>';
endforeach; ?>
</div>
<div class="col-lg-1">
<?= $user->isActivated() ?
'<a href="#" data-bs-toggle="tooltip" data-bs-title="'.lang('Auth.account.active').'" data-bs-custom-class="tooltip-success"><i class="bi-check-square-fill text-success"></i></a>' :
'<a href="#" data-bs-toggle="tooltip" data-bs-title="'.lang('Auth.account.inactive').'" data-bs-custom-class="tooltip-warning"><i class="bi-x-square-fill text-warning"></i></a>'
?>
<?= $user->isBanned() ?
'<a href="#" data-bs-toggle="tooltip" data-bs-title="'.lang('Auth.account.banned').'" data-bs-custom-class="tooltip-danger"><i class="bi-sign-stop-fill text-danger"></i></a>' : ''
?>
</div>
<div class="col-lg-1 text-end">
<div class="btn-user">
<button id="action-<?= $user->id ?>" type="button" class="btn btn-sm btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"><?= lang('Auth.btn.action') ?></button>
Expand Down

0 comments on commit 2ae8271

Please sign in to comment.