This commit is contained in:
Samuele Locatelli
2023-12-13 19:35:34 +01:00
8 changed files with 99 additions and 53 deletions
+5
View File
@@ -0,0 +1,5 @@
{
"recommendations": [
"cweijan.dbclient-jdbc"
]
}
+31 -24
View File
@@ -27,6 +27,7 @@ namespace MP_TAB_SERV.Components
#region Protected Properties
protected string CurrOprTknLS { get; set; } = null!;
//protected Guid CurrDevGuid { get; set; }
protected string LastOpenedPage { get; set; } = null!;
protected string CurrMacc { get; set; } = null!;
@@ -63,7 +64,7 @@ namespace MP_TAB_SERV.Components
protected async Task RefreshLogIn(string decodValue)
{
bool done = await MsgServ.DoLogIn(decodValue);
bool done = await MsgServ.DoLogIn(decodValue, false);
if (done)
{
if (!string.IsNullOrEmpty(LastOpenedPage) && !string.IsNullOrEmpty(CurrMacc))
@@ -84,7 +85,7 @@ namespace MP_TAB_SERV.Components
Log.Info("Start ForceReload");
ResetClass = "btn-warning";
await InvokeAsync(StateHasChanged);
var currToken = await MsgServ.GetCurrOperDtoAsync();
var currToken = await MsgServ.GetCurrOperDtoLSAsync();
var lastOpr = await MsgServ.GetLastMatrOprAsync();
// reset cache varie
await MsgServ.ClearLocalStor();
@@ -92,7 +93,7 @@ namespace MP_TAB_SERV.Components
await MDataService.FlushCache();
// salvo di nuovo opr
await MsgServ.SetLastMatrOprAsync(lastOpr);
await MsgServ.SetCurrOperDtoAsync(currToken);
await MsgServ.SetCurrOperDtoLSAsync(currToken);
// reload MStor
await ReloadMemStor();
// calcolo tempo esecuzione
@@ -123,44 +124,50 @@ namespace MP_TAB_SERV.Components
await Task.Delay(1);
int expDays = SMServ.GetConfInt("cookieDayExpire");
expDT = DateTime.Now.AddDays(expDays);
var CurrDevGuid = await MsgServ.GetCurrDevGuidLSAsync();
//if (string.IsNullOrEmpty(CurrDevGuid.ToString()))
if (CurrDevGuid == Guid.Empty)
{
CurrDevGuid = Guid.NewGuid();
await MsgServ.SetCurrDevGuidLSAsync(CurrDevGuid);
}
CurrOprTknLS = await MsgServ.GetCurrOperDtoAsync();
CurrOprTknLS = await MsgServ.GetCurrOperDtoLSAsync();
LastOpenedPage = await MsgServ.LastOpenedPageGet();
CurrMacc = await MsgServ.IdxMaccGet();
var decodedUrl = Uri.UnescapeDataString(CurrOprTknLS);
// verifico se non avessi dati operatore
//var diffOfTime = DateTime.Now - MsgServ.dtLastAction;
//if (diffOfTime.Minutes >= 1)
//{
// NavMan.NavigateTo("logout");
//}
//else
if (MsgServ.RigaOper == null)
if (!string.IsNullOrEmpty(CurrOprTknLS))
{
await RefreshLogIn(decodedUrl);
var decryptedData = MsgServ.DecryptData(CurrOprTknLS);
if (!string.IsNullOrEmpty(decryptedData))
{
var oprObj = JsonConvert.DeserializeObject<userTknDTO>(decryptedData);
if(oprObj != null)
{
MsgServ.RigaOper = oprObj.currOpr;
}
}
}
CurrOprTknRedis = await TDService.OperatoreGetRedis(MatrOpr);
CurrOprTknRedis = await TDService.OperatoreGetRedis(MatrOpr, CurrDevGuid);
if (CurrOprTknRedis == "")
if (string.IsNullOrEmpty(CurrOprTknRedis))
{
if (!NavMan.Uri.Contains("reg-new-device"))
{
NavMan.NavigateTo("reg-new-device", true);
}
}
else if (CurrOprTknRedis != "")
else if (!string.IsNullOrEmpty(CurrOprTknRedis) && CurrOprTknRedis == CurrOprTknLS)
{
//if (!NavMan.Uri.Contains("status-map"))
//{
//}
//if (LastOpenedPage != "")
//{
// NavMan.NavigateTo(LastOpenedPage, true);
//}
if (MsgServ.RigaOper == null)
{
await RefreshLogIn(decodedUrl);
}
}
}
+5 -3
View File
@@ -418,6 +418,7 @@ namespace MP_TAB_SERV.Components
}
await advStep(currStep++);
// riporto stringa
lblOut = sb.ToString().Replace("---", "<br/>");
// update buttons...
@@ -427,15 +428,15 @@ namespace MP_TAB_SERV.Components
inAttr = false;
IdxPOdlSel = 0;
RecMSE = null;
await advStep(currStep++);
// faccio refresh e riporto
await RefreshData();
await CheckAttr();
await advStep(currStep++);
// chiudo update...
isProcessing = false;
//await InvokeAsync(StateHasChanged);
await InvokeAsync(StateHasChanged);
// qui rimando a pag principale...
NavMan.NavigateTo("status-map", true);
//NavMan.NavigateTo("status-map", true);
}
/// <summary>
@@ -629,6 +630,7 @@ namespace MP_TAB_SERV.Components
lblOut = "Selezionare un ORDINE valido!";
}
// refresh finale
var tmpTCR = tcRichAttr;
checkBtnStatus();
+4 -6
View File
@@ -45,8 +45,6 @@ namespace MP_TAB_SERV.Pages
protected string CurrOprTknRedis { get; set; } = null!;
protected DateTime expDT { get; set; } = DateTime.Now;
protected int matrOpr
{
get
@@ -90,6 +88,7 @@ namespace MP_TAB_SERV.Pages
protected async Task FirstLogIn()
{
rigaOpr = await TDService.OperatoreSearch(matrOpr, authKey);
var devGuid = await MsgServ.GetCurrDevGuidLSAsync();
if (rigaOpr == null)
{
var deHash = TDService.DecryptData(authKey);
@@ -100,15 +99,15 @@ namespace MP_TAB_SERV.Pages
userTknDTO newUserTkn = new userTknDTO()
{
currOpr = rigaOpr,
expTime = expDT
DevGuid = devGuid
};
var jsonTkn = JsonConvert.SerializeObject(newUserTkn);
string hash = TDService.EncryptData(jsonTkn);
MsgServ.RigaOper = rigaOpr;
await MsgServ.SetCurrOperDtoAsync(hash);
await MsgServ.SetCurrOperDtoLSAsync(hash);
await MsgServ.SetLastMatrOprAsync(rigaOpr.MatrOpr);
await TDService.OperatoreSetRedis(matrOpr, hash);
await TDService.OperatoreSetRedis(matrOpr, hash, devGuid);
NavMan.NavigateTo("status-map");
}
else
@@ -124,7 +123,6 @@ namespace MP_TAB_SERV.Pages
matrOpr = await MsgServ.GetLastMatrOprAsync();
TDService.ConfigGetVal("cookieDayExpire", ref expDays);
ShowScanBarcode = !SMServ.GetConfBool("TAB_WebCamHide");
expDT = DateTime.Now.AddDays(expDays);
oprsList = await TDService.ElencoOperatori();
}
+10 -5
View File
@@ -82,7 +82,6 @@ namespace MP_TAB_SERV.Shared
protected async Task handleBodyClick()
{
await Task.Delay(1);
MsgServ.dtLastAction = DateTime.Now;
if (!pageOk)
{
await checkDtDiff2Logout();
@@ -95,6 +94,7 @@ namespace MP_TAB_SERV.Shared
}
protected int typeScadLogin { get; set; } = 0;
protected int dtScadLogin { get; set; } = 0;
protected Guid currDevGuid { get; set; } = new Guid();
protected async Task checkDtDiff2Logout()
{
@@ -111,10 +111,11 @@ namespace MP_TAB_SERV.Shared
case 1:
if (tsDeltaAct.Minutes >= dtScadLogin)
{
var userTkn = await TDataService.OperatoreGetRedis(MatrOpr);
var userTkn = await TDataService.OperatoreGetRedis(MatrOpr, currDevGuid);
if (!string.IsNullOrEmpty(userTkn))
{
await MsgServ.DoLogIn(userTkn);
await MsgServ.DoLogIn(userTkn, true);
MsgServ.dtLastAction = DateTime.Now;
MsgServ.dtLastSave = DateTime.Now;
}
else
@@ -127,10 +128,11 @@ namespace MP_TAB_SERV.Shared
// se fosse oltre 1 minuto da ultimo save --> salvo!
if (tsDeltaSave.TotalMinutes > 1)
{
var userTkn = await TDataService.OperatoreGetRedis(MatrOpr);
var userTkn = await TDataService.OperatoreGetRedis(MatrOpr, currDevGuid);
if (!string.IsNullOrEmpty(userTkn))
{
await MsgServ.DoLogIn(userTkn);
await MsgServ.DoLogIn(userTkn, true);
MsgServ.dtLastAction = DateTime.Now;
MsgServ.dtLastSave = DateTime.Now;
}
}
@@ -148,6 +150,9 @@ namespace MP_TAB_SERV.Shared
typeScadLogin = MStor.GetConfInt("TAB_TypeScadLogin");
dtScadLogin = MStor.GetConfInt("TAB_dtTimerScadLogin");
NavMan.LocationChanged += HandleLocationChanged;
currDevGuid = await MsgServ.GetCurrDevGuidLSAsync();
// verifica preliminare setup mdati
if (!MStor.MenuOk)
{
+2 -1
View File
@@ -10,6 +10,7 @@ namespace MP.Data.DTO
public class userTknDTO
{
public AnagOperatoriModel currOpr { get; set; } = null;
public DateTime expTime { get; set; } = DateTime.Now;
//public DateTime expTime { get; set; } = DateTime.Now;
public Guid DevGuid { get; set; }
}
}
+37 -9
View File
@@ -248,11 +248,12 @@ namespace MP.Data.Services
return SteamCrypto.DecryptString(encData, Constants.passPhrase);
}
public async Task<bool> DoLogIn(string decodValue)
public async Task<bool> DoLogIn(string decodValue, bool saveOpr)
{
bool answ = false;
expDays = SMService.GetConfInt("cookieDayExpire");
var expDT = DateTime.Now.AddDays(expDays);
//expDays = SMService.GetConfInt("cookieDayExpire");
//var expDT = DateTime.Now.AddDays(expDays);
var devGuid = await GetCurrDevGuidLSAsync();
// decifro i valori..
var decrVal = DecryptData(decodValue);
var opData = JsonConvert.DeserializeObject<userTknDTO>(decrVal);
@@ -264,15 +265,18 @@ namespace MP.Data.Services
userTknDTO newUserTkn = new userTknDTO()
{
currOpr = rigaOpr,
expTime = expDT
DevGuid = devGuid
};
var jsonTkn = JsonConvert.SerializeObject(newUserTkn);
string hash = TDService.EncryptData(jsonTkn);
RigaOper = rigaOpr;
await SetLastMatrOprAsync(rigaOpr.MatrOpr);
await SetCurrOperDtoAsync(hash);
await TDService.OperatoreSetRedis(rigaOpr.MatrOpr, hash);
await SetCurrOperDtoLSAsync(hash);
if (saveOpr)
{
await TDService.OperatoreSetRedis(rigaOpr.MatrOpr, hash, devGuid);
}
answ = true;
}
}
@@ -284,17 +288,30 @@ namespace MP.Data.Services
return SteamCrypto.EncryptString(rawData, Constants.passPhrase);
}
/// <summary>
/// Restituisce il record device GUID da localstorage
/// </summary>
/// <returns></returns>
public async Task<Guid> GetCurrDevGuidLSAsync()
{
Guid answ = new Guid();
var result = await localStorage.GetItemAsync<string>("devGuid");
if (result != null)
{
answ = Guid.Parse(result);
}
return answ;
}
/// <summary>
/// Restituisce il record OperatoreDTO da localstorage
/// </summary>
/// <returns></returns>
public async Task<string> GetCurrOperDtoAsync()
public async Task<string> GetCurrOperDtoLSAsync()
{
string answ = "";
var result = await localStorage.GetItemAsync<string>("currTkn");
if (result != null)
{
//var data = JsonConvert.DeserializeObject<userTknDTO>(result);
answ = result;
}
return answ;
@@ -423,13 +440,24 @@ namespace MP.Data.Services
/// scrive il record OperatoreDTO nel localstorage
/// </summary>
/// <returns></returns>
public async Task<bool> SetCurrOperDtoAsync(string currTkn)
public async Task<bool> SetCurrOperDtoLSAsync(string currTkn)
{
bool answ = false;
await localStorage.SetItemAsync("currTkn", currTkn);
answ = true;
return answ;
}
/// <summary>
/// scrive il record Device GUID nel localstorage
/// </summary>
/// <returns></returns>
public async Task<bool> SetCurrDevGuidLSAsync(Guid currDevGuid)
{
bool answ = false;
await localStorage.SetItemAsync("devGuid", currDevGuid.ToString());
answ = true;
return answ;
}
/// <summary>
/// Scrive il valore di IPV4 del device nel localstoragee
+5 -5
View File
@@ -1615,18 +1615,18 @@ namespace MP.Data.Services
}
/// <summary>
/// Scrive l'hash dell'oggetto curr opr
/// Legge l'oggetto operatore loggato
/// </summary>
/// <param name="matrOpr"></param>
/// <returns></returns>
public async Task<string> OperatoreGetRedis(int matrOpr)
public async Task<string> OperatoreGetRedis(int matrOpr, Guid currDevGuid)
{
string source = "REDIS";
Stopwatch sw = new Stopwatch();
sw.Start();
string answ = "";
// cerco in redis...
string currKey = $"{redisUserDataKey}:CurrOpr:{matrOpr}";
string currKey = $"{redisUserDataKey}:CurrOpr:{matrOpr}:CurrDevGuid:{currDevGuid}";
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (rawData.HasValue)
{
@@ -1672,7 +1672,7 @@ namespace MP.Data.Services
/// </summary>
/// <param name="currOpr"></param>
/// <returns></returns>
public async Task<string> OperatoreSetRedis(int matrOpr, string currOpr)
public async Task<string> OperatoreSetRedis(int matrOpr, string currOpr, Guid currDevGuid)
{
setExpDays();
string source = "REDIS";
@@ -1680,7 +1680,7 @@ namespace MP.Data.Services
sw.Start();
string answ = "";
// cerco in redis...
string currKey = $"{redisUserDataKey}:CurrOpr:{matrOpr}";
string currKey = $"{redisUserDataKey}:CurrOpr:{matrOpr}:CurrDevGuid:{currDevGuid}";
//RedisValue rawData = await redisDb.StringGetAsync(currKey);
// serializzo e salvo...
//rawData = JsonConvert.SerializeObject(currOpr);