fix display current user +
redirect in caso di user nullo
This commit is contained in:
@@ -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<int>("MatrOpr");
|
||||
userName = answ.ToString();
|
||||
OperatoreDTO answ = new OperatoreDTO();
|
||||
answ = await sessionStorage.GetItemAsync<OperatoreDTO>("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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<int>("MatrOpr");
|
||||
OperatoreDTO answ = new OperatoreDTO();
|
||||
answ = await sessionStorage.GetItemAsync<OperatoreDTO>("MatrOpr");
|
||||
if (answ != null)
|
||||
{
|
||||
idOperatore = answ.MatrOpr;
|
||||
authKey = answ.hashAuthKey;
|
||||
}
|
||||
else
|
||||
{
|
||||
NavManager.NavigateTo("OperatoreLogin");
|
||||
}
|
||||
}
|
||||
protected async Task getAuth()
|
||||
{
|
||||
authKey = await sessionStorage.GetItemAsync<string>("AuthKey");
|
||||
}
|
||||
|
||||
[Inject]
|
||||
private NavigationManager NavManager { get; set; } = null!;
|
||||
protected string rawCode
|
||||
{
|
||||
get
|
||||
|
||||
Reference in New Issue
Block a user