22c0a15b8e
BREAKING CHANGE: Tutte le pagine ora richiedono autenticazione Nuove funzionalità: - Sistema di login con password hardcoded (admin123) - Form di login full-screen con gradiente viola - Protezione automatica di tutte le route - Pulsante logout visibile in tutte le pagine - Gestione thread-safe eventi autenticazione con InvokeAsync() Componenti: - AuthenticationService: servizio Singleton per gestione stato - Login.razor: pagina login con validazione e messaggi errore - App.razor: routing condizionale basato su autenticazione - MainLayout.razor: pulsante logout integrato Fix tecnici: - Risolto errore "Dispatcher not associated" usando InvokeAsync() - Implementato pattern corretto per eventi cross-thread in Blazor Server - Aggiunto Dispose per prevenire memory leak
57 lines
1.6 KiB
Plaintext
57 lines
1.6 KiB
Plaintext
@using Data_Coupler.Services
|
|
@using Data_Coupler.Pages
|
|
@inject IAuthenticationService AuthService
|
|
@implements IDisposable
|
|
|
|
@if (!AuthService.IsAuthenticated)
|
|
{
|
|
<Login />
|
|
}
|
|
else
|
|
{
|
|
<Router AppAssembly="@typeof(App).Assembly">
|
|
<Found Context="routeData">
|
|
@{
|
|
// Se l'utente prova ad accedere alla pagina di login mentre è autenticato, reindirizza alla home
|
|
if (routeData.PageType == typeof(Data_Coupler.Pages.Login))
|
|
{
|
|
<RouteView RouteData="@CreateHomeRouteData()" DefaultLayout="@typeof(MainLayout)" />
|
|
}
|
|
else
|
|
{
|
|
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
|
}
|
|
}
|
|
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
|
</Found>
|
|
<NotFound>
|
|
<PageTitle>Not found</PageTitle>
|
|
<LayoutView Layout="@typeof(MainLayout)">
|
|
<p role="alert">Sorry, there's nothing at this address.</p>
|
|
</LayoutView>
|
|
</NotFound>
|
|
</Router>
|
|
}
|
|
|
|
@code {
|
|
protected override void OnInitialized()
|
|
{
|
|
AuthService.OnAuthenticationStateChanged += OnAuthenticationStateChanged;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
AuthService.OnAuthenticationStateChanged -= OnAuthenticationStateChanged;
|
|
}
|
|
|
|
private void OnAuthenticationStateChanged()
|
|
{
|
|
InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private RouteData CreateHomeRouteData()
|
|
{
|
|
return new RouteData(typeof(Data_Coupler.Pages.DataCoupler), new Dictionary<string, object?>());
|
|
}
|
|
}
|