LANCommander/LANCommander.Launcher/UI/Components/AuthenticationForm.razor
2025-10-05 17:13:47 -05:00

62 lines
No EOL
2 KiB
Text

@using LANCommander.Launcher.UI.Authenticate.Components
@using LANCommander.SDK.Services
@inject IMessageService MessageService
@inject IConnectionClient ConnectionClient
<Layout Style="background-image: url('/assets/auth-background.jpg'); background-size: cover;">
<Content Class="authentication-form">
<div class="authentication-logo">
<img src="/assets/logo.svg" width="300" />
</div>
<div class="authentication-box">
@if (_stage == AuthenticationStage.SelectServer)
{
<ServerSelector OnSelected="ServerSelected" Connecting="_connecting" />
}
else if (_stage == AuthenticationStage.Login)
{
<LoginForm ServerAddress="@ConnectionClient.GetServerAddress()" OnBack="() => _stage = AuthenticationStage.SelectServer" OnRegister="() => _stage = AuthenticationStage.Register" />
}
else if (_stage == AuthenticationStage.Register)
{
<RegistrationForm ServerAddress="@ConnectionClient.GetServerAddress()" OnBack="() => _stage = AuthenticationStage.Login" />
}
</div>
</Content>
</Layout>
@code {
bool _connecting { get; set; } = false;
AuthenticationStage _stage = AuthenticationStage.None;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
if (ConnectionClient.HasServerAddress())
_stage = AuthenticationStage.Login;
else
_stage = AuthenticationStage.SelectServer;
}
async Task ServerSelected(Uri serverAddress)
{
try
{
_connecting = true;
await ConnectionClient.UpdateServerAddressAsync(serverAddress);
_stage = AuthenticationStage.Login;
}
catch (Exception ex)
{
MessageService.Error(ex.Message);
}
finally
{
_connecting = false;
}
}
}