@page "/profile" @attribute [Authorize] @layout MainLayout @inject HeimdallApiClient Api @inject AuthState Auth @inject ISnackbar Snackbar @inject HeimdallAuthStateProvider AuthProvider Mon profil @if (_loading) { } else if (_error) { Erreur lors du chargement du profil. Réessayer } else if (_profile is not null) { @* ─── Section 1: Informations personnelles ─── *@ Informations personnelles @if (!string.IsNullOrEmpty(_profileError)) { @_profileError }
Email @_profile.Email Thème Auto Light Dark Langue Français English @if (_saving) { } Enregistrer
@* ─── Section 2: Statistiques du compte ─── *@ Statistiques du compte Date d'inscription @_profile.CreatedAt.ToString("g") Email confirmé @(_profile.EmailConfirmed ? "Oui" : "Non") 2FA @(_profile.TwoFactorEnabled ? "Activé" : "Désactivé") Rôles @if (_profile.Roles is not null && _profile.Roles.Count > 0) { foreach (var r in _profile.Roles) { @r } } else { Aucun rôle } @* ─── Section 3: Changer le mot de passe ─── *@ Changer le mot de passe @if (!string.IsNullOrEmpty(_passwordError)) { @_passwordError }
@if (_changingPassword) { } Changer le mot de passe
@* ─── Section 4: Notifications ─── *@ Notifications @if (!string.IsNullOrEmpty(_notifError)) { @_notifError } Les notifications push utilisent ntfy (serveur auto-hébergé). Votre topic personnel est heimdall_@_profile.Id. Installez l'app ntfy et abonnez-vous à ce topic pour recevoir les notifications. Canal Email Canal Push (ntfy) Résumés @if (_savingNotif) { } Enregistrer } @code { private UserItem? _profile; private bool _loading = true; private bool _error; private bool _saving; private bool _changingPassword; // Section 1 — Informations personnelles private string _displayName = ""; private string _theme = "Auto"; private string _language = "fr"; private string _profileError = ""; // Section 3 — Changer le mot de passe private string _currentPassword = ""; private string _newPassword = ""; private string _confirmPassword = ""; private string _passwordError = ""; protected override async Task OnInitializedAsync() { await LoadProfile(); await LoadNotificationConfig(); } private async Task LoadProfile() { _loading = true; _error = false; try { var result = await Api.GetMyProfileAsync(); if (result is not null) { _profile = result; _displayName = result.DisplayName; _theme = result.Theme ?? "Auto"; _language = result.Language; } } catch { _error = true; Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); } finally { _loading = false; } } // ─── Section 1: Enregistrer le profil ───────────────────────── private async Task SaveProfile() { if (string.IsNullOrWhiteSpace(_displayName)) { _profileError = "Le nom d'affichage est requis"; return; } _saving = true; _profileError = ""; try { var success = await Api.UpdateMyProfileAsync(_displayName.Trim(), _theme, _language); if (success) { Snackbar.Add("Profil mis à jour avec succès", Severity.Success); } else { _profileError = "Erreur lors de la mise à jour du profil"; } } catch { _profileError = UiErrors.OperationFailed(); } finally { _saving = false; } } // ─── Section 3: Changer le mot de passe ─────────────────────── private async Task ChangePassword() { if (string.IsNullOrWhiteSpace(_currentPassword)) { _passwordError = "Le mot de passe actuel est requis"; return; } if (string.IsNullOrWhiteSpace(_newPassword)) { _passwordError = "Le nouveau mot de passe est requis"; return; } if (_newPassword.Length < 12) { _passwordError = "Le nouveau mot de passe doit contenir au moins 12 caractères"; return; } if (_newPassword != _confirmPassword) { _passwordError = "Les mots de passe ne correspondent pas"; return; } _changingPassword = true; _passwordError = ""; try { var success = await Api.ChangePasswordAsync(_currentPassword, _newPassword); if (success) { _currentPassword = ""; _newPassword = ""; _confirmPassword = ""; Snackbar.Add("Mot de passe changé avec succès", Severity.Success); } else { _passwordError = "Erreur lors du changement de mot de passe. Vérifiez votre mot de passe actuel."; } } catch { _passwordError = UiErrors.OperationFailed(); } finally { _changingPassword = false; } } // ─── Section 4: Notifications ───────────────────────────────── private NotificationConfigItem? _notifConfig; private MudForm? _notifForm; private bool _emailEnabled; private string? _emailAddress; private bool _ntfyEnabled; private string? _ntfyUrl; private bool _dailyDigest; private bool _weeklyDigest; private bool _savingNotif; private string _notifError = ""; private async Task LoadNotificationConfig() { try { _notifConfig = await Api.GetNotificationConfigAsync(); if (_notifConfig is not null) { _emailEnabled = _notifConfig.EmailEnabled; _emailAddress = _notifConfig.EmailAddress; _ntfyEnabled = _notifConfig.NtfyEnabled; _ntfyUrl = _notifConfig.NtfyUrl; _dailyDigest = _notifConfig.DailyDigest; _weeklyDigest = _notifConfig.WeeklyDigest; } } catch (Exception ex) { _notifError = $"Erreur chargement config notifications : {ex.Message}"; } } private async Task SaveNotificationConfig() { _savingNotif = true; _notifError = ""; try { var request = new UpdateNotificationConfigRequest( _emailEnabled, string.IsNullOrWhiteSpace(_emailAddress) ? null : _emailAddress.Trim(), _ntfyEnabled, string.IsNullOrWhiteSpace(_ntfyUrl) ? null : _ntfyUrl.Trim(), _dailyDigest, _weeklyDigest, null // SubscribedEvents — à implémenter dans une version future ); var success = await Api.UpdateNotificationConfigAsync(request); if (success) { Snackbar.Add("Configuration notifications mise à jour", Severity.Success); } else { _notifError = "Erreur lors de la mise à jour"; } } catch { _notifError = UiErrors.OperationFailed(); } finally { _savingNotif = false; } } }