Files
Data-Coupler/Data_Coupler/Services/AuthenticationService.cs
Alessio Dal Santo 22c0a15b8e 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
2025-10-08 17:58:46 +02:00

42 lines
1.0 KiB
C#

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();
}
}
}