@page "/login" @using Microsoft.Extensions.Logging @using SteUp.Shared.Core.BarcodeReader.Contracts @using SteUp.Shared.Core.Interface.System @using SteUp.Shared.Core.Services @inject IUserAccountService UserAccountService @inject AppAuthenticationStateProvider AuthenticationStateProvider @inject IGenericSystemService GenericSystemService @inject IBarcodeManager BarcodeManager @inject ILogger Logger @* Accesso (STILE_UI §7): stessa struttura dell'app, registro diverso. Niente accento cromatico — l'attenzione sta sul marchio; il corallo torna dentro l'app, dove significa "qui si agisce". *@
@* Un solo pannello con tre righe divise da una linea, come le liste del resto dell'app. Prima ogni campo era un riquadro dentro il riquadro, con l'etichetta che saltava sopra il testo al primo tocco: un gesto da modulo web, non da applicazione. Qui l'etichetta sta ferma sopra il campo e non si muove mai. *@
@if (_attemptFailed) { @* Stesso riquadro di avviso usato dentro l'app: l'errore di accesso non e' un caso speciale che merita un suo stile. *@ }
@code { private SignIn UserData { get; } = new(); private string ErrorMessage { get; set; } = ""; private bool _attemptFailed; private bool _busy; private bool _isShow; private bool CanSubmit => !string.IsNullOrWhiteSpace(UserData.Username) && !string.IsNullOrWhiteSpace(UserData.Password) && !string.IsNullOrWhiteSpace(UserData.CodHash); private void ShowPassword() => _isShow = !_isShow; protected override void OnInitialized() { UserData.CodHash = LocalStorage.GetString("codHash"); StateHasChanged(); } private async Task SignInUser() { if (_busy || !CanSubmit) return; _attemptFailed = false; _busy = true; StateHasChanged(); try { SteupDataService.RegisterAppVersion(); await UserAccountService.Login(UserData.Username!, UserData.Password!, UserData.CodHash!); AuthenticationStateProvider.NotifyAuthenticationState(); //Chiamato per forzare il refresh await SteupDataService.Init(); BarcodeManager.Init(); LocalStorage.SetString("codHash", UserData.CodHash!); NavigationManager.NavigateTo("/"); } catch (Exception e) { ErrorMessage = e.Message; Logger.LogError(e, ErrorMessage); _attemptFailed = true; } finally { _busy = false; StateHasChanged(); } } public class SignIn { public string? Username { get; set; } public string? Password { get; set; } public string? CodHash { get; set; } } }