89 lines
No EOL
2.4 KiB
Text
89 lines
No EOL
2.4 KiB
Text
@using LANCommander.SDK.Models
|
|
@inject AuthenticationService AuthenticationService
|
|
@inject SDK.Client Client
|
|
@inject NavigationManager NavigationManager
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<RegistrationForm> Logger
|
|
|
|
<PageHeader OnBack="OnBack">
|
|
<TitleTemplate>
|
|
Register
|
|
</TitleTemplate>
|
|
</PageHeader>
|
|
<Form Model="@Model" Loading="@Loading" Layout="FormLayout.Vertical" OnFinish="OnFinish">
|
|
<FormItem Label="Server Address">
|
|
<Input Value="ServerAddress" Disabled />
|
|
</FormItem>
|
|
<FormItem Label="Username">
|
|
<Input @bind-Value="@context.UserName"/>
|
|
</FormItem>
|
|
<FormItem Label="Password">
|
|
<InputPassword @bind-Value="@context.Password"/>
|
|
</FormItem>
|
|
<FormItem Label="Confirm Password">
|
|
<InputPassword @bind-Value="@context.PasswordConfirmation" />
|
|
</FormItem>
|
|
<FormItem>
|
|
<Button Type="ButtonType.Primary" HtmlType="submit">
|
|
Register
|
|
</Button>
|
|
</FormItem>
|
|
</Form>
|
|
|
|
@code {
|
|
[Parameter] public string ServerAddress { get; set; }
|
|
[Parameter] public EventCallback OnBack { get; set; }
|
|
|
|
RegistrationRequest Model = new();
|
|
bool Loading = false;
|
|
|
|
Models.Settings Settings = SettingService.GetSettings();
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
Client.ChangeServerAddress(ServerAddress);
|
|
|
|
StateHasChanged();
|
|
}
|
|
|
|
async Task OnFinish(EditContext editContext)
|
|
{
|
|
Loading = true;
|
|
|
|
try
|
|
{
|
|
await AuthenticationService.Register(Client.GetServerAddress(), Model.UserName, Model.Password, Model.PasswordConfirmation);
|
|
|
|
MainLayout.Import();
|
|
|
|
NavigationManager.NavigateTo("/");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error(ex.Message, 5);
|
|
Logger.LogError(ex, ex.Message);
|
|
Loading = false;
|
|
}
|
|
}
|
|
|
|
async Task UseToken(AuthToken token)
|
|
{
|
|
Settings.Authentication.AccessToken = token.AccessToken;
|
|
Settings.Authentication.RefreshToken = token.RefreshToken;
|
|
|
|
try
|
|
{
|
|
await AuthenticationService.Login(ServerAddress, token);
|
|
|
|
MainLayout.Import();
|
|
|
|
NavigationManager.NavigateTo("/");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error(ex.Message, 5);
|
|
Logger.LogError(ex, ex.Message);
|
|
Loading = false;
|
|
}
|
|
}
|
|
} |