feat(auth): Implementazione completa sistema autenticazione
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
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace Data_Coupler.Services
|
||||
{
|
||||
public interface IAuthenticationService
|
||||
{
|
||||
bool IsAuthenticated { get; }
|
||||
event Action? OnAuthenticationStateChanged;
|
||||
bool Login(string password);
|
||||
void Logout();
|
||||
}
|
||||
|
||||
public class AuthenticationService : IAuthenticationService
|
||||
{
|
||||
// Password hardcoded - CAMBIARE IN PRODUZIONE
|
||||
private const string HARDCODED_PASSWORD = "admin123";
|
||||
|
||||
private bool _isAuthenticated = false;
|
||||
|
||||
public bool IsAuthenticated => _isAuthenticated;
|
||||
|
||||
public event Action? OnAuthenticationStateChanged;
|
||||
|
||||
public bool Login(string password)
|
||||
{
|
||||
if (password == HARDCODED_PASSWORD)
|
||||
{
|
||||
_isAuthenticated = true;
|
||||
OnAuthenticationStateChanged?.Invoke();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
_isAuthenticated = false;
|
||||
OnAuthenticationStateChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user