Implemented account system

This commit is contained in:
Michel Fedde 2024-07-05 16:50:53 +02:00
parent 51c20b55a0
commit ace0de4063
25 changed files with 1543 additions and 40 deletions

View file

@ -1,31 +1,29 @@
<?php
declare(strict_types=1);
use GamesShop\ContainerHandler;
use GamesShop\Login\LoginHandler;
use GamesShop\Entities\Account\User;
/** @var User|null $activeUser */
$loginHandler = ContainerHandler::get(LoginHandler::class);
?>
<?php if ($loginHandler->isLoggedIn()):
$user = $loginHandler->getCurrentUser();
?>
<?php if ($activeUser !== null): ?>
<div class="d-flex avatar justify-content-center">
<div class="avatar-icon h-100 position-relative me-2 ratio-1">
<img src="<?= $user->getProfilePictureUrl(); ?>" class="rounded-circle h-100" alt="User Profile Picture" />
<img src="<?= $activeUser->getProfilePictureUrl(); ?>" class="rounded-circle h-100" alt="User Profile Picture" />
<div class="position-absolute bottom-0 end-0 ratio-1 d-flex align-items-center z-1 avatar-login-method">
<i class="fa-brands <?= $user->getLoginMethod()->getIconClass() ?>"></i>
<i class="fa-brands <?= $activeUser->getLoginMethod()->getIconClass() ?>"></i>
<span class="position-absolute w-100 h-100 bottom-0 end-0 ratio-1 bg-body rounded-circle z-n1 avatar-login-method-icon"></span>
</div>
</div>
<div class="d-flex flex-column">
<span class="me-2 h-3">
<?= $user->getName() ?>
<?= $activeUser->getName() ?>
</span>
<small class="text-muted">
<?= $user->getPermission()->getHumanReadableName() ?>
<?= $activeUser->getPermission()->getHumanReadableName() ?>
</small>
</div>
<div class="h-100 d-flex align-items-center ms-2">

View file

@ -39,5 +39,7 @@ $resource = $resources->getResource($resourceEntry);
<?= $this->section('content'); ?>
</main>
<?= $this->section('modal') ?>
</body>
</html>

View file

@ -1,10 +1,17 @@
<?php
declare(strict_types=1);
use GamesShop\ContainerHandler;
use GamesShop\Login\LoginHandler;
use GamesShop\Entities\Account\User;
use GamesShop\Login\UserPermission;
use GamesShop\Templates\NavigationHeader;
ContainerHandler::get(LoginHandler::class);
$headers = [
new NavigationHeader('My Keys', '/keys', UserPermission::PROVIDER),
new NavigationHeader('Accounts', '/accounts', UserPermission::ADMIN)
];
/** @var User|null $activeUser */
$currentPermission = $activeUser === null ? UserPermission::NONE : $activeUser->getPermission();
?>
@ -15,7 +22,19 @@ ContainerHandler::get(LoginHandler::class);
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar-content">
<ul class="navbar-nav me-auto mb-2 mb-lg-0"></ul>
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<?php foreach ($headers as $header):
if (!$currentPermission->hasLevel($header->minimumPermission)) {
continue;
}
?>
<li class="nav-link">
<a href="<?= $header->link ?>" class="nav-link"><?= $header->title ?></a>
</li>
<?php endforeach; ?>
</ul>
<?= $this->insert('layout/accountDisplay'); ?>
</div>

View file

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
use GamesShop\Login\UserPermission;
$this->layout('layout/main', [ 'resourceEntry' => 'admin/accounts' ]);
?>
<h1>Users</h1>
<table id="user-table" class="table table-striped w-100">
<thead>
<tr>
<th width="2.4rem"></th>
<th>Name</th>
<th>Permission</th>
<th>Login-Method</th>
</tr>
</thead>
<tbody></tbody>
</table>
<?php $this->start('modal') ?>
<div class="modal" id="edit-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title h3">
Edit User
</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-2">
Name: <span class="name-input"></span>
</div>
<div class="mb-2">
Login Method: <span class="login-method"></span>
</div>
<div>
<label for="permissions">Permissions:</label>
<select name="" id="permissions" class="form-select permission-editor">
<?php foreach (UserPermission::cases() as $userPermission):?>
<option value="<?= $userPermission->value ?>"><?= $userPermission->getHumanReadableName() ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary js--save">Save changes</button>
</div>
</div>
</div>
</div>
<?php $this->end() ?>