99 lines
No EOL
2.9 KiB
Text
99 lines
No EOL
2.9 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 Uri ServerAddress { get; set; }
|
|
[Parameter] public EventCallback OnBack { get; set; }
|
|
[Parameter] public IEnumerable<string> Errors { get; set; } = [];
|
|
|
|
RegistrationRequest Model = new();
|
|
bool Loading = false;
|
|
private Uri? PreviousServerAddress;
|
|
|
|
Models.Settings Settings = SettingService.GetSettings();
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (ServerAddress != PreviousServerAddress)
|
|
await Client.Connection.UpdateServerAddressAsync(ServerAddress.ToString());
|
|
|
|
PreviousServerAddress = ServerAddress;
|
|
|
|
ClearErrors();
|
|
|
|
}
|
|
|
|
protected void ClearErrors()
|
|
{
|
|
Errors = [];
|
|
StateHasChanged();
|
|
}
|
|
|
|
async Task OnFinish(EditContext editContext)
|
|
{
|
|
Loading = true;
|
|
|
|
try
|
|
{
|
|
ClearErrors();
|
|
|
|
await AuthenticationService.Register(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;
|
|
}
|
|
}
|
|
} |