diff --git a/MP.INVE/Components/CmpTop.razor.cs b/MP.INVE/Components/CmpTop.razor.cs index 8c704ed0..58555dde 100644 --- a/MP.INVE/Components/CmpTop.razor.cs +++ b/MP.INVE/Components/CmpTop.razor.cs @@ -2,6 +2,7 @@ using Blazored.SessionStorage; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.JSInterop; +using MP.Data.DTO; using MP.INVE.Data; namespace MP.INVE.Components @@ -45,9 +46,16 @@ namespace MP.INVE.Components } protected async Task getId() { - int answ = 0; - answ = await sessionStorage.GetItemAsync("MatrOpr"); - userName = answ.ToString(); + OperatoreDTO answ = new OperatoreDTO(); + answ = await sessionStorage.GetItemAsync("MatrOpr"); + if (answ != null) + { + userName = $"{answ.Cognome} {answ.Cognome} ({answ.MatrOpr})"; + } + else + { + userName = "0"; + } } #endregion Protected Methods @@ -70,7 +78,7 @@ namespace MP.INVE.Components #region Private Methods private async Task forceReload() - { + { await getId(); } diff --git a/MP.INVE/Pages/OperatoreLogin.razor.cs b/MP.INVE/Pages/OperatoreLogin.razor.cs index 73a3f8de..4555be7e 100644 --- a/MP.INVE/Pages/OperatoreLogin.razor.cs +++ b/MP.INVE/Pages/OperatoreLogin.razor.cs @@ -17,6 +17,7 @@ using MP.INVE.Shared; using MP.INVE.Components; using MP.Data.DatabaseModels; using Blazored.SessionStorage; +using MP.Data.DTO; namespace MP.INVE.Pages { @@ -45,16 +46,30 @@ namespace MP.INVE.Pages { elencoOperatori = MIDataservice.ElencoOperatori(idOperatore, authKey); - if (elencoOperatori.Count == 1) - { - NavManager.NavigateTo("/Starter", true); - sessionStorage.SetItemAsync("MatrOpr", idOperatore); - sessionStorage.SetItemAsync("AuthKey", authKey); - } - else - { + AnagOperatoriModel? currOpr = elencoOperatori.SingleOrDefault(); - } + if (currOpr != null) + { + OperatoreDTO sessionOpr = new OperatoreDTO + { + MatrOpr = currOpr.MatrOpr, + Nome = currOpr.Nome, + Cognome = currOpr.Cognome, + hashAuthKey = currOpr.authKey + }; + + + if (elencoOperatori.Count == 1) + { + NavManager.NavigateTo("/Starter", true); + sessionStorage.SetItemAsync("MatrOpr", sessionOpr); + //sessionStorage.SetItemAsync("AuthKey", authKey); + } + else + { + + } + } } } } \ No newline at end of file diff --git a/MP.INVE/Pages/Starter.razor.cs b/MP.INVE/Pages/Starter.razor.cs index aa197872..2389327e 100644 --- a/MP.INVE/Pages/Starter.razor.cs +++ b/MP.INVE/Pages/Starter.razor.cs @@ -15,13 +15,14 @@ using MP.INVE; using MP.INVE.Shared; using MP.INVE.Components; using Blazored.SessionStorage; +using MP.Data.DTO; namespace MP.INVE.Pages { public partial class Starter { [Inject] - private IConfiguration Configuration { get; set; } = null !; + private IConfiguration Configuration { get; set; } = null!; [Inject] private ISessionStorageService sessionStorage { get; set; } = null!; @@ -32,7 +33,6 @@ namespace MP.INVE.Pages protected override async Task OnInitializedAsync() { await getId(); - await getAuth(); } protected override async Task OnAfterRenderAsync(bool firstRender) @@ -48,13 +48,20 @@ namespace MP.INVE.Pages protected async Task getId() { - idOperatore = await sessionStorage.GetItemAsync("MatrOpr"); + OperatoreDTO answ = new OperatoreDTO(); + answ = await sessionStorage.GetItemAsync("MatrOpr"); + if (answ != null) + { + idOperatore = answ.MatrOpr; + authKey = answ.hashAuthKey; + } + else + { + NavManager.NavigateTo("OperatoreLogin"); + } } - protected async Task getAuth() - { - authKey = await sessionStorage.GetItemAsync("AuthKey"); - } - + [Inject] + private NavigationManager NavManager { get; set; } = null!; protected string rawCode { get