93 lines
3.0 KiB
C#
93 lines
3.0 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.Data;
|
|
using MP.INVE.Shared;
|
|
using MP.INVE.Components;
|
|
using MP.Data.DatabaseModels;
|
|
using Blazored.SessionStorage;
|
|
using MP.Data.DTO;
|
|
using Blazored.LocalStorage;
|
|
|
|
namespace MP.INVE.Pages
|
|
{
|
|
public partial class OperatoreLogin
|
|
{
|
|
[Inject]
|
|
private MiDataService MIDataservice { get; set; } = null!;
|
|
[Inject]
|
|
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 => _authKey;
|
|
set {
|
|
if (_authKey != value)
|
|
{
|
|
_authKey = value;
|
|
login();
|
|
}
|
|
}
|
|
}
|
|
|
|
private string _authKey { get; set; } = "";
|
|
private bool logged { get; set; } = false;
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private List<AnagOperatoriModel>? elencoOperatori;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
isLoading = true;
|
|
//await FilterChanged.InvokeAsync(actFilter);
|
|
await Task.Delay(1);
|
|
elencoOperatori = MIDataservice.ElencoOperatori();
|
|
isLoading = false;
|
|
}
|
|
[Inject]
|
|
protected MessageService MsgService { get; set; } = null!;
|
|
private async void login()
|
|
{
|
|
logged = MIDataservice.loginOperatore(idOperatore, authKey);
|
|
|
|
if (elencoOperatori != null)
|
|
{
|
|
AnagOperatoriModel? currOpr = elencoOperatori.Where(x => (x.MatrOpr == idOperatore) && (x.authKey == authKey)).SingleOrDefault();
|
|
|
|
if (logged)
|
|
{
|
|
if (currOpr != null)
|
|
{
|
|
string hash = MIDataservice.EncriptData(currOpr.authKey);
|
|
OperatoreDTO sessionOpr = new OperatoreDTO
|
|
{
|
|
MatrOpr = currOpr.MatrOpr,
|
|
Nome = currOpr.Nome,
|
|
Cognome = currOpr.Cognome,
|
|
hashAuthKey = hash,
|
|
dtExp = DateTime.Now.AddMinutes(1)
|
|
};
|
|
await MsgService.setCurrOperDtoAsync(sessionOpr);
|
|
NavManager.NavigateTo("InveSession", true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |