@page "/login" @using Microsoft.Extensions.Logging @using SteUp.Shared.Components.Layout.Spinner @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 @if (Spinner) { } else { } @code { private SignIn UserData { get; } = new(); private bool Spinner { get; set; } private string ErrorMessage { get; set; } = ""; private bool _attemptFailed; private bool _isShow; private InputType _passwordInput = InputType.Password; private string _passwordInputIcon = Icons.Material.Rounded.VisibilityOff; private void ShowPassword() { if (_isShow) { _isShow = false; _passwordInputIcon = Icons.Material.Rounded.VisibilityOff; _passwordInput = InputType.Password; } else { _isShow = true; _passwordInputIcon = Icons.Material.Rounded.Visibility; _passwordInput = InputType.Text; } } protected override void OnInitialized() { UserData.CodHash = LocalStorage.GetString("codHash"); StateHasChanged(); } private async Task SignInUser() { _attemptFailed = false; if (!string.IsNullOrEmpty(UserData.Username) && !string.IsNullOrEmpty(UserData.Password) && !string.IsNullOrEmpty(UserData.CodHash)) { Spinner = 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("/"); StateHasChanged(); } catch (Exception e) { ErrorMessage = e.Message; Logger.LogError(e, ErrorMessage); Console.WriteLine(e.Message); Spinner = false; StateHasChanged(); _attemptFailed = true; Console.WriteLine(e); } } } public class SignIn { public string? Username { get; set; } public string? Password { get; set; } public string? CodHash { get; set; } } }