Files
mapo-core/MP.INVE/Pages/Jumper.razor.cs
T
2022-11-28 11:03:27 +01:00

90 lines
3.0 KiB
C#

using Blazored.LocalStorage;
using Blazored.SessionStorage;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.WebUtilities;
using MP.Data.DatabaseModels;
using MP.Data.DTO;
using MP.INVE.Data;
namespace MP.INVE.Pages
{
public partial class Jumper
{
#region Protected Properties
protected string authKey { get; set; } = null!;
protected string idOPeratore { get; set; } = null!;
protected int inveSessionId { get; set; } = 0;
[Inject]
protected ILocalStorageService localStorage { get; set; } = null!;
[Inject]
protected MiDataService MIService { get; set; } = null!;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
[Inject]
protected ISessionStorageService sessionStorage { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("MatrOpr", out var _matrOpr) && QueryHelpers.ParseQuery(uri.Query).TryGetValue("UserAuthKey", out var _authKey) && QueryHelpers.ParseQuery(uri.Query).TryGetValue("idSessione", out var _inveSessionId))
{
idOPeratore = _matrOpr;
authKey = _authKey;
inveSessionId = int.Parse(_inveSessionId);
}
string pw = MIService.DeriptData(authKey);
logged = MIService.loginOperatore(int.Parse(idOPeratore), pw);
if (logged)
{
operatore = MIService.ElencoOperatori();
if (operatore != null)
{
AnagOperatoriModel? currOpr = operatore.Where(x => (x.MatrOpr == int.Parse(idOPeratore)) && (x.authKey == pw)).SingleOrDefault();
if (currOpr != null)
{
string hash = MIService.EncriptData(currOpr.authKey);
OperatoreDTO sessionOpr = new OperatoreDTO
{
MatrOpr = currOpr.MatrOpr,
Nome = currOpr.Nome,
Cognome = currOpr.Cognome,
hashAuthKey = hash
};
await localStorage.SetItemAsync("MatrOpr", currOpr);
await sessionStorage.SetItemAsync("idSessione", inveSessionId);
}
NavManager.NavigateTo($"Acquisizione?idSessione={inveSessionId}");
}
}
}
#endregion Protected Methods
#region Private Fields
private List<AnagOperatoriModel> operatore = new List<AnagOperatoriModel>();
#endregion Private Fields
#region Private Properties
private bool logged { get; set; } = false;
#endregion Private Properties
}
}