114 lines
5.9 KiB
Plaintext
114 lines
5.9 KiB
Plaintext
@using TrafagSalesExporter.Services
|
|
@rendermode @(Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveServer)
|
|
@inject IFinanceCockpitAccessService FinanceAccess
|
|
@inject ISnackbar Snackbar
|
|
@inject NavigationManager Navigation
|
|
@inject IUiTextService UiText
|
|
@inject ILogger<FinanceCockpitUnlockPanel> Logger
|
|
|
|
<MudText Typo="Typo.h4" Class="mb-4">@T("Finance Cockpit", "Finance Cockpit")</MudText>
|
|
|
|
<MudPaper Class="pa-4 mb-4" Elevation="1" Style="max-width:520px;">
|
|
<MudStack Spacing="3">
|
|
<MudAlert Severity="Severity.Warning" Variant="Variant.Outlined">
|
|
@T("Finance Cockpit ist geschuetzt. Bitte separat anmelden.", "Finance Cockpit is protected. Please sign in separately.")
|
|
</MudAlert>
|
|
@if (!FinanceAccess.IsConfigured)
|
|
{
|
|
<MudAlert Severity="Severity.Error" Variant="Variant.Filled">
|
|
@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.")
|
|
</MudAlert>
|
|
}
|
|
<form method="post" action="@AccessUrl">
|
|
<input type="hidden" name="returnUrl" value="@Navigation.Uri" />
|
|
<MudStack Spacing="3">
|
|
<MudTextField T="string" Name="username" Label="@T("Name", "Name")" Disabled="@(!FinanceAccess.IsConfigured)" />
|
|
<MudTextField T="string" Name="password" Label="@T("Passwort", "Password")" InputType="InputType.Password" Disabled="@(!FinanceAccess.IsConfigured)" />
|
|
<button type="submit" class="mud-button-root mud-button mud-button-filled mud-button-filled-primary mud-button-filled-size-medium mud-ripple">
|
|
@T("Finance Cockpit entsperren", "Unlock Finance Cockpit")
|
|
</button>
|
|
</MudStack>
|
|
</form>
|
|
<MudText Typo="Typo.caption">
|
|
@T("Server-Klicks", "Server clicks"): @_unlockClickCount |
|
|
@T("Konfiguriert", "Configured"): @(FinanceAccess.IsConfigured ? "JA" : "NEIN")
|
|
</MudText>
|
|
<MudDivider />
|
|
<MudExpansionPanels Elevation="0">
|
|
<MudExpansionPanel Text="@T("Passwort ändern", "Change password")" Icon="@Icons.Material.Filled.Password">
|
|
<MudStack Spacing="3" Class="pt-2">
|
|
<MudTextField @bind-Value="_changeUsername" Label="@T("Name", "Name")" Disabled="@(!FinanceAccess.IsConfigured)" />
|
|
<MudTextField @bind-Value="_currentPassword" Label="@T("Aktuelles Passwort", "Current password")" InputType="InputType.Password" Disabled="@(!FinanceAccess.IsConfigured)" />
|
|
<MudTextField @bind-Value="_newPassword" Label="@T("Neues Passwort", "New password")" InputType="InputType.Password" HelperText="@T("Mindestens 8 Zeichen.", "At least 8 characters.")" Disabled="@(!FinanceAccess.IsConfigured)" />
|
|
<MudTextField @bind-Value="_newPasswordRepeat" Label="@T("Neues Passwort wiederholen", "Repeat new password")" InputType="InputType.Password" Disabled="@(!FinanceAccess.IsConfigured)" />
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Primary" OnClick="ChangePasswordAsync"
|
|
StartIcon="@Icons.Material.Filled.Save" Disabled="@(!FinanceAccess.IsConfigured)">
|
|
@T("Passwort speichern", "Save password")
|
|
</MudButton>
|
|
</MudStack>
|
|
</MudExpansionPanel>
|
|
</MudExpansionPanels>
|
|
</MudStack>
|
|
</MudPaper>
|
|
|
|
@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);
|
|
}
|