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
|
|
|
|
|
|
|
|
|
|
<MudText Typo="Typo.h4" Class="mb-6">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.People" Class="mr-2" />
|
|
|
|
|
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 ?? [])
|
|
|
|
|
{
|
|
|
|
|
<MudText Typo="Typo.body2" Class="d-inline mr-1"
|
|
|
|
|
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)">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small"
|
|
|
|
|
OnClick="@(() => OpenEdit(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 *@
|
|
|
|
|
@if (_showCreate)
|
|
|
|
|
{
|
|
|
|
|
<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 *@
|
|
|
|
|
@if (_editUser is not null && _showEdit)
|
|
|
|
|
{
|
|
|
|
|
<MudOverlay Visible="@_showEdit" OnClick="@(() => _showEdit = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_showEdit" Class="edit-user-dialog">
|
|
|
|
|
<TitleContent><MudText Typo="Typo.h6">Utilisateur : @_editUser.DisplayName</MudText></TitleContent>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">@_editUser.Email</MudText>
|
|
|
|
|
|
|
|
|
|
@* 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-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">
|
|
|
|
|
<MudCheckBox T="bool" @bind-Checked="_editRoleAdmin" Color="Color.Tertiary" Label="Admin — accès complet à toutes les fonctionnalités" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12">
|
|
|
|
|
<MudCheckBox T="bool" @bind-Checked="_editRoleSupervisor" Color="Color.Secondary" Label="Supervisor — gestion des sites, caméras et événements" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12">
|
|
|
|
|
<MudCheckBox T="bool" @bind-Checked="_editRoleViewer" Color="Color.Primary" Label="Viewer — consultation en lecture seule" />
|
|
|
|
|
</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">
|
|
|
|
|
<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é")
|
|
|
|
|
</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Email confirmé</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">
|
|
|
|
|
<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")
|
|
|
|
|
</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Tentatives échouées</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@_editUser.AccessFailedCount / 5</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Verrouillé</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1" Color="@(_editUser.IsLockedOut ? Color.Error : Color.Success)">
|
|
|
|
|
@(_editUser.IsLockedOut ? "Oui" : "Non")
|
|
|
|
|
</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>
|
|
|
|
|
@if (_editUser.IsLockedOut)
|
|
|
|
|
{
|
|
|
|
|
<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 />
|
|
|
|
|
<code class="mt-2 d-block p-2" style="background:#fff;word-break:break-all;">
|
|
|
|
|
@_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>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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-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 = "";
|
|
|
|
|
|
|
|
|
|
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-07-18 18:58:20 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_error = true;
|
|
|
|
|
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
|
|
|
|
}
|
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();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { _createError = $"Erreur : {ex.Message}"; }
|
|
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Edit ─────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
private void OpenEdit(UserItem user)
|
|
|
|
|
{
|
|
|
|
|
_editUser = user;
|
|
|
|
|
_editDisplayName = user.DisplayName;
|
|
|
|
|
_editTheme = user.Theme ?? "Auto";
|
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-16 21:19:16 +00:00
|
|
|
await Api.UpdateUserAsync(_editUser.Id, _editDisplayName, _editTheme, null);
|
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();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { _editError = $"Erreur : {ex.Message}"; }
|
|
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Lock / Unlock / Reset Password ───────────────────────────
|
|
|
|
|
|
|
|
|
|
private async Task LockUser()
|
|
|
|
|
{
|
|
|
|
|
if (_editUser is null) return;
|
|
|
|
|
if (await Api.LockUserAsync(_editUser.Id))
|
|
|
|
|
{
|
|
|
|
|
_editUser.IsLockedOut = true;
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
_editUser.IsLockedOut = false;
|
|
|
|
|
_editUser.AccessFailedCount = 0;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { _editError = $"Erreur : {ex.Message}"; }
|
|
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
}
|