From 2a8f82e35d7c8b8b4544d44a23a73fbe5a4a0c4a Mon Sep 17 00:00:00 2001 From: GiuseppeS Date: Tue, 23 Sep 2025 13:36:21 +0200 Subject: [PATCH] Implementata autenticazione per tutte le pagine della dashboard --- .../Layout/MainLayout.razor | 37 ++-- .../Layout/NavMenu.razor | 39 ++-- .../Pages/Counter.razor | 2 + .../Pages/Dashboard.razor | 166 ++++++++++++++++++ .../Pages/Home.razor | 67 ++----- .../Pages/Weather.razor | 3 +- .../IntegryControlPanel.Client/Routes.razor | 19 +- .../IntegryControlPanel.Client/_Imports.razor | 2 + ...omponentsEndpointRouteBuilderExtensions.cs | 10 ++ 9 files changed, 258 insertions(+), 87 deletions(-) create mode 100644 IntegryControlPanel/IntegryControlPanel.Client/Pages/Dashboard.razor diff --git a/IntegryControlPanel/IntegryControlPanel.Client/Layout/MainLayout.razor b/IntegryControlPanel/IntegryControlPanel.Client/Layout/MainLayout.razor index 96653ec..3e9bc61 100644 --- a/IntegryControlPanel/IntegryControlPanel.Client/Layout/MainLayout.razor +++ b/IntegryControlPanel/IntegryControlPanel.Client/Layout/MainLayout.razor @@ -4,21 +4,30 @@ - - - - Application - - - - - - - - @Body - - + + + + + Integry Control Panel + + + + + Benvenuto, @context.User.Identity?.Name + + + + + + + + + + @Body + + +
An unhandled error has occurred. diff --git a/IntegryControlPanel/IntegryControlPanel.Client/Layout/NavMenu.razor b/IntegryControlPanel/IntegryControlPanel.Client/Layout/NavMenu.razor index 800ed07..1137a67 100644 --- a/IntegryControlPanel/IntegryControlPanel.Client/Layout/NavMenu.razor +++ b/IntegryControlPanel/IntegryControlPanel.Client/Layout/NavMenu.razor @@ -3,26 +3,33 @@ @inject NavigationManager NavigationManager - Home - Counter - - Weather - - Auth Required - @context.User.Identity?.Name -
- - - - + Dashboard + + + Server + Client + Servizi + + + Counter + Weather + Auth Required + + + + Profilo (@context.User.Identity?.Name) + + Logout + +
- Register - Login + Login + Register
diff --git a/IntegryControlPanel/IntegryControlPanel.Client/Pages/Counter.razor b/IntegryControlPanel/IntegryControlPanel.Client/Pages/Counter.razor index 83d09a7..a6c9344 100644 --- a/IntegryControlPanel/IntegryControlPanel.Client/Pages/Counter.razor +++ b/IntegryControlPanel/IntegryControlPanel.Client/Pages/Counter.razor @@ -1,5 +1,7 @@ @page "/counter" +@using Microsoft.AspNetCore.Authorization +@attribute [Authorize] Counter diff --git a/IntegryControlPanel/IntegryControlPanel.Client/Pages/Dashboard.razor b/IntegryControlPanel/IntegryControlPanel.Client/Pages/Dashboard.razor new file mode 100644 index 0000000..5c3cc8e --- /dev/null +++ b/IntegryControlPanel/IntegryControlPanel.Client/Pages/Dashboard.razor @@ -0,0 +1,166 @@ +@page "/dashboard" + +@using Microsoft.AspNetCore.Authorization +@attribute [Authorize] + +Dashboard - Integry Control Panel + + + Dashboard + + + + + Benvenuto, @context.User.Identity?.Name! + + + + + + + + + +
+
+ Server Status + Online +
+ +
+
+
+
+ + + + + +
+
+ Client Attivi + -- +
+ +
+
+
+
+ + + + + +
+
+ Servizi + -- +
+ +
+
+
+
+ + + + + + + Azioni Rapide + + + + + + + Gestisci Server + + + + + Gestisci Client + + + + + Configurazioni + + + + + Report + + + + + + + + + + + + + Attività Recenti + + + + + Nessuna attività recente da visualizzare + + + + + + + + + + + Informazioni Sistema + + + + +
+ + Versione: 1.0.0 + +
+
+ + Database: Connesso + +
+
+ + LDAP: Connesso + +
+
+
+
+
+
+
+ +@code { + +} \ No newline at end of file diff --git a/IntegryControlPanel/IntegryControlPanel.Client/Pages/Home.razor b/IntegryControlPanel/IntegryControlPanel.Client/Pages/Home.razor index 6aaa2a4..caa7b11 100644 --- a/IntegryControlPanel/IntegryControlPanel.Client/Pages/Home.razor +++ b/IntegryControlPanel/IntegryControlPanel.Client/Pages/Home.razor @@ -1,59 +1,16 @@ @page "/" +@using Microsoft.AspNetCore.Authorization +@attribute [Authorize] + +@inject NavigationManager NavigationManager + Home -Hello, world! -Welcome to your new app, powered by MudBlazor and the .NET 9 Template! - - - You can find documentation and examples on our website here: - - www.mudblazor.com - - - -
-Interactivity in this Template -
- - When you opt for the "Global" Interactivity Location,
- the render modes are defined in App.razor and consequently apply to all child components.
- In this case, providers are globally set in the MainLayout.
-
- On the other hand, if you choose the "Per page/component" Interactivity Location,
- it is necessary to include the
-
- <MudPopoverProvider />
- <MudDialogProvider />
- <MudSnackbarProvider />
-
- components on every interactive page.
-
- If a render mode is not specified for a page, it defaults to Server-Side Rendering (SSR),
- similar to this page. While MudBlazor allows pages to be rendered in SSR,
- please note that interactive features, such as buttons and dropdown menus, will not be functional. -
- -
-What's New in Blazor with the Release of .NET 9 -
- -Prerendering - - If you're exploring the features of .NET 9 Blazor,
you might be pleasantly surprised to learn that each page is prerendered on the server,
regardless of the selected render mode.

- This means that you'll need to inject all necessary services on the server,
even when opting for the wasm (WebAssembly) render mode.

- This prerendering functionality is crucial to ensuring that WebAssembly mode feels fast and responsive,
especially when it comes to initial page load times.

- For more information on how to detect prerendering and leverage the RenderContext, you can refer to the following link: - - More details - -
- -
-InteractiveAuto - - A discussion on how to achieve this can be found here: - - More details - - +@code { + protected override void OnInitialized() + { + // Redirect authenticated users to dashboard + NavigationManager.NavigateTo("/dashboard", replace: true); + } +} diff --git a/IntegryControlPanel/IntegryControlPanel.Client/Pages/Weather.razor b/IntegryControlPanel/IntegryControlPanel.Client/Pages/Weather.razor index 3ffd7d8..35d4a80 100644 --- a/IntegryControlPanel/IntegryControlPanel.Client/Pages/Weather.razor +++ b/IntegryControlPanel/IntegryControlPanel.Client/Pages/Weather.razor @@ -1,6 +1,7 @@ @page "/weather" - +@using Microsoft.AspNetCore.Authorization +@attribute [Authorize] Weather diff --git a/IntegryControlPanel/IntegryControlPanel.Client/Routes.razor b/IntegryControlPanel/IntegryControlPanel.Client/Routes.razor index 16f0026..6bb34e8 100644 --- a/IntegryControlPanel/IntegryControlPanel.Client/Routes.razor +++ b/IntegryControlPanel/IntegryControlPanel.Client/Routes.razor @@ -2,9 +2,26 @@ - + @if (context.User.Identity?.IsAuthenticated != true) + { + + } + else + { +
+

Non hai i permessi necessari per accedere a questa risorsa.

+
+ }
+ + Not found + +
+

Pagina non trovata!

+
+
+
diff --git a/IntegryControlPanel/IntegryControlPanel.Client/_Imports.razor b/IntegryControlPanel/IntegryControlPanel.Client/_Imports.razor index bf18238..441826a 100644 --- a/IntegryControlPanel/IntegryControlPanel.Client/_Imports.razor +++ b/IntegryControlPanel/IntegryControlPanel.Client/_Imports.razor @@ -1,6 +1,7 @@ @using System.Net.Http @using System.Net.Http.Json @using Microsoft.AspNetCore.Components.Authorization +@using Microsoft.AspNetCore.Authorization @using MudBlazor.StaticInput @using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Routing @@ -10,3 +11,4 @@ @using Microsoft.JSInterop @using MudBlazor @using MudBlazor.Services +@using IntegryControlPanel.Client diff --git a/IntegryControlPanel/IntegryControlPanel/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs b/IntegryControlPanel/IntegryControlPanel/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs index f183858..b9c0ddf 100644 --- a/IntegryControlPanel/IntegryControlPanel/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs +++ b/IntegryControlPanel/IntegryControlPanel/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs @@ -49,6 +49,16 @@ namespace Microsoft.AspNetCore.Routing return TypedResults.LocalRedirect($"~/{returnUrl}"); }); + // Add GET endpoint for logout to handle navigation from WebAssembly client + accountGroup.MapGet("/Logout", async ( + ClaimsPrincipal user, + [FromServices] SignInManager signInManager, + [FromQuery] string? returnUrl) => + { + await signInManager.SignOutAsync(); + return TypedResults.LocalRedirect($"~/{returnUrl ?? "Account/Login"}"); + }); + var manageGroup = accountGroup.MapGroup("/Manage").RequireAuthorization(); manageGroup.MapPost("/LinkExternalLogin", async (