Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
120 lines
No EOL
3.5 KiB
Text
120 lines
No EOL
3.5 KiB
Text
@using LANCommander.SDK.Exceptions
|
|
@using LANCommander.SDK.Models
|
|
@inject AuthenticationService AuthenticationService
|
|
@inject SDK.Client Client
|
|
@inject NavigationManager NavigationManager
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<RegistrationForm> Logger
|
|
@inject ImportManagerService ImportManagerService
|
|
@inject LocalizationService LocalizationService
|
|
|
|
<PageHeader OnBack="OnBack">
|
|
<TitleTemplate>
|
|
@LocalizationService.GetString("Register")
|
|
</TitleTemplate>
|
|
</PageHeader>
|
|
<Form Model="@Model" Loading="@Loading" Layout="FormLayout.Vertical" OnFinish="OnFinish">
|
|
|
|
@foreach (var item in Errors)
|
|
{
|
|
<Alert Message="@item" Type="AlertType.Error" ShowIcon="true" Style="margin-bottom: 8px;" />
|
|
}
|
|
|
|
<FormItem Label="@LocalizationService.GetString("ServerAddress")">
|
|
<Input Value="ServerAddress" Disabled />
|
|
</FormItem>
|
|
<FormItem Label="@LocalizationService.GetString("Username")">
|
|
<Input @bind-Value="@context.UserName" AutoFocus />
|
|
</FormItem>
|
|
<FormItem Label="@LocalizationService.GetString("Password")">
|
|
<InputPassword @bind-Value="@context.Password"/>
|
|
</FormItem>
|
|
<FormItem Label="@LocalizationService.GetString("ConfirmPassword")">
|
|
<InputPassword @bind-Value="@context.PasswordConfirmation" />
|
|
</FormItem>
|
|
<FormItem>
|
|
<Button Type="ButtonType.Primary" HtmlType="submit">
|
|
@LocalizationService.GetString("Register")
|
|
</Button>
|
|
</FormItem>
|
|
</Form>
|
|
|
|
@code {
|
|
[Parameter] public string ServerAddress { get; set; }
|
|
[Parameter] public EventCallback OnBack { get; set; }
|
|
[Parameter] public IEnumerable<string> Errors { get; set; } = [];
|
|
|
|
RegistrationRequest Model = new();
|
|
bool Loading = false;
|
|
private string? PreviousServerAddress;
|
|
|
|
Models.Settings Settings = SettingService.GetSettings();
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (ServerAddress != PreviousServerAddress)
|
|
await Client.ChangeServerAddressAsync(ServerAddress);
|
|
|
|
PreviousServerAddress = ServerAddress;
|
|
|
|
ClearErrors();
|
|
|
|
}
|
|
|
|
protected void ClearErrors()
|
|
{
|
|
Errors = [];
|
|
StateHasChanged();
|
|
}
|
|
|
|
async Task OnFinish(EditContext editContext)
|
|
{
|
|
Loading = true;
|
|
|
|
try
|
|
{
|
|
ClearErrors();
|
|
|
|
await AuthenticationService.Register(Client.GetServerAddress(), Model.UserName, Model.Password, Model.PasswordConfirmation);
|
|
|
|
await ImportManagerService.RequestImport();
|
|
|
|
NavigationManager.NavigateTo("/");
|
|
}
|
|
catch (RegisterFailedException ex)
|
|
{
|
|
Errors = ex.ErrorData.Details?.Select(x => x.Message) ?? [];
|
|
MessageService.Error(ex.Message, 5);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error(ex.Message, 5);
|
|
Logger.LogError(ex, ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
Loading = false;
|
|
}
|
|
}
|
|
|
|
async Task UseToken(AuthToken token)
|
|
{
|
|
Settings.Authentication.AccessToken = token.AccessToken;
|
|
Settings.Authentication.RefreshToken = token.RefreshToken;
|
|
|
|
try
|
|
{
|
|
await AuthenticationService.Login(ServerAddress, token);
|
|
|
|
await ImportManagerService.RequestImport();
|
|
|
|
NavigationManager.NavigateTo("/");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error(ex.Message, 5);
|
|
Logger.LogError(ex, ex.Message);
|
|
Loading = false;
|
|
}
|
|
}
|
|
} |