big restructure

This commit is contained in:
2026-02-11 19:28:12 +01:00
parent cd59ccd99b
commit 3eb9cc0ac4
209 changed files with 5101 additions and 2459 deletions

View File

@@ -20,10 +20,14 @@
* @var bool $isReadOnly
* @var bool $showPermissions
* @var array $permissionRows
* @var bool $showPasswordResets
* @var array $passwordResets
* @var bool $showRememberTokens
* @var array $rememberTokens
*/
use MintyPHP\Session;
use MintyPHP\Service\UserService;
use MintyPHP\Service\User\UserService;
use MintyPHP\I18n;
$values = $values ?? [];
@@ -50,6 +54,10 @@ if (!$primaryTenantId && count($selectedTenantIds) === 1) {
$isReadOnly = $isReadOnly ?? false;
$permissionRows = $permissionRows ?? [];
$showPermissions = $showPermissions ?? false;
$passwordResets = $passwordResets ?? [];
$showPasswordResets = $showPasswordResets ?? false;
$rememberTokens = $rememberTokens ?? [];
$showRememberTokens = $showRememberTokens ?? false;
$minLength = UserService::passwordMinLength();
$requiredAttr = $passwordRequired ? 'required' : '';
$readonlyAttr = $isReadOnly ? 'readonly' : '';
@@ -73,12 +81,16 @@ $showOrganization = $showTenants || $showDepartments || $showRoles;
<?php if ($showPermissions): ?>
<button type="button" data-tab="permissions"><?php e(t('Permissions')); ?></button>
<?php endif; ?>
<?php if ($showPasswordResets): ?>
<button type="button" data-tab="password-resets"><?php e(t('Password resets')); ?></button>
<?php endif; ?>
<?php if ($showRememberTokens): ?>
<button type="button" data-tab="login-tokens"><?php e(t('Login tokens')); ?></button>
<?php endif; ?>
</div>
<div data-tab-panel="profile">
<details name="identity-data" open>
<summary><?php e(t('Identity')); ?></summary>
<hr>
<div class="grid">
<label for="first_name">
<span><?php e(t('First name')); ?></span>
@@ -95,7 +107,7 @@ $showOrganization = $showTenants || $showDepartments || $showRoles;
<span><?php e(t('Email')); ?></span>
<input required type="email" name="email" id="email" value="<?php e($values['email'] ?? ''); ?>" <?php e($readonlyAttr); ?> />
</label>
</details>
<hr>
<details name="profile-data" open>
<summary><?php e(t('Profile')); ?></summary>
@@ -119,14 +131,19 @@ $showOrganization = $showTenants || $showDepartments || $showRoles;
<?php if (allowUserTheme()): ?>
<label for="theme">
<span><?php e(t('Theme')); ?></span>
<?php $selectedTheme = $values['theme'] ?? 'light'; ?>
<?php
$themes = appThemes();
$selectedTheme = (string) ($values['theme'] ?? '');
if ($selectedTheme === '' || !isset($themes[$selectedTheme])) {
$selectedTheme = appDefaultTheme();
}
?>
<select name="theme" id="theme" <?php e($disabledAttr); ?>>
<option value="light" <?php if ($selectedTheme === 'light') { ?>selected<?php } ?>>
<?php e(t('Light')); ?>
</option>
<option value="dark" <?php if ($selectedTheme === 'dark') { ?>selected<?php } ?>>
<?php e(t('Dark')); ?>
</option>
<?php foreach ($themes as $key => $label): ?>
<option value="<?php e($key); ?>" <?php if ($selectedTheme === $key) { ?>selected<?php } ?>>
<?php e(t($label)); ?>
</option>
<?php endforeach; ?>
</select>
</label>
<?php endif; ?>
@@ -154,9 +171,7 @@ $showOrganization = $showTenants || $showDepartments || $showRoles;
</div>
<div data-tab-panel="access">
<details name="access-data" open>
<summary><?php e(t('Access & password')); ?></summary>
<hr>
<div class="grid">
<div>
<label for="password">
@@ -188,7 +203,6 @@ $showOrganization = $showTenants || $showDepartments || $showRoles;
<span><?php e(t('Active')); ?></span>
</label>
<?php endif; ?>
</details>
</div>
<?php if ($showOrganization): ?>
@@ -313,45 +327,152 @@ $showOrganization = $showTenants || $showDepartments || $showRoles;
</div>
<?php if ($showPermissions): ?>
<div data-tab-panel="permissions">
<table>
<thead>
<tr>
<th><?php e(t('Description')); ?></th>
<th><?php e(t('Permission key')); ?></th>
<th><?php e(t('Permission origin')); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($permissionRows as $permissionRow): ?>
<?php
$permissionKey = (string) ($permissionRow['key'] ?? '');
$labelKey = 'perm.' . $permissionKey;
$label = t($labelKey);
if ($label === $labelKey) {
$label = (string) ($permissionRow['description'] ?? '');
if ($label === '') {
$label = $permissionKey;
}
}
$rolesList = [];
if (!empty($permissionRow['roles']) && is_array($permissionRow['roles'])) {
$rolesList = $permissionRow['roles'];
}
?>
<div class="overflow-auto white-space-nowrap">
<table>
<thead>
<tr>
<td><?php e($label); ?></td>
<td><code><?php e($permissionKey); ?></code></td>
<td>
<?php if ($rolesList): ?>
<?php foreach ($rolesList as $roleLabel): ?>
<span class="badge" data-variant="neutral"><?php e($roleLabel); ?></span>
<?php endforeach; ?>
<?php endif; ?>
</td>
<th><?php e(t('Description')); ?></th>
<th><?php e(t('Permission key')); ?></th>
<th><?php e(t('Permission origin')); ?></th>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</thead>
<tbody>
<?php foreach ($permissionRows as $permissionRow): ?>
<?php
$permissionKey = (string) ($permissionRow['key'] ?? '');
$labelKey = 'perm.' . $permissionKey;
$label = t($labelKey);
if ($label === $labelKey) {
$label = (string) ($permissionRow['description'] ?? '');
if ($label === '') {
$label = $permissionKey;
}
}
$rolesList = [];
if (!empty($permissionRow['roles']) && is_array($permissionRow['roles'])) {
$rolesList = $permissionRow['roles'];
}
?>
<tr>
<td><?php e($label); ?></td>
<td><code><?php e($permissionKey); ?></code></td>
<td>
<?php if ($rolesList): ?>
<?php foreach ($rolesList as $roleLabel): ?>
<span class="badge" data-variant="neutral"><?php e($roleLabel); ?></span>
<?php endforeach; ?>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
<?php if ($showPasswordResets): ?>
<div data-tab-panel="password-resets">
<div class="overflow-auto white-space-nowrap">
<table>
<thead>
<tr>
<th><?php e(t('Requested at')); ?></th>
<th><?php e(t('Expires at')); ?></th>
<th><?php e(t('Used at')); ?></th>
<th><?php e(t('Attempts')); ?></th>
<th><?php e(t('Status')); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($passwordResets as $reset): ?>
<?php
$expiresAt = (string) ($reset['expires_at'] ?? '');
$usedAt = (string) ($reset['used_at'] ?? '');
$status = t('Active');
$statusVariant = 'success';
if ($usedAt !== '') {
$status = t('Used');
$statusVariant = 'neutral';
} elseif ($expiresAt !== '') {
try {
$expired = (new \DateTimeImmutable($expiresAt)) <= new \DateTimeImmutable('now');
if ($expired) {
$status = t('Expired');
$statusVariant = 'warning';
}
} catch (\Exception $e) {
// fallback: keep Active
}
}
?>
<tr>
<td><?php e(dt($reset['created'] ?? '')); ?></td>
<td><?php e($expiresAt !== '' ? dt($expiresAt) : '-'); ?></td>
<td><?php e($usedAt !== '' ? dt($usedAt) : '-'); ?></td>
<td><?php e((string) ($reset['attempts'] ?? 0)); ?></td>
<td>
<span class="badge" data-variant="<?php e($statusVariant); ?>">
<?php e($status); ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
<?php if ($showRememberTokens): ?>
<div data-tab-panel="login-tokens">
<div class="overflow-auto white-space-nowrap">
<table>
<thead>
<tr>
<th><?php e(t('Created at')); ?></th>
<th><?php e(t('Expires at')); ?></th>
<th><?php e(t('Last used')); ?></th>
<th><?php e(t('Status')); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($rememberTokens as $token): ?>
<?php
$expiresAt = (string) ($token['expires_at'] ?? '');
$expiredByAdminAt = (string) ($token['expired_by_admin_at'] ?? '');
$lastUsed = (string) ($token['last_used'] ?? '');
$status = t('Active');
$statusVariant = 'success';
if ($expiresAt !== '') {
try {
$expired = (new \DateTimeImmutable($expiresAt)) <= new \DateTimeImmutable('now');
if ($expired) {
if ($expiredByAdminAt !== '') {
$status = t('Expired by admin');
$statusVariant = 'warning';
} else {
$status = t('Expired');
$statusVariant = 'warning';
}
}
} catch (\Exception $e) {
// fallback: keep Active
}
}
?>
<tr>
<td><?php e(dt($token['created'] ?? '')); ?></td>
<td><?php e($expiresAt !== '' ? dt($expiresAt) : '-'); ?></td>
<td><?php e($lastUsed !== '' ? dt($lastUsed) : '-'); ?></td>
<td>
<span class="badge" data-variant="<?php e($statusVariant); ?>">
<?php e($status); ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
</div>