@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". *@
@if (_attemptFailed) { }
@code { private SignIn UserData { get; } = new(); private string ErrorMessage { get; set; } = ""; private bool _attemptFailed; private bool _busy; private bool _isShow; private InputType _passwordInput = InputType.Password; private string _passwordInputIcon = Icons.Material.Rounded.VisibilityOff; private bool CanSubmit => !string.IsNullOrWhiteSpace(UserData.Username) && !string.IsNullOrWhiteSpace(UserData.Password) && !string.IsNullOrWhiteSpace(UserData.CodHash); private void ShowPassword() { _isShow = !_isShow; _passwordInputIcon = _isShow ? Icons.Material.Rounded.Visibility : Icons.Material.Rounded.VisibilityOff; _passwordInput = _isShow ? InputType.Text : InputType.Password; } 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; } } }