Changed auth success ui. Switched to new interface service. Upgraded mooncore versions

This commit is contained in:
Masu Baumgartner
2024-10-27 20:49:06 +01:00
parent 7239182e83
commit c15f18108d
9 changed files with 73 additions and 60 deletions

View File

@@ -8,10 +8,11 @@
@inherits LayoutComponentBase
@inject ImplementationService ImplementationService
@inject IdentityService IdentityService
@inject IServiceProvider ServiceProvider
@inject ILogger<MainLayout> Logger
@inject IAppLoader[] AppLoaders
@inject IAppScreen[] AppScreens
@if (IsLoading)
{
@@ -98,8 +99,7 @@ else
private async Task RunLoaders()
{
var appLoaders = ImplementationService
.Get<IAppLoader>()
var appLoaders = AppLoaders
.OrderBy(x => x.Priority);
foreach (var loader in appLoaders) //TODO: Measure performance of every loader?
@@ -120,8 +120,7 @@ else
{
CurrentScreen = null;
var appScreens = ImplementationService
.Get<IAppScreen>()
var appScreens = AppScreens
.OrderBy(x => x.Priority);
foreach (var screen in appScreens)

View File

@@ -6,7 +6,7 @@
@inject NavigationManager Navigation
@inject IdentityService IdentityService
@inject ImplementationService ImplementationService
@inject ISidebarItemProvider[] SidebarItemProviders
@{
var url = new Uri(Navigation.Uri);
@@ -168,7 +168,7 @@
protected override void OnInitialized()
{
Items = ImplementationService.Get<ISidebarItemProvider>()
Items = SidebarItemProviders
.SelectMany(x => x.Get())
.Where(x => x.Permission == null || (x.Permission != null && IdentityService.HasPermission(x.Permission)))
.GroupBy(x => x.Group ?? "")

View File

@@ -12,6 +12,8 @@
@inject HttpClient HttpClient
@inject LocalStorageService LocalStorageService
@inject ILogger<AuthenticationScreen> Logger
@if (Code == null)
{
<div class="h-full w-full min-h-[100dvh] flex items-center justify-center px-5 md:px-0">
@@ -53,14 +55,10 @@ else
@if (IsHandlingDone)
{
<div class="sm:mx-auto sm:w-full sm:max-w-sm mb-5">
<img class="mx-auto h-16 w-auto" src="/logolong.webp" alt="Moonlight">
<h2 class="mt-6 text-center text-2xl font-bold leading-9 tracking-tight text-gray-100">Login to access your account</h2>
</div>
<div class="flex justify-center">
<p class="mt-3 text-center text-md text-gray-400">
<img class="mx-auto w-auto h-32" src="/svg/completed.svg" alt="Completed illustration">
<h2 class="mt-6 text-center text-2xl font-semibold leading-9 tracking-tight text-gray-100">
Login successful. You can close this window now
</p>
</h2>
</div>
}
else
@@ -91,25 +89,35 @@ else
if (Code == null)
return;
var authHandleData = await HttpApiClient.PostJson<OAuth2HandleResponse>("api/auth", new OAuth2HandleRequest()
{
Code = Code
});
await LocalStorageService.SetString("AccessToken", authHandleData.AccessToken);
await LocalStorageService.SetString("RefreshToken", authHandleData.RefreshToken);
await LocalStorageService.Set("ExpiresAt", authHandleData.ExpiresAt);
try
{
await WindowService.Close();
}
finally
{
var authHandleData = await HttpApiClient.PostJson<OAuth2HandleResponse>("api/auth", new OAuth2HandleRequest()
{
Code = Code
});
// Save the auth handle data
await LocalStorageService.SetString("AccessToken", authHandleData.AccessToken);
await LocalStorageService.SetString("RefreshToken", authHandleData.RefreshToken);
await LocalStorageService.Set("ExpiresAt", authHandleData.ExpiresAt);
// Update UI
IsHandlingDone = true;
await InvokeAsync(StateHasChanged);
await Task.Delay(TimeSpan.FromSeconds(2));
Navigation.NavigateTo("/", true);
try
{
await WindowService.Close();
}
finally
{
Navigation.NavigateTo("/", true);
}
}
catch (Exception e)
{
Logger.LogError("An unhandled error occured while handling oauth2 code: {e}", e);
}
}