2026-10-27 22:19:52 +01:00
|
|
|
@page "/setup"
|
|
|
|
|
@layout MudBlazorLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject UiText Text
|
|
|
|
|
@inject HeimdallAuthStateProvider AuthStateProvider
|
|
|
|
|
@inject NavigationManager Navigation
|
|
|
|
|
@inject IJSRuntime JsRuntime
|
2026-11-08 20:03:03 +01:00
|
|
|
@inject Microsoft.Extensions.Logging.ILogger<Setup> Logger
|
2026-10-27 22:19:52 +01:00
|
|
|
|
|
|
|
|
<div class="auth-page">
|
|
|
|
|
<div class="auth-card">
|
|
|
|
|
<div class="auth-header">
|
|
|
|
|
<div class="auth-icon"><i class="fas fa-user-shield"></i></div>
|
|
|
|
|
<h1>@Text["SetupAdmin_Title"]</h1>
|
|
|
|
|
<p>@Text["SetupAdmin_Subtitle"]</p>
|
|
|
|
|
</div>
|
|
|
|
|
@if (_checking)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Indeterminate="true" Color="Color.Primary" />
|
|
|
|
|
}
|
|
|
|
|
else if (_unavailable)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error">@Text["SetupAdmin_Unavailable"]</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<div class="auth-form">
|
|
|
|
|
<form @onsubmit="CreateAdminAsync">
|
|
|
|
|
<MudTextField @bind-Value="_displayName" Label="@Text["SetupAdmin_DisplayName"]"
|
|
|
|
|
Variant="Variant.Outlined" Class="mb-4" Required="true" Immediate="true" Autocomplete="name" />
|
|
|
|
|
<MudTextField @bind-Value="_email" Label="@Text["LoginPage_Email"]"
|
|
|
|
|
Variant="Variant.Outlined" Class="mb-4" Required="true" Immediate="true" Autocomplete="email" />
|
|
|
|
|
<MudTextField @bind-Value="_password" Label="@Text["LoginPage_Password"]"
|
|
|
|
|
Variant="Variant.Outlined" InputType="InputType.Password" Class="mb-4"
|
|
|
|
|
Required="true" Immediate="true" Autocomplete="new-password"
|
|
|
|
|
HelperText="@Text["SetupAdmin_PasswordMinimum"]" />
|
|
|
|
|
<MudTextField @bind-Value="_confirmPassword" Label="@Text["SetupAdmin_ConfirmPassword"]"
|
|
|
|
|
Variant="Variant.Outlined" InputType="InputType.Password" Class="mb-4"
|
|
|
|
|
Required="true" Immediate="true" Autocomplete="new-password" />
|
|
|
|
|
@if (!string.IsNullOrEmpty(_error))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_error</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
|
|
|
|
|
ButtonType="ButtonType.Submit" Disabled="@_loading" Class="auth-submit-btn">
|
|
|
|
|
@(_loading ? Text["SetupAdmin_Loading"] : Text["SetupAdmin_Submit"])
|
|
|
|
|
</MudButton>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
private string _displayName = "";
|
|
|
|
|
private string _email = "";
|
|
|
|
|
private string _password = "";
|
|
|
|
|
private string _confirmPassword = "";
|
|
|
|
|
private string _error = "";
|
|
|
|
|
private bool _checking = true;
|
|
|
|
|
private bool _unavailable;
|
|
|
|
|
private bool _loading;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!await Api.IsAdminSetupRequiredAsync())
|
|
|
|
|
{
|
|
|
|
|
Navigation.NavigateTo("/login", replace: true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
_unavailable = true;
|
|
|
|
|
}
|
|
|
|
|
finally { _checking = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task CreateAdminAsync()
|
|
|
|
|
{
|
|
|
|
|
if (_password != _confirmPassword)
|
|
|
|
|
{
|
|
|
|
|
_error = Text["SetupAdmin_PasswordMismatch"];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_loading = true;
|
|
|
|
|
_error = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.BootstrapAdminAsync(_email, _password, _displayName);
|
|
|
|
|
if (result is null)
|
|
|
|
|
{
|
|
|
|
|
_error = Text["SetupAdmin_Failed"];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await AuthStateProvider.NotifyLoginAsync(result);
|
|
|
|
|
var cookieOk = !string.IsNullOrEmpty(result.AccessToken) && await AuthHelper.SignInAsync(
|
2026-11-08 20:03:03 +01:00
|
|
|
JsRuntime, Logger, AuthHelper.CreateSignInPayload(result.AccessToken));
|
2026-10-27 22:19:52 +01:00
|
|
|
if (!cookieOk)
|
|
|
|
|
{
|
|
|
|
|
_error = Text["SetupAdmin_AutoLoginFailed"];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Navigation.NavigateTo("/dashboard", replace: true);
|
|
|
|
|
}
|
|
|
|
|
catch { _error = UiErrors.OperationFailed(); }
|
|
|
|
|
finally { _password = ""; _confirmPassword = ""; _loading = false; }
|
|
|
|
|
}
|
|
|
|
|
}
|