From 630ff7462c6078ee2160f0ef60fcc1c60b17937c Mon Sep 17 00:00:00 2001 From: "zaccaria.majid" Date: Wed, 16 Nov 2022 15:49:37 +0100 Subject: [PATCH] fix gestione sessione con local storage --- MP.INVE/Components/CmpTop.razor.cs | 14 +++-- MP.INVE/MP.INVE.csproj | 3 +- MP.INVE/Pages/OperatoreLogin.razor | 76 ++++++++++++++++++--------- MP.INVE/Pages/OperatoreLogin.razor.cs | 10 ++-- MP.INVE/Pages/Starter.razor.cs | 20 +++++-- MP.INVE/Program.cs | 4 ++ MP.INVE/Resources/ChangeLog.html | 2 +- MP.INVE/Resources/VersNum.txt | 2 +- MP.INVE/Resources/manifest.xml | 2 +- 9 files changed, 92 insertions(+), 41 deletions(-) diff --git a/MP.INVE/Components/CmpTop.razor.cs b/MP.INVE/Components/CmpTop.razor.cs index 93fa76ce..3a58fbc0 100644 --- a/MP.INVE/Components/CmpTop.razor.cs +++ b/MP.INVE/Components/CmpTop.razor.cs @@ -1,4 +1,5 @@ using Blazored.SessionStorage; +using Blazored.LocalStorage; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using MP.Data.DTO; @@ -19,7 +20,7 @@ namespace MP.INVE.Components public async Task LogOut() { - await sessionStorage.ClearAsync(); + await localStorage.ClearAsync(); // rimando a pagina login NavManager.NavigateTo("OperatoreLogin", true); } @@ -38,10 +39,14 @@ namespace MP.INVE.Components protected async Task getId() { OperatoreDTO answ = new OperatoreDTO(); - answ = await sessionStorage.GetItemAsync("MatrOpr"); + answ = await localStorage.GetItemAsync("MatrOpr"); if (answ != null) { - userName = $"{answ.Cognome} {answ.Cognome} ({answ.MatrOpr})"; + userName = $"{answ.Cognome} {answ.Nome} ({answ.MatrOpr})"; + if (NavManager.Uri.Contains("OperatoreLogin")) + { + NavManager.NavigateTo("Starter", true); + } } else { @@ -70,9 +75,10 @@ namespace MP.INVE.Components [Inject] private NavigationManager NavManager { get; set; } = null!; - [Inject] private ISessionStorageService sessionStorage { get; set; } = null!; + [Inject] + private ILocalStorageService localStorage { get; set; } = null!; #endregion Private Properties } diff --git a/MP.INVE/MP.INVE.csproj b/MP.INVE/MP.INVE.csproj index 9c297f5e..3689cff4 100644 --- a/MP.INVE/MP.INVE.csproj +++ b/MP.INVE/MP.INVE.csproj @@ -5,7 +5,7 @@ enable enable MP.INVE - 6.16.2211.1612 + 6.16.2211.1615 @@ -27,6 +27,7 @@ + diff --git a/MP.INVE/Pages/OperatoreLogin.razor b/MP.INVE/Pages/OperatoreLogin.razor index 2444299a..9d0e9867 100644 --- a/MP.INVE/Pages/OperatoreLogin.razor +++ b/MP.INVE/Pages/OperatoreLogin.razor @@ -1,34 +1,60 @@ @page "/OperatoreLogin" -
-
-

OperatoreLogin

-
-
- -
+
+
+
-
- -
-
- - +
+
+
+

login Operatore

+
+
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+ +
+
+ +
+
-
- -
+ + +
+
- diff --git a/MP.INVE/Pages/OperatoreLogin.razor.cs b/MP.INVE/Pages/OperatoreLogin.razor.cs index 4555be7e..e0570b65 100644 --- a/MP.INVE/Pages/OperatoreLogin.razor.cs +++ b/MP.INVE/Pages/OperatoreLogin.razor.cs @@ -18,6 +18,7 @@ using MP.INVE.Components; using MP.Data.DatabaseModels; using Blazored.SessionStorage; using MP.Data.DTO; +using Blazored.LocalStorage; namespace MP.INVE.Pages { @@ -29,6 +30,8 @@ namespace MP.INVE.Pages private NavigationManager NavManager { get; set; } = null!; [Inject] private ISessionStorageService sessionStorage { get; set; } = null!; + [Inject] + private ILocalStorageService localStorage { get; set; } = null!; private int idOperatore { get; set; } = 0; private string authKey { get; set; } = ""; @@ -48,22 +51,23 @@ namespace MP.INVE.Pages AnagOperatoriModel? currOpr = elencoOperatori.SingleOrDefault(); + if (currOpr != null) { + string hash = MIDataservice.EncriptData(currOpr.authKey); OperatoreDTO sessionOpr = new OperatoreDTO { MatrOpr = currOpr.MatrOpr, Nome = currOpr.Nome, Cognome = currOpr.Cognome, - hashAuthKey = currOpr.authKey + hashAuthKey = hash }; if (elencoOperatori.Count == 1) { NavManager.NavigateTo("/Starter", true); - sessionStorage.SetItemAsync("MatrOpr", sessionOpr); - //sessionStorage.SetItemAsync("AuthKey", authKey); + localStorage.SetItemAsync("MatrOpr", sessionOpr); } else { diff --git a/MP.INVE/Pages/Starter.razor.cs b/MP.INVE/Pages/Starter.razor.cs index 2389327e..fcb59bf7 100644 --- a/MP.INVE/Pages/Starter.razor.cs +++ b/MP.INVE/Pages/Starter.razor.cs @@ -16,6 +16,8 @@ using MP.INVE.Shared; using MP.INVE.Components; using Blazored.SessionStorage; using MP.Data.DTO; +using MP.INVE.Data; +using Blazored.LocalStorage; namespace MP.INVE.Pages { @@ -26,6 +28,11 @@ namespace MP.INVE.Pages [Inject] private ISessionStorageService sessionStorage { get; set; } = null!; + [Inject] + private ILocalStorageService localStorage { get; set; } = null!; + + [Inject] + private MiDataService MIDataservice { get; set; } = null!; private int idOperatore { get; set; } = 0; private string authKey { get; set; } = ""; @@ -48,12 +55,15 @@ namespace MP.INVE.Pages protected async Task getId() { - OperatoreDTO answ = new OperatoreDTO(); - answ = await sessionStorage.GetItemAsync("MatrOpr"); - if (answ != null) + OperatoreDTO sess = new OperatoreDTO(); + OperatoreDTO local = new OperatoreDTO(); + sess = await sessionStorage.GetItemAsync("MatrOpr"); + local = await localStorage.GetItemAsync("MatrOpr"); + if ((local != null)) { - idOperatore = answ.MatrOpr; - authKey = answ.hashAuthKey; + string auth = local.hashAuthKey; + idOperatore = local.MatrOpr; + authKey = auth; } else { diff --git a/MP.INVE/Program.cs b/MP.INVE/Program.cs index 6efe71ad..7fab8411 100644 --- a/MP.INVE/Program.cs +++ b/MP.INVE/Program.cs @@ -1,3 +1,4 @@ +using Blazored.LocalStorage; using Blazored.SessionStorage; using Microsoft.AspNetCore.Authentication.Negotiate; using Microsoft.AspNetCore.Components; @@ -41,7 +42,10 @@ builder.Services.AddSingleton(redisMultiplexer); builder.Services.AddSingleton(); builder.Services.AddScoped(); // aggiungere servizio da usare come DI x gestione session, aggiungere anche local storage + builder.Services.AddBlazoredSessionStorage(); +builder.Services.AddBlazoredLocalStorage(); + builder.Services.AddHttpClient(); builder.Services.AddSingleton(); diff --git a/MP.INVE/Resources/ChangeLog.html b/MP.INVE/Resources/ChangeLog.html index 31e795a4..08233761 100644 --- a/MP.INVE/Resources/ChangeLog.html +++ b/MP.INVE/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOINVE -

Versione: 6.16.2211.1612

+

Versione: 6.16.2211.1615


Note di rilascio:
  • diff --git a/MP.INVE/Resources/VersNum.txt b/MP.INVE/Resources/VersNum.txt index fc3f78cb..e237fd3e 100644 --- a/MP.INVE/Resources/VersNum.txt +++ b/MP.INVE/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2211.1612 +6.16.2211.1615 diff --git a/MP.INVE/Resources/manifest.xml b/MP.INVE/Resources/manifest.xml index 61b65b2c..09e085a6 100644 --- a/MP.INVE/Resources/manifest.xml +++ b/MP.INVE/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2211.1612 + 6.16.2211.1615 https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/MP.INVE.zip https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/ChangeLog.html false