aggiunto metodo specifico per il login
This commit is contained in:
@@ -54,32 +54,46 @@ namespace MP.Data.Controllers
|
||||
/// /// <param name="MatrOpr"></param>
|
||||
/// /// <param name="authKey"></param>
|
||||
/// <returns></returns>
|
||||
public List<AnagOperatoriModel> ElencoOperatori(int matrOpr, string authKey)
|
||||
public List<AnagOperatoriModel> ElencoOperatori()
|
||||
{
|
||||
List<AnagOperatoriModel> dbResult = new List<AnagOperatoriModel>();
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
if ((matrOpr == 0) && (authKey == ""))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbOperatori
|
||||
.Where(s => s.MatrOpr > 0)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbOperatori
|
||||
.Where(s => (s.MatrOpr > 0) && (s.MatrOpr == matrOpr) && (s.authKey == authKey))
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
dbResult = dbCtx
|
||||
.DbOperatori
|
||||
.Where(s => s.MatrOpr > 0)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MatrOpr)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// login operatori
|
||||
/// </summary>
|
||||
/// /// <param name="MatrOpr"></param>
|
||||
/// /// <param name="authKey"></param>
|
||||
/// <returns></returns>
|
||||
public bool LoginOperatore(int matrOpr, string authKey)
|
||||
{
|
||||
List<AnagOperatoriModel> dbResult = new List<AnagOperatoriModel>();
|
||||
bool answ = false;
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbOperatori
|
||||
.Where(s => (s.MatrOpr > 0) && (s.MatrOpr == matrOpr) && (s.authKey == authKey))
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
if(dbResult.Count == 1)
|
||||
{
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#region gestione magazzini
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Egw.Core;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using MP.Data.Conf;
|
||||
using MP.Data.DatabaseModels;
|
||||
using MP.INVE.Pages;
|
||||
@@ -6,6 +7,7 @@ using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using StackExchange.Redis;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace MP.INVE.Data
|
||||
{
|
||||
@@ -143,9 +145,51 @@ namespace MP.INVE.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public List<AnagOperatoriModel> ElencoOperatori(int matrOpr, string authkey)
|
||||
public bool loginOperatore(int matrOpr, string authkey)
|
||||
{
|
||||
string source = "";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
AnagOperatoriModel? result = new AnagOperatoriModel();
|
||||
bool answ = false;
|
||||
// cerco in redis...
|
||||
RedisValue rawData = redisDb.StringGet($"{redisElencoOperatori}:{matrOpr}:{authkey}");
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
|
||||
result = JsonConvert.DeserializeObject<AnagOperatoriModel>($"{rawData}");
|
||||
if (result != null)
|
||||
{
|
||||
answ = true;
|
||||
source = "REDIS";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = dbController.LoginOperatore(matrOpr, authkey);
|
||||
if (answ)
|
||||
{
|
||||
result = ElencoOperatori().Where(x => (x.MatrOpr == matrOpr) && (x.authKey == authkey)).SingleOrDefault();
|
||||
}
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSetAsync(redisOperatoreLogged, rawData, getRandTOut(redisLongTimeCache));
|
||||
source = "DB";
|
||||
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new AnagOperatoriModel();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"loginOperatore Read from {source}: {ts.TotalMilliseconds}ms");
|
||||
return answ;
|
||||
}
|
||||
|
||||
public List<AnagOperatoriModel> ElencoOperatori()
|
||||
{
|
||||
string source = "";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
List<AnagOperatoriModel>? result = new List<AnagOperatoriModel>();
|
||||
@@ -153,36 +197,25 @@ namespace MP.INVE.Data
|
||||
RedisValue rawData = redisDb.StringGet(redisElencoOperatori);
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
var dese = JsonConvert.DeserializeObject<List<AnagOperatoriModel>>($"{rawData}");
|
||||
if (dese != null)
|
||||
{
|
||||
if ((matrOpr != 0) && (authkey != ""))
|
||||
{
|
||||
result = dese.Where(x => (x.MatrOpr == matrOpr) && (x.authKey == authkey)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dese;
|
||||
}
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"ElencoOperatori Read from REDIS: {ts.TotalMilliseconds}ms");
|
||||
result = JsonConvert.DeserializeObject<List<AnagOperatoriModel>>($"{rawData}");
|
||||
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.ElencoOperatori(matrOpr, authkey);
|
||||
result = dbController.ElencoOperatori();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSetAsync(redisElencoOperatori, rawData, getRandTOut(redisLongTimeCache));
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"ElencoOperatori Read from DB: {ts.TotalMilliseconds}ms");
|
||||
source = "DB";
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<AnagOperatoriModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"ElencoOperatori Read from {source}: {ts.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -356,7 +389,9 @@ namespace MP.INVE.Data
|
||||
|
||||
private const string redisBaseAddr = "MP:INVE";
|
||||
private const string redisSessionBaseAddr = ":Session:";
|
||||
private const string redisElencoOperatori = redisBaseAddr + ":ListOperatori";
|
||||
private const string redisOperatoriBaseAddr = ":Operatore:";
|
||||
private const string redisElencoOperatori = redisBaseAddr + redisOperatoriBaseAddr + ":ListOperatori";
|
||||
private const string redisOperatoreLogged = redisBaseAddr + redisOperatoriBaseAddr + ":OperatoreLogged";
|
||||
private const string redisSessionCurrList = redisBaseAddr + redisSessionBaseAddr + ":ListSessHist";
|
||||
private const string redisSessionHistList = redisBaseAddr + redisSessionBaseAddr + ":ListSessCurr";
|
||||
private const string redisMagList = redisBaseAddr + ":ListMag";
|
||||
|
||||
@@ -32,10 +32,9 @@ namespace MP.INVE.Pages
|
||||
[Inject]
|
||||
protected MiDataService MIService { get; set; } = null!;
|
||||
|
||||
private string logged { get; set; } = "";
|
||||
private bool logged { get; set; } = false;
|
||||
|
||||
private List<AnagOperatoriModel> operatore = new List<AnagOperatoriModel>();
|
||||
private AnagOperatoriModel currOperatore = new AnagOperatoriModel();
|
||||
protected string idOPeratore { get; set; } = null!;
|
||||
protected string authKey { get; set; } = null!;
|
||||
protected override async Task OnInitializedAsync()
|
||||
@@ -47,22 +46,32 @@ namespace MP.INVE.Pages
|
||||
idOPeratore = _matrOpr;
|
||||
authKey = _authKey;
|
||||
}
|
||||
string pw = MIService.DeriptData(authKey);
|
||||
logged = MIService.loginOperatore(int.Parse(idOPeratore), pw);
|
||||
|
||||
operatore = MIService.ElencoOperatori(int.Parse(idOPeratore), MIService.DeriptData(authKey));
|
||||
|
||||
|
||||
if (operatore != null)
|
||||
if (logged)
|
||||
{
|
||||
if (operatore.Count == 1)
|
||||
if (operatore != null)
|
||||
{
|
||||
logged = "success";
|
||||
NavManager.NavigateTo("Acquisizione");
|
||||
localStorage.SetItemAsync("MatrOpr", idOPeratore);
|
||||
localStorage.SetItemAsync("authKey", authKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
logged = "not success";
|
||||
AnagOperatoriModel? currOpr = operatore.Where(x => (x.MatrOpr == int.Parse(idOPeratore)) && (x.authKey == authKey)).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
|
||||
};
|
||||
if (operatore.Count == 1)
|
||||
{
|
||||
NavManager.NavigateTo("Acquisizione");
|
||||
await localStorage.SetItemAsync("MatrOpr", currOpr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace MP.INVE.Pages
|
||||
|
||||
private int idOperatore { get; set; } = 0;
|
||||
private string authKey { get; set; } = "";
|
||||
private bool logged { get; set; } = false;
|
||||
|
||||
private List<AnagOperatoriModel>? elencoOperatori;
|
||||
|
||||
@@ -42,37 +43,30 @@ namespace MP.INVE.Pages
|
||||
{
|
||||
//await FilterChanged.InvokeAsync(actFilter);
|
||||
await Task.Delay(1);
|
||||
elencoOperatori = MIDataservice.ElencoOperatori(idOperatore, authKey);
|
||||
elencoOperatori = MIDataservice.ElencoOperatori();
|
||||
}
|
||||
|
||||
private void login()
|
||||
{
|
||||
elencoOperatori = MIDataservice.ElencoOperatori(idOperatore, authKey);
|
||||
logged = MIDataservice.loginOperatore(idOperatore, authKey);
|
||||
|
||||
AnagOperatoriModel? currOpr = elencoOperatori.SingleOrDefault();
|
||||
AnagOperatoriModel? currOpr = elencoOperatori.Where(x => (x.MatrOpr == idOperatore) && (x.authKey == authKey)).SingleOrDefault();
|
||||
|
||||
|
||||
if (currOpr != null)
|
||||
if (logged)
|
||||
{
|
||||
string hash = MIDataservice.EncriptData(currOpr.authKey);
|
||||
OperatoreDTO sessionOpr = new OperatoreDTO
|
||||
{
|
||||
MatrOpr = currOpr.MatrOpr,
|
||||
Nome = currOpr.Nome,
|
||||
Cognome = currOpr.Cognome,
|
||||
hashAuthKey = hash
|
||||
};
|
||||
|
||||
|
||||
if (elencoOperatori.Count == 1)
|
||||
if (currOpr != null)
|
||||
{
|
||||
string hash = MIDataservice.EncriptData(currOpr.authKey);
|
||||
OperatoreDTO sessionOpr = new OperatoreDTO
|
||||
{
|
||||
MatrOpr = currOpr.MatrOpr,
|
||||
Nome = currOpr.Nome,
|
||||
Cognome = currOpr.Cognome,
|
||||
hashAuthKey = hash
|
||||
};
|
||||
NavManager.NavigateTo("InveSession", true);
|
||||
localStorage.SetItemAsync("MatrOpr", sessionOpr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user