diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..e051a0d8 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "cweijan.dbclient-jdbc" + ] +} \ No newline at end of file diff --git a/MP-TAB-SERV/Components/CmpTop.razor.cs b/MP-TAB-SERV/Components/CmpTop.razor.cs index 8f465e08..8453c92b 100644 --- a/MP-TAB-SERV/Components/CmpTop.razor.cs +++ b/MP-TAB-SERV/Components/CmpTop.razor.cs @@ -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(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); + } } } diff --git a/MP-TAB-SERV/Components/OdlMan.razor.cs b/MP-TAB-SERV/Components/OdlMan.razor.cs index 4c2b32c3..c47869cd 100644 --- a/MP-TAB-SERV/Components/OdlMan.razor.cs +++ b/MP-TAB-SERV/Components/OdlMan.razor.cs @@ -418,6 +418,7 @@ namespace MP_TAB_SERV.Components } await advStep(currStep++); + // riporto stringa lblOut = sb.ToString().Replace("---", "
"); // 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); } /// @@ -629,6 +630,7 @@ namespace MP_TAB_SERV.Components lblOut = "Selezionare un ORDINE valido!"; } + // refresh finale var tmpTCR = tcRichAttr; checkBtnStatus(); diff --git a/MP-TAB-SERV/Pages/RegNewDevice.razor.cs b/MP-TAB-SERV/Pages/RegNewDevice.razor.cs index 993a095c..a42d0b2d 100644 --- a/MP-TAB-SERV/Pages/RegNewDevice.razor.cs +++ b/MP-TAB-SERV/Pages/RegNewDevice.razor.cs @@ -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(); } diff --git a/MP-TAB-SERV/Shared/MainLayout.razor.cs b/MP-TAB-SERV/Shared/MainLayout.razor.cs index 617d1c18..2d993db9 100644 --- a/MP-TAB-SERV/Shared/MainLayout.razor.cs +++ b/MP-TAB-SERV/Shared/MainLayout.razor.cs @@ -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) { diff --git a/MP.Data/DTO/userTknDTO.cs b/MP.Data/DTO/userTknDTO.cs index bc9a8db5..4ff3b3bd 100644 --- a/MP.Data/DTO/userTknDTO.cs +++ b/MP.Data/DTO/userTknDTO.cs @@ -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; } } } diff --git a/MP.Data/Services/MessageService.cs b/MP.Data/Services/MessageService.cs index 2855c6ec..000f9e77 100644 --- a/MP.Data/Services/MessageService.cs +++ b/MP.Data/Services/MessageService.cs @@ -248,11 +248,12 @@ namespace MP.Data.Services return SteamCrypto.DecryptString(encData, Constants.passPhrase); } - public async Task DoLogIn(string decodValue) + public async Task 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(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); } + /// + /// Restituisce il record device GUID da localstorage + /// + /// + public async Task GetCurrDevGuidLSAsync() + { + Guid answ = new Guid(); + var result = await localStorage.GetItemAsync("devGuid"); + if (result != null) + { + answ = Guid.Parse(result); + } + return answ; + } /// /// Restituisce il record OperatoreDTO da localstorage /// /// - public async Task GetCurrOperDtoAsync() + public async Task GetCurrOperDtoLSAsync() { string answ = ""; var result = await localStorage.GetItemAsync("currTkn"); if (result != null) { - //var data = JsonConvert.DeserializeObject(result); answ = result; } return answ; @@ -423,13 +440,24 @@ namespace MP.Data.Services /// scrive il record OperatoreDTO nel localstorage /// /// - public async Task SetCurrOperDtoAsync(string currTkn) + public async Task SetCurrOperDtoLSAsync(string currTkn) { bool answ = false; await localStorage.SetItemAsync("currTkn", currTkn); answ = true; return answ; } + /// + /// scrive il record Device GUID nel localstorage + /// + /// + public async Task SetCurrDevGuidLSAsync(Guid currDevGuid) + { + bool answ = false; + await localStorage.SetItemAsync("devGuid", currDevGuid.ToString()); + answ = true; + return answ; + } /// /// Scrive il valore di IPV4 del device nel localstoragee diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index 0de3b7aa..c5963172 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -1615,18 +1615,18 @@ namespace MP.Data.Services } /// - /// Scrive l'hash dell'oggetto curr opr + /// Legge l'oggetto operatore loggato /// /// /// - public async Task OperatoreGetRedis(int matrOpr) + public async Task 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 /// /// /// - public async Task OperatoreSetRedis(int matrOpr, string currOpr) + public async Task 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);