@using TrafagSalesExporter.Services @rendermode @(Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveServer) @inject IFinanceCockpitAccessService FinanceAccess @inject ISnackbar Snackbar @inject NavigationManager Navigation @inject IUiTextService UiText @inject ILogger Logger @T("Finance Cockpit", "Finance Cockpit") @T("Finance Cockpit ist geschuetzt. Bitte separat anmelden.", "Finance Cockpit is protected. Please sign in separately.") @if (!FinanceAccess.IsConfigured) { @T("Finance-Cockpit-Zugang ist noch nicht konfiguriert. Bitte Username und PasswordHash in FinanceCockpitAccess konfigurieren.", "Finance Cockpit access is not configured yet. Please configure Username and PasswordHash in FinanceCockpitAccess.") }
@T("Server-Klicks", "Server clicks"): @_unlockClickCount | @T("Konfiguriert", "Configured"): @(FinanceAccess.IsConfigured ? "JA" : "NEIN") @T("Passwort speichern", "Save password")
@code { private string? _username; private string? _password; private string? _changeUsername; private string? _currentPassword; private string? _newPassword; private string? _newPasswordRepeat; private int _unlockClickCount; private string AccessUrl => new Uri(new Uri(Navigation.BaseUri), "access/finance").ToString(); private Task UnlockAsync() { _unlockClickCount++; Logger.LogInformation( "Finance unlock button handler reached. ClickCount={ClickCount}, IsConfigured={IsConfigured}, UsernameLength={UsernameLength}, PasswordLength={PasswordLength}", _unlockClickCount, FinanceAccess.IsConfigured, _username?.Length ?? 0, _password?.Length ?? 0); if (!FinanceAccess.TryUnlock(_username ?? string.Empty, _password ?? string.Empty)) { Snackbar.Add(T("Finance-Cockpit-Anmeldung fehlgeschlagen.", "Finance Cockpit sign-in failed."), Severity.Error); return Task.CompletedTask; } _password = string.Empty; Navigation.Refresh(forceReload: false); return Task.CompletedTask; } private Task ChangePasswordAsync() { if (string.IsNullOrWhiteSpace(_newPassword) || _newPassword.Length < 8) { Snackbar.Add(T("Das neue Passwort muss mindestens 8 Zeichen lang sein.", "The new password must be at least 8 characters long."), Severity.Warning); return Task.CompletedTask; } if (_newPassword != _newPasswordRepeat) { Snackbar.Add(T("Die neuen Passwörter stimmen nicht überein.", "The new passwords do not match."), Severity.Warning); return Task.CompletedTask; } if (!FinanceAccess.TryChangePassword(_changeUsername ?? string.Empty, _currentPassword ?? string.Empty, _newPassword)) { Snackbar.Add(T("Passwort konnte nicht geändert werden. Name oder aktuelles Passwort prüfen.", "Password could not be changed. Check the name or current password."), Severity.Error); return Task.CompletedTask; } _currentPassword = string.Empty; _newPassword = string.Empty; _newPasswordRepeat = string.Empty; Snackbar.Add(T("Passwort wurde geändert.", "Password has been changed."), Severity.Success); return Task.CompletedTask; } private string T(string german, string english) => UiText.Text(german, english); }