Files
mapo-core/MP.INVE/Pages/Jumper.razor.cs
T
2022-11-23 10:30:32 +01:00

84 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using MP.INVE;
using MP.INVE.Shared;
using MP.INVE.Components;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.WebUtilities;
using MP.INVE.Data;
using MP.Data.DatabaseModels;
using MP.Data.DTO;
using Microsoft.IdentityModel.Tokens;
using Blazored.SessionStorage;
namespace MP.INVE.Pages
{
public partial class Jumper
{
[Inject]
protected ILocalStorageService localStorage { get; set; } = null!;
[Inject]
protected ISessionStorageService sessionStorage { get; set; } = null!;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
[Inject]
protected MiDataService MIService { get; set; } = null!;
private bool logged { get; set; } = false;
private List<AnagOperatoriModel> operatore = new List<AnagOperatoriModel>();
protected string idOPeratore { get; set; } = null!;
protected string authKey { get; set; } = null!;
protected int inveSessionId { get; set; } = 0;
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}");
}
}
}
}
}