2026-07-16 21:19:16 +00:00
|
|
|
@page "/users"
|
2026-07-19 07:04:25 +00:00
|
|
|
@attribute [Authorize(Policy = "Admin.Users")]
|
2026-07-16 21:19:16 +00:00
|
|
|
@layout MainLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject ISnackbar Snackbar
|
|
|
|
|
|
2026-08-10 22:41:49 +02:00
|
|
|
<MudText Typo="Typo.h1" Class="mb-6">
|
2026-07-27 20:11:31 +00:00
|
|
|
<i class="fas fa-users mr-2"></i>
|
2026-07-16 21:19:16 +00:00
|
|
|
Utilisateurs
|
|
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showCreate = true)" Class="mb-4">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.PersonAdd" Class="mr-1" /> Nouvel utilisateur
|
|
|
|
|
</MudButton>
|
|
|
|
|
|
|
|
|
|
@if (_loading)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Indeterminate="true" />
|
|
|
|
|
}
|
2026-07-18 18:58:20 +00:00
|
|
|
else if (_error)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
|
|
|
|
<MudText>Erreur lors du chargement des utilisateurs.</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadUsers" Class="mt-2">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
2026-07-16 21:19:16 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudTable Items="@_users" Hover="true" Striped="true" Elevation="2">
|
|
|
|
|
<HeaderContent>
|
|
|
|
|
<MudTh>Nom</MudTh>
|
|
|
|
|
<MudTh>Email</MudTh>
|
|
|
|
|
<MudTh>Rôles</MudTh>
|
|
|
|
|
<MudTh>Statut</MudTh>
|
|
|
|
|
<MudTh>Inscrit le</MudTh>
|
|
|
|
|
<MudTh>Actions</MudTh>
|
|
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
|
|
|
|
<MudTd DataLabel="Nom">@context.DisplayName</MudTd>
|
|
|
|
|
<MudTd DataLabel="Email">@context.Email</MudTd>
|
|
|
|
|
<MudTd DataLabel="Rôles">
|
|
|
|
|
@foreach (var r in context.Roles ?? [])
|
|
|
|
|
{
|
2026-07-20 10:03:12 +00:00
|
|
|
<MudText Typo="Typo.body2" Class="d-inline mr-1" @key="r"
|
2026-07-16 21:19:16 +00:00
|
|
|
Color="@(r=="Admin"?Color.Tertiary:r=="Supervisor"?Color.Secondary:Color.Primary)">
|
|
|
|
|
@r
|
|
|
|
|
</MudText>
|
|
|
|
|
}
|
|
|
|
|
</MudTd>
|
|
|
|
|
<MudTd DataLabel="Statut">
|
|
|
|
|
@if (context.IsLockedOut)
|
|
|
|
|
{
|
|
|
|
|
<MudText Color="Color.Error" Typo="Typo.body2">🔒 Verrouillé</MudText>
|
|
|
|
|
}
|
|
|
|
|
else if (!context.EmailConfirmed)
|
|
|
|
|
{
|
|
|
|
|
<MudText Color="Color.Warning" Typo="Typo.body2">⏳ En attente</MudText>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudText Color="Color.Success" Typo="Typo.body2">✓ Actif</MudText>
|
|
|
|
|
}
|
|
|
|
|
</MudTd>
|
|
|
|
|
<MudTd DataLabel="Inscrit le">@context.CreatedAt.ToString("g")</MudTd>
|
|
|
|
|
<MudTd DataLabel="Actions">
|
2026-07-19 07:12:40 +00:00
|
|
|
<MudTooltip Text="Modifier cet utilisateur (rôles, statut, mot de passe)">
|
2026-08-10 22:41:49 +02:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small" aria-label="Modifier l'utilisateur"
|
2026-07-19 07:12:40 +00:00
|
|
|
OnClick="@(() => OpenEdit(context))" />
|
|
|
|
|
</MudTooltip>
|
2026-08-27 16:49:45 +02:00
|
|
|
<MudTooltip Text="Supprimer cet utilisateur">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" aria-label="Supprimer l'utilisateur"
|
|
|
|
|
Color="Color.Error"
|
|
|
|
|
OnClick="@(() => OpenDeleteConfirm(context))" />
|
|
|
|
|
</MudTooltip>
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudTd>
|
|
|
|
|
</RowTemplate>
|
|
|
|
|
<NoRecordsContent>
|
|
|
|
|
<MudText Align="Align.Center" Class="py-4">Aucun utilisateur</MudText>
|
|
|
|
|
</NoRecordsContent>
|
|
|
|
|
</MudTable>
|
|
|
|
|
|
|
|
|
|
@* Pagination *@
|
|
|
|
|
<MudPaper Class="d-flex align-center pa-4 mt-4">
|
|
|
|
|
<MudText Typo="Typo.body2" Class="mr-4">
|
|
|
|
|
Page @_page sur @_totalPages (@_total utilisateurs)
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" Class="mr-2"
|
|
|
|
|
Disabled="@(_page <= 1)" OnClick="@(() => GoToPage(_page - 1))">
|
|
|
|
|
← Précédent
|
|
|
|
|
</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small"
|
|
|
|
|
Disabled="@(_page >= _totalPages)" OnClick="@(() => GoToPage(_page + 1))">
|
|
|
|
|
Suivant →
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@* Dialog: Créer un utilisateur *@
|
|
|
|
|
<MudOverlay Visible="@_showCreate" OnClick="@(() => _showCreate = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_showCreate">
|
|
|
|
|
<TitleContent><MudText Typo="Typo.h6">Nouvel utilisateur</MudText></TitleContent>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<MudTextField @bind-Value="_createEmail" Label="Email *" Variant="Variant.Outlined"
|
2026-07-19 06:34:32 +00:00
|
|
|
Class="mb-4" Required="true" Immediate="true"
|
|
|
|
|
Autocomplete="email" />
|
2026-07-16 21:19:16 +00:00
|
|
|
<MudTextField @bind-Value="_createDisplayName" Label="Nom d'affichage *" Variant="Variant.Outlined"
|
2026-07-19 06:34:32 +00:00
|
|
|
Class="mb-4" Required="true" Immediate="true"
|
|
|
|
|
Autocomplete="name" />
|
2026-07-16 21:19:16 +00:00
|
|
|
<MudTextField @bind-Value="_createPassword" Label="Mot de passe *" Variant="Variant.Outlined"
|
|
|
|
|
InputType="InputType.Password" Class="mb-4" Required="true" Immediate="true"
|
2026-07-19 06:34:32 +00:00
|
|
|
HelperText="Minimum 12 caractères"
|
|
|
|
|
Autocomplete="new-password" />
|
2026-07-16 21:19:16 +00:00
|
|
|
<MudText Typo="Typo.body2" Class="mb-2">Rôle</MudText>
|
|
|
|
|
<MudSelect @bind-Value="_createRole" Label="Rôle" Variant="Variant.Outlined" Class="mb-4">
|
|
|
|
|
<MudSelectItem Value="@("Viewer")">Viewer</MudSelectItem>
|
|
|
|
|
<MudSelectItem Value="@("Supervisor")">Supervisor</MudSelectItem>
|
|
|
|
|
<MudSelectItem Value="@("Admin")">Admin</MudSelectItem>
|
|
|
|
|
</MudSelect>
|
|
|
|
|
@if (!string.IsNullOrEmpty(_createError))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_createError</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showCreate = false)">Annuler</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@CreateUser" Disabled="@_saving">
|
|
|
|
|
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
|
|
|
|
Créer
|
|
|
|
|
</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
|
|
|
|
@* Dialog: Modifier un utilisateur *@
|
|
|
|
|
<MudOverlay Visible="@_showEdit" OnClick="@(() => _showEdit = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_showEdit" Class="edit-user-dialog">
|
2026-08-10 21:14:27 +02:00
|
|
|
<TitleContent><MudText Typo="Typo.h6">Utilisateur : @_editUser!.DisplayName</MudText></TitleContent>
|
2026-07-16 21:19:16 +00:00
|
|
|
<DialogContent>
|
2026-08-10 21:14:27 +02:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">@_editUser!.Email</MudText>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
|
|
|
|
@* Section: Informations *@
|
|
|
|
|
<MudText Typo="Typo.subtitle1" Class="mb-2">Informations</MudText>
|
|
|
|
|
<MudTextField @bind-Value="_editDisplayName" Label="Nom d'affichage" Variant="Variant.Outlined"
|
|
|
|
|
Class="mb-4" Immediate="true" />
|
|
|
|
|
<MudTextField @bind-Value="_editTheme" Label="Thème" Variant="Variant.Outlined"
|
|
|
|
|
Class="mb-4" Immediate="true" HelperText="Light, Dark ou Auto" />
|
2026-07-21 08:47:24 +00:00
|
|
|
<MudSelect @bind-Value="_editLanguage" Label="Langue" Variant="Variant.Outlined" Class="mb-4" Immediate="true">
|
|
|
|
|
<MudSelectItem Value="@("fr")">Français</MudSelectItem>
|
|
|
|
|
<MudSelectItem Value="@("en")">English</MudSelectItem>
|
|
|
|
|
</MudSelect>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-07-17 13:26:15 +00:00
|
|
|
@* Section: Rôles (multi-sélection) *@
|
2026-07-16 21:19:16 +00:00
|
|
|
<MudText Typo="Typo.subtitle1" Class="mb-2 mt-4">Rôles</MudText>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-2">
|
2026-07-17 13:26:15 +00:00
|
|
|
Un utilisateur peut avoir plusieurs rôles
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudText>
|
2026-07-19 06:34:32 +00:00
|
|
|
<MudPaper Class="pa-4 mb-4 user-section-card" Elevation="0">
|
2026-07-17 13:26:15 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12">
|
2026-08-10 16:46:08 +02:00
|
|
|
<MudCheckBox T="bool" @bind-Value="_editRoleAdmin" Color="Color.Tertiary" Label="Admin — accès complet à toutes les fonctionnalités" />
|
2026-07-17 13:26:15 +00:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12">
|
2026-08-10 16:46:08 +02:00
|
|
|
<MudCheckBox T="bool" @bind-Value="_editRoleSupervisor" Color="Color.Secondary" Label="Supervisor — gestion des sites, caméras et événements" />
|
2026-07-17 13:26:15 +00:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12">
|
2026-08-10 16:46:08 +02:00
|
|
|
<MudCheckBox T="bool" @bind-Value="_editRoleViewer" Color="Color.Primary" Label="Viewer — consultation en lecture seule" />
|
2026-07-17 13:26:15 +00:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
</MudPaper>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
|
|
|
|
@* Section: Statut du compte *@
|
|
|
|
|
<MudText Typo="Typo.subtitle1" Class="mb-2 mt-4">Statut du compte</MudText>
|
2026-07-19 06:34:32 +00:00
|
|
|
<MudPaper Class="pa-4 mb-4 user-section-card" Elevation="0">
|
2026-07-16 21:19:16 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">2FA</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">
|
2026-08-10 21:14:27 +02:00
|
|
|
<MudIcon Icon="@(_editUser!.TwoFactorEnabled ? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Cancel)"
|
|
|
|
|
Color="@(_editUser!.TwoFactorEnabled ? Color.Success : Color.Default)" Size="Size.Small" />
|
|
|
|
|
@(_editUser!.TwoFactorEnabled ? "Activé" : "Désactivé")
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Email confirmé</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">
|
2026-08-10 21:14:27 +02:00
|
|
|
<MudIcon Icon="@(_editUser!.EmailConfirmed ? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Cancel)"
|
|
|
|
|
Color="@(_editUser!.EmailConfirmed ? Color.Success : Color.Default)" Size="Size.Small" />
|
|
|
|
|
@(_editUser!.EmailConfirmed ? "Oui" : "Non")
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Tentatives échouées</MudText>
|
2026-08-10 21:14:27 +02:00
|
|
|
<MudText Typo="Typo.body1">@_editUser!.AccessFailedCount / 5</MudText>
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Verrouillé</MudText>
|
2026-08-10 21:14:27 +02:00
|
|
|
<MudText Typo="Typo.body1" Color="@(_editUser!.IsLockedOut ? Color.Error : Color.Success)">
|
|
|
|
|
@(_editUser!.IsLockedOut ? "Oui" : "Non")
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
|
|
|
|
|
@* Actions du compte *@
|
|
|
|
|
<MudText Typo="Typo.subtitle1" Class="mb-2 mt-4">Actions</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Warning" FullWidth="true" Class="mb-2"
|
|
|
|
|
OnClick="@ResetPassword">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.LockReset" Class="mr-1" /> Réinitialiser le mot de passe
|
|
|
|
|
</MudButton>
|
2026-08-10 21:14:27 +02:00
|
|
|
@if (_editUser!.IsLockedOut)
|
2026-07-16 21:19:16 +00:00
|
|
|
{
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Success" FullWidth="true" Class="mb-2"
|
|
|
|
|
OnClick="@UnlockUser">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.LockOpen" Class="mr-1" /> Déverrouiller le compte
|
|
|
|
|
</MudButton>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Error" FullWidth="true" Class="mb-2"
|
|
|
|
|
OnClick="@LockUser">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Lock" Class="mr-1" /> Verrouiller le compte
|
|
|
|
|
</MudButton>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@if (!string.IsNullOrEmpty(_editError))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mt-2">@_editError</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
@if (!string.IsNullOrEmpty(_temporaryPassword))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Warning" Class="mt-2">
|
|
|
|
|
<strong>Nouveau mot de passe temporaire :</strong><br />
|
2026-08-11 10:55:11 +02:00
|
|
|
<code class="hmd-code-block mt-2">
|
2026-07-16 21:19:16 +00:00
|
|
|
@_temporaryPassword
|
|
|
|
|
</code>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Warning" Class="mt-2">
|
|
|
|
|
⚠ L'utilisateur devra changer ce mot de passe à la prochaine connexion.
|
|
|
|
|
</MudText>
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<MudButton Variant="Variant.Text" OnClick="@CloseEdit">Fermer</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@SaveEdit" Disabled="@_saving">
|
|
|
|
|
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
|
|
|
|
Enregistrer
|
|
|
|
|
</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
2026-08-27 16:49:45 +02:00
|
|
|
@* Dialog: Supprimer un utilisateur *@
|
|
|
|
|
<MudOverlay Visible="@_showDeleteConfirm" OnClick="@(() => _showDeleteConfirm = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_showDeleteConfirm">
|
|
|
|
|
<TitleContent>
|
|
|
|
|
<MudText Typo="Typo.h6" Color="Color.Error">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Warning" Class="mr-1" /> Supprimer l'utilisateur
|
|
|
|
|
</MudText>
|
|
|
|
|
</TitleContent>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<MudText Typo="Typo.body1" Class="mb-2">
|
|
|
|
|
Souhaitez-vous vraiment supprimer l'utilisateur suivant ?
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1" Class="mb-1">
|
|
|
|
|
<strong>@_deleteUserTarget?.DisplayName</strong>
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
|
|
|
@_deleteUserTarget?.Email
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudAlert Severity="Severity.Warning" Variant="Variant.Filled" Class="mb-2">
|
|
|
|
|
Cette action est irréversible. Toutes les données associées seront supprimées.
|
|
|
|
|
</MudAlert>
|
|
|
|
|
@if (!string.IsNullOrEmpty(_deleteError))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mt-2">@_deleteError</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showDeleteConfirm = false)">Annuler</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@DeleteUser" Disabled="@_deleting">
|
|
|
|
|
@if (_deleting) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
|
|
|
|
Supprimer
|
|
|
|
|
</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
2026-07-16 21:19:16 +00:00
|
|
|
@code {
|
|
|
|
|
private IReadOnlyList<UserItem>? _users;
|
|
|
|
|
private bool _loading = true;
|
2026-07-18 18:58:20 +00:00
|
|
|
private bool _error;
|
2026-07-16 21:19:16 +00:00
|
|
|
private int _page = 1;
|
|
|
|
|
private int _totalPages = 1;
|
|
|
|
|
private int _total;
|
|
|
|
|
private bool _saving;
|
|
|
|
|
|
|
|
|
|
// Create dialog
|
|
|
|
|
private bool _showCreate;
|
|
|
|
|
private string _createEmail = "";
|
|
|
|
|
private string _createPassword = "";
|
|
|
|
|
private string _createDisplayName = "";
|
|
|
|
|
private string _createRole = "Viewer";
|
|
|
|
|
private string _createError = "";
|
|
|
|
|
|
|
|
|
|
// Edit dialog
|
|
|
|
|
private UserItem? _editUser;
|
|
|
|
|
private bool _showEdit;
|
|
|
|
|
private string _editDisplayName = "";
|
|
|
|
|
private string _editTheme = "";
|
2026-07-21 08:47:24 +00:00
|
|
|
private string _editLanguage = "fr";
|
2026-07-17 13:26:15 +00:00
|
|
|
private bool _editRoleAdmin;
|
|
|
|
|
private bool _editRoleSupervisor;
|
|
|
|
|
private bool _editRoleViewer;
|
2026-07-16 21:19:16 +00:00
|
|
|
private string _editError = "";
|
|
|
|
|
private string _temporaryPassword = "";
|
|
|
|
|
|
2026-08-27 16:49:45 +02:00
|
|
|
// Delete dialog
|
|
|
|
|
private bool _showDeleteConfirm;
|
|
|
|
|
private bool _deleting;
|
|
|
|
|
private UserItem? _deleteUserTarget;
|
|
|
|
|
private string _deleteError = "";
|
|
|
|
|
|
2026-07-16 21:19:16 +00:00
|
|
|
protected override async Task OnInitializedAsync() => await LoadUsers();
|
|
|
|
|
|
|
|
|
|
private async Task LoadUsers()
|
|
|
|
|
{
|
|
|
|
|
_loading = true;
|
2026-07-18 18:58:20 +00:00
|
|
|
_error = false;
|
2026-07-16 21:19:16 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.GetUsersAsync(_page);
|
|
|
|
|
if (result is not null)
|
|
|
|
|
{
|
|
|
|
|
_users = result.Items;
|
|
|
|
|
_total = result.TotalCount;
|
|
|
|
|
_totalPages = Math.Max(1, (int)Math.Ceiling(result.TotalCount / (double)result.PageSize));
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-10 23:33:06 +02:00
|
|
|
catch {
|
2026-07-18 18:58:20 +00:00
|
|
|
_error = true;
|
2026-08-10 23:33:06 +02:00
|
|
|
Snackbar.Add(UiErrors.OperationFailed(), Severity.Error);
|
2026-07-18 18:58:20 +00:00
|
|
|
}
|
2026-07-16 21:19:16 +00:00
|
|
|
finally { _loading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task GoToPage(int p)
|
|
|
|
|
{
|
|
|
|
|
_page = p;
|
|
|
|
|
await LoadUsers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Create ───────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
private async Task CreateUser()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(_createEmail) || string.IsNullOrWhiteSpace(_createPassword)
|
|
|
|
|
|| string.IsNullOrWhiteSpace(_createDisplayName))
|
|
|
|
|
{ _createError = "Tous les champs sont requis"; return; }
|
|
|
|
|
_saving = true;
|
|
|
|
|
_createError = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.CreateUserAsync(_createEmail, _createPassword, _createDisplayName,
|
|
|
|
|
new List<string> { _createRole });
|
|
|
|
|
if (result is null) { _createError = "Erreur lors de la création"; return; }
|
|
|
|
|
_showCreate = false;
|
|
|
|
|
_createEmail = ""; _createPassword = ""; _createDisplayName = ""; _createRole = "Viewer";
|
|
|
|
|
Snackbar.Add("Utilisateur créé avec succès", Severity.Success);
|
|
|
|
|
await LoadUsers();
|
|
|
|
|
}
|
2026-08-10 23:33:06 +02:00
|
|
|
catch { _createError = UiErrors.OperationFailed(); }
|
2026-07-16 21:19:16 +00:00
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Edit ─────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
private void OpenEdit(UserItem user)
|
|
|
|
|
{
|
|
|
|
|
_editUser = user;
|
|
|
|
|
_editDisplayName = user.DisplayName;
|
|
|
|
|
_editTheme = user.Theme ?? "Auto";
|
2026-07-21 08:47:24 +00:00
|
|
|
_editLanguage = user.Language;
|
2026-07-17 13:26:15 +00:00
|
|
|
_editRoleAdmin = user.Roles?.Contains("Admin") == true;
|
|
|
|
|
_editRoleSupervisor = user.Roles?.Contains("Supervisor") == true;
|
|
|
|
|
_editRoleViewer = user.Roles?.Contains("Viewer") == true;
|
2026-07-16 21:19:16 +00:00
|
|
|
_editError = "";
|
|
|
|
|
_temporaryPassword = "";
|
|
|
|
|
_showEdit = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CloseEdit()
|
|
|
|
|
{
|
|
|
|
|
_showEdit = false;
|
|
|
|
|
_editUser = null;
|
|
|
|
|
_temporaryPassword = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SaveEdit()
|
|
|
|
|
{
|
|
|
|
|
if (_editUser is null) return;
|
|
|
|
|
_saving = true;
|
|
|
|
|
_editError = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-07-17 13:26:15 +00:00
|
|
|
var selectedRoles = new List<string>();
|
|
|
|
|
if (_editRoleAdmin) selectedRoles.Add("Admin");
|
|
|
|
|
if (_editRoleSupervisor) selectedRoles.Add("Supervisor");
|
|
|
|
|
if (_editRoleViewer) selectedRoles.Add("Viewer");
|
|
|
|
|
|
|
|
|
|
// Ensure at least one role
|
|
|
|
|
if (selectedRoles.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
_editError = "Au moins un rôle doit être sélectionné";
|
|
|
|
|
_saving = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 08:47:24 +00:00
|
|
|
await Api.UpdateUserAsync(_editUser.Id, _editDisplayName, _editTheme, _editLanguage);
|
2026-07-17 13:26:15 +00:00
|
|
|
await Api.AssignRolesAsync(_editUser.Id, selectedRoles);
|
2026-07-16 21:19:16 +00:00
|
|
|
Snackbar.Add("Utilisateur mis à jour", Severity.Success);
|
|
|
|
|
CloseEdit();
|
|
|
|
|
await LoadUsers();
|
|
|
|
|
}
|
2026-08-10 23:33:06 +02:00
|
|
|
catch { _editError = UiErrors.OperationFailed(); }
|
2026-07-16 21:19:16 +00:00
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Lock / Unlock / Reset Password ───────────────────────────
|
|
|
|
|
|
|
|
|
|
private async Task LockUser()
|
|
|
|
|
{
|
|
|
|
|
if (_editUser is null) return;
|
|
|
|
|
if (await Api.LockUserAsync(_editUser.Id))
|
|
|
|
|
{
|
2026-08-10 21:14:27 +02:00
|
|
|
_editUser!.IsLockedOut = true;
|
2026-07-16 21:19:16 +00:00
|
|
|
Snackbar.Add("Compte verrouillé", Severity.Success);
|
|
|
|
|
}
|
|
|
|
|
else Snackbar.Add("Erreur", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task UnlockUser()
|
|
|
|
|
{
|
|
|
|
|
if (_editUser is null) return;
|
|
|
|
|
if (await Api.UnlockUserAsync(_editUser.Id))
|
|
|
|
|
{
|
2026-08-10 21:14:27 +02:00
|
|
|
_editUser!.IsLockedOut = false;
|
|
|
|
|
_editUser!.AccessFailedCount = 0;
|
2026-07-16 21:19:16 +00:00
|
|
|
Snackbar.Add("Compte déverrouillé", Severity.Success);
|
|
|
|
|
}
|
|
|
|
|
else Snackbar.Add("Erreur", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ResetPassword()
|
|
|
|
|
{
|
|
|
|
|
if (_editUser is null) return;
|
|
|
|
|
_saving = true;
|
|
|
|
|
_temporaryPassword = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.ResetPasswordAsync(_editUser.Id);
|
|
|
|
|
if (result is null) { _editError = "Erreur lors de la réinitialisation"; return; }
|
|
|
|
|
_temporaryPassword = result.TemporaryPassword;
|
|
|
|
|
Snackbar.Add("Mot de passe réinitialisé", Severity.Success);
|
|
|
|
|
}
|
2026-08-10 23:33:06 +02:00
|
|
|
catch { _editError = UiErrors.OperationFailed(); }
|
2026-07-16 21:19:16 +00:00
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
2026-08-27 16:49:45 +02:00
|
|
|
|
|
|
|
|
// ─── Delete ────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
private void OpenDeleteConfirm(UserItem user)
|
|
|
|
|
{
|
|
|
|
|
_deleteUserTarget = user;
|
|
|
|
|
_deleteError = "";
|
|
|
|
|
_showDeleteConfirm = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task DeleteUser()
|
|
|
|
|
{
|
|
|
|
|
if (_deleteUserTarget is null) return;
|
|
|
|
|
_deleting = true;
|
|
|
|
|
_deleteError = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var error = await Api.DeleteUserAsync(_deleteUserTarget.Id);
|
|
|
|
|
if (error is not null)
|
|
|
|
|
{
|
|
|
|
|
_deleteError = error;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_showDeleteConfirm = false;
|
|
|
|
|
Snackbar.Add("Utilisateur supprimé", Severity.Success);
|
|
|
|
|
await LoadUsers();
|
|
|
|
|
}
|
|
|
|
|
catch { _deleteError = UiErrors.OperationFailed(); }
|
|
|
|
|
finally { _deleting = false; }
|
|
|
|
|
}
|
2026-07-16 21:19:16 +00:00
|
|
|
}
|