Fix due tipologie di login

This commit is contained in:
Samuele Locatelli
2024-01-08 12:21:25 +01:00
parent 20ae251943
commit 1eb01b0532
12 changed files with 210 additions and 150 deletions
+11 -1
View File
@@ -11,7 +11,17 @@
}
else
{
<ProgBar currVal="@CurrExpVal" maxVal="@MaxExpVal" singleLine="true" baseUM="m" yelLim="@yLimit" redLim="@rLimit"></ProgBar>
if (MatrOper >= 0)
{
if (showProgrBar)
{
<ProgBar currVal="@CurrExpVal" maxVal="@MaxExpVal" singleLine="true" baseUM="m" yelLim="@yLimit" redLim="@rLimit"></ProgBar>
}
}
else
{
<div class="alert alert-info text-center p-0 mb-0">...login...</div>
}
}
}
</div>
+71 -12
View File
@@ -8,9 +8,15 @@ namespace MP_TAB3.Components
{
#region Public Properties
[Parameter]
public Guid CurrDevGuid { get; set; }
[Parameter]
public int DtScadLogin { get; set; } = 0;
[Parameter]
public int MatrOper { get; set; } = -1;
[Parameter]
public int TypeScadLogin { get; set; } = -1;
@@ -41,6 +47,9 @@ namespace MP_TAB3.Components
[Inject]
protected SharedMemService SMServ { get; set; } = null!;
[Inject]
protected TabDataService TDataService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
@@ -49,16 +58,50 @@ namespace MP_TAB3.Components
{
var pUpd = Task.Run(async () =>
{
if (TypeScadLogin > 0)
{
var diffOfTime = DateTime.Now.Subtract(MsgServ.dtLastAction);
CurrExpVal = MaxExpVal - diffOfTime.TotalMinutes;
}
else
{
}
adesso = DateTime.Now;
await InvokeAsync(() => StateHasChanged());
// solo se NON sono in login...
if (!IsLoginPage)
{
var diffOfTime = adesso.Subtract(MsgServ.dtLastAction);
CurrExpVal = MaxExpVal - diffOfTime.TotalMinutes;
if (TypeScadLogin == 1)
{
if (CurrExpVal < 0)
{
MsgServ.dtLastAction = adesso;
NavMan.NavigateTo("logout");
}
}
// in questo caso cerco SOLO se sia scaduto su redis
else if (TypeScadLogin == 2)
{
// mitigazione check: solo ogni 10 secondi...
if (adesso.Subtract(MsgServ.dtLastSave).TotalSeconds > 10)
{
MsgServ.dtLastSave = adesso;
// rileggo scadenza ultima...
TimeSpan tsScadenza = TDataService.OperatoreGetGuidTTL(MatrOper, CurrDevGuid);
// mostro scadenza SOLO se inferiore a 24h...
showProgrBar = tsScadenza.TotalHours < 24;
// se < 0 --> login
if (tsScadenza.TotalMinutes < 0)
{
NavMan.NavigateTo("logout");
}
else
{
MsgServ.dtLastAction = adesso.Subtract(TimeSpan.FromMinutes(MaxExpVal)).Add(tsScadenza);
}
// comunque controllo chiave redis
var userTkn = await TDataService.OperatoreGetRedis(MatrOper, CurrDevGuid);
if (string.IsNullOrEmpty(userTkn))
{
NavMan.NavigateTo("logout");
}
}
}
}
await InvokeAsync(StateHasChanged);
});
pUpd.Wait();
}
@@ -68,9 +111,14 @@ namespace MP_TAB3.Components
var rawVers = typeof(Program).Assembly.GetName().Version;
version = rawVers != null ? rawVers : new Version("0.0.0.0");
DtScadLogin = SMServ.GetConfInt("TAB_dtTimerScadLogin");
showProgrBar = TypeScadLogin == 1;
MaxExpVal = DtScadLogin;
yLimit = MaxExpVal * 0.3;
rLimit = MaxExpVal * 0.1;
// rileggo scadenza ultima...
TimeSpan tsScadenza = TDataService.OperatoreGetGuidTTL(MatrOper, CurrDevGuid);
MsgServ.dtLastAction = adesso.Subtract(TimeSpan.FromMinutes(MaxExpVal)).Add(tsScadenza);
showProgrBar = tsScadenza.TotalHours < 24;
StartTimer();
}
@@ -89,6 +137,7 @@ namespace MP_TAB3.Components
private DateTime adesso = DateTime.Now;
private System.Timers.Timer aTimer = null!;
private bool showProgrBar = true;
private Version version = null!;
#endregion Private Fields
@@ -96,20 +145,30 @@ namespace MP_TAB3.Components
#region Private Properties
private double CurrExpVal { get; set; } = 50;
private bool IsLoginPage
{
get
{
string currPage = NavMan.Uri;
return currPage.Contains("logout") || currPage.Contains("reg-new-device");
}
}
private double MaxExpVal { get; set; } = 100;
private double rLimit { get; set; } = 10;
private string timeUm
private string CurrUM
{
get
{
string answ = "m";
if (CurrExpVal > 60)
if (MaxExpVal > 60)
{
answ = "h";
}
else if (CurrExpVal > 1440)
else if (MaxExpVal > 1440)
{
answ = "gg";
}
+7 -45
View File
@@ -17,6 +17,8 @@ namespace MP_TAB3.Components
public List<LinkMenu> CurrMenuItems { get; set; } = new List<LinkMenu>();
[Parameter]
public EventCallback<bool> EA_UserIsOk { get; set; }
[Parameter]
public EventCallback<bool> EA_ReloadMStor { get; set; }
#endregion Public Properties
@@ -29,7 +31,7 @@ namespace MP_TAB3.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!;
@@ -68,7 +70,7 @@ namespace MP_TAB3.Components
protected async Task RefreshLogIn(string decodValue)
{
bool done = false;
if (TypeScadLogin <= 0)
if (TypeScadLogin <= 0 || TypeScadLogin == 2)
{
done = await MsgServ.DoLogIn(decodValue, false);
}
@@ -107,8 +109,8 @@ namespace MP_TAB3.Components
await MsgServ.SetCurrDevGuidLSAsync(devGuid);
await MsgServ.SetLastMatrOprAsync(lastOpr);
await MsgServ.SetCurrOperDtoLSAsync(currToken);
// reload MStor
await ReloadMemStor();
// richiesta reload MStor
await EA_ReloadMStor.InvokeAsync(true);
// calcolo tempo esecuzione
sw.Stop();
int delta = 500 - (int)sw.ElapsedMilliseconds;
@@ -116,7 +118,7 @@ namespace MP_TAB3.Components
await Task.Delay(delta);
ResetClass = "btn-primary";
// await InvokeAsync(StateHasChanged);
Log.Info($"ForceReload completed in {sw.ElapsedMilliseconds}ms");
Log.Info($"ForceReload completed in {sw.Elapsed.TotalMilliseconds}ms");
// ricarica pagina!
NavMan.NavigateTo("status-map");
}
@@ -135,9 +137,6 @@ namespace MP_TAB3.Components
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
#if false
TypeScadLogin = SMServ.GetConfInt("TAB_TypeScadLogin");
#endif
var CurrDevGuid = await MsgServ.GetCurrDevGuidLSAsync();
if (CurrDevGuid == Guid.Empty)
@@ -182,43 +181,6 @@ namespace MP_TAB3.Components
}
}
protected async Task ReloadMemStor()
{
// in primis svuoto...
MStor.ClearCache();
// rileggo link
var allData = await MDataService.ListLinkAll();
MStor.SetupMenu(allData);
// fix config...
var allConf = await MDataService.ConfigGetAll();
MStor.SetConfig(allConf);
// fix MSFD...
var allMSFD = await TDService.VMSFDGetAll();
MStor.SetMsfd(allMSFD);
// fix slave
var macSlave = await TDService.Macchine2Slave();
MStor.SetM2S(macSlave);
// fix elenco eventi
var allEvents = await TDService.AnagEventiGetAll();
MStor.SetEventi(allEvents);
// fix elenco stati
var allStati = await TDService.AnaStatiGetAll();
MStor.SetStati(allStati);
// non da farsi globalmente // fix macchine var allMach = await
// MDataService.MacchineByMatrOper(0); MStor.DictMacchine = allMach.ToDictionary(x =>
// x.IdxMacchina, x => $"{x.IdxMacchina} | {x.Nome}");
// fix vocabolario
var allVoc = TDService.VocabolarioGetAll();
MStor.SetVocab(allVoc);
// resetto il tabDServ
await TDService.FlushCache();
// ricarica la config...
TDService.SetupConfig();
}
#endregion Protected Methods
#region Private Fields
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>6.16.2401.511</Version>
<Version>6.16.2401.812</Version>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>MP_TAB3</RootNamespace>
</PropertyGroup>
+14 -22
View File
@@ -1,41 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazored.LocalStorage;
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_TAB3;
using MP_TAB3.Shared;
using MP_TAB3.Components;
using MP.Data;
using MP.Data.DatabaseModels;
using MP.Data.DTO;
using MP.Data.Services;
using Newtonsoft.Json;
using NLog;
using EgwCoreLib.Razor;
using Blazored.LocalStorage;
namespace MP_TAB3.Pages
{
public partial class Logout
{
#region Protected Properties
[Inject]
protected ILocalStorageService localStorage { get; set; } = null!;
[Inject]
protected TabDataService TDService { get; set; } = null!;
[Inject]
protected MessageService MsgServ { get; set; } = null!;
[Inject]
protected NavigationManager NavMan { get; set; } = null!;
[Inject]
protected TabDataService TDService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
@@ -60,5 +50,7 @@ namespace MP_TAB3.Pages
MsgServ.RigaOper = null;
NavMan.NavigateTo("reg-new-device", true);
}
#endregion Protected Methods
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MAPOSPEC </i>
<h4>Versione: 6.16.2401.511</h4>
<h4>Versione: 6.16.2401.812</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
6.16.2401.511
6.16.2401.812
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.16.2401.511</version>
<version>6.16.2401.812</version>
<url>https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/MP-TAB3.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+3 -3
View File
@@ -4,9 +4,9 @@
<PageTitle>MP-TAB3</PageTitle>
<div class="page" @onclick="()=>handleBodyClick()">
<div class="page" @onclick="()=>HandleBodyClick()">
<main>
<CmpTop TypeScadLogin="@typeScadLogin" CurrMenuItems="@CurrMenuItems" EA_UserIsOk="checkIfUserOk"></CmpTop>
<CmpTop TypeScadLogin="@typeScadLogin" CurrMenuItems="@CurrMenuItems" EA_UserIsOk="SetUserOk" EA_ReloadMStor="ForceReloadMStor"></CmpTop>
@if (userIsOk || NavMan.Uri.Contains("reg-new-device"))
{
<article class="content pt-1 d-flex mb-5">
@@ -24,5 +24,5 @@
</main>
</div>
<div class="fixed-bottom">
<CmpFooter TypeScadLogin="@typeScadLogin" DtScadLogin="@dtScadLogin"></CmpFooter>
<CmpFooter TypeScadLogin="@typeScadLogin" DtScadLogin="@dtScadLogin" MatrOper="@MatrOpr" CurrDevGuid="@currDevGuid"></CmpFooter>
</div>
+43 -23
View File
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Components.Routing;
using Microsoft.JSInterop;
using MP.Data.DatabaseModels;
using MP.Data.Services;
using MP_TAB3.Components;
using NLog;
namespace MP_TAB3.Shared
@@ -94,23 +93,25 @@ namespace MP_TAB3.Shared
protected async Task checkDtDiff2Logout()
{
TimeSpan tsDeltaAct = DateTime.Now.Subtract(MsgServ.dtLastAction);
TimeSpan tsDeltaSave = DateTime.Now.Subtract(MsgServ.dtLastSave);
DateTime adesso = DateTime.Now;
TimeSpan tsDeltaAct = adesso.Subtract(MsgServ.dtLastAction);
TimeSpan tsDeltaSave = adesso.Subtract(MsgServ.dtLastSave);
string userTkn = "";
switch (typeScadLogin)
{
case 1:
if (tsDeltaAct.TotalMinutes >= dtScadLogin)
{
var userTkn = await TDataService.OperatoreGetRedis(MatrOpr, currDevGuid);
if (!string.IsNullOrEmpty(userTkn))
userTkn = await TDataService.OperatoreGetRedis(MatrOpr, currDevGuid);
if (string.IsNullOrEmpty(userTkn))
{
await MsgServ.DoLogIn(userTkn, true);
MsgServ.dtLastAction = DateTime.Now;
MsgServ.dtLastSave = DateTime.Now;
NavMan.NavigateTo("logout");
}
else
{
NavMan.NavigateTo("logout");
await MsgServ.DoLogIn(userTkn, true);
MsgServ.dtLastAction = adesso;
MsgServ.dtLastSave = adesso;
}
}
else
@@ -118,21 +119,35 @@ namespace MP_TAB3.Shared
// se fosse oltre 1 minuto da ultimo save --> salvo!
if (tsDeltaSave.TotalMinutes > 1)
{
var userTkn = await TDataService.OperatoreGetRedis(MatrOpr, currDevGuid);
userTkn = await TDataService.OperatoreGetRedis(MatrOpr, currDevGuid);
if (!string.IsNullOrEmpty(userTkn))
{
await MsgServ.DoLogIn(userTkn, true);
MsgServ.dtLastAction = DateTime.Now;
MsgServ.dtLastSave = DateTime.Now;
MsgServ.dtLastAction = adesso;
MsgServ.dtLastSave = adesso;
}
}
}
break;
case 2:
if (tsDeltaAct.TotalMinutes >= dtScadLogin)
// se fosse oltre 1 minuto da ultimo save --> salvo!
if (tsDeltaSave.TotalMinutes > 1)
{
NavMan.NavigateTo("logout");
// mitigazione controlli: solo ogni 1 minuto...
if (tsDeltaSave.TotalMinutes > 1)
{
MsgServ.dtLastSave = adesso;
userTkn = await TDataService.OperatoreGetRedis(MatrOpr, currDevGuid);
if (string.IsNullOrEmpty(userTkn))
{
NavMan.NavigateTo("logout");
}
if (tsDeltaAct.TotalMinutes >= dtScadLogin)
{
NavMan.NavigateTo("logout");
}
}
}
break;
@@ -145,13 +160,12 @@ namespace MP_TAB3.Shared
}
}
protected async Task checkIfUserOk(bool isOk)
protected async Task ForceReloadMStor(bool isOk)
{
await Task.Delay(1);
userIsOk = isOk;
await ReloadMemStor();
}
protected async Task handleBodyClick()
protected async Task HandleBodyClick()
{
await Task.Delay(1);
if (!pageOk)
@@ -160,6 +174,11 @@ namespace MP_TAB3.Shared
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
currDevGuid = await MsgServ.GetCurrDevGuidLSAsync();
}
/// <summary>
/// Init struttura dati
/// </summary>
@@ -184,11 +203,6 @@ namespace MP_TAB3.Shared
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
currDevGuid = await MsgServ.GetCurrDevGuidLSAsync();
}
protected async Task ReloadMemStor()
{
// in primis svuoto...
@@ -223,6 +237,12 @@ namespace MP_TAB3.Shared
TDataService.SetupConfig();
}
protected async Task SetUserOk(bool isOk)
{
await Task.Delay(1);
userIsOk = isOk;
}
#endregion Protected Methods
#region Private Fields
+27 -38
View File
@@ -53,30 +53,6 @@ namespace MP.Data.Services
#endregion Public Events
#if false
protected bool _tReset { get; set; } = false;
protected bool tReset
{
get => _tReset;
set
{
if (_tReset != value)
{
_tReset = value;
resetTimer();
}
}
}
protected void resetTimer()
{
if (EA_ResetFooterTimer != null)
{
EA_ResetFooterTimer?.Invoke();
}
}
#endif
#region Public Properties
public string CognomeNome
@@ -251,8 +227,6 @@ namespace MP.Data.Services
public async Task<bool> DoLogIn(string decodValue, bool saveOpr)
{
bool answ = false;
//expDays = SMService.GetConfInt("cookieDayExpire");
//var expDT = DateTime.Now.AddDays(expDays);
var devGuid = await GetCurrDevGuidLSAsync();
// decifro i valori..
var decrVal = DecryptData(decodValue);
@@ -306,6 +280,7 @@ namespace MP.Data.Services
}
return answ;
}
/// <summary>
/// Restituisce il record OperatoreDTO da localstorage
/// </summary>
@@ -351,6 +326,20 @@ namespace MP.Data.Services
return answ;
}
public TimeSpan GetKeyTTL(string redKey)
{
TimeSpan answ = new TimeSpan();
try
{
answ = redisDb.KeyTimeToLive(redKey) ?? new TimeSpan();
}
catch (Exception exc)
{
Log.Info($"Errore GetKeyTTL | currKey: {redKey}{Environment.NewLine}{exc}");
}
return answ;
}
/// <summary>
/// Restituisce ultima matrOpr registrata da localstorage
/// </summary>
@@ -440,17 +429,6 @@ namespace MP.Data.Services
return hasKey;
}
/// <summary>
/// scrive il record OperatoreDTO nel localstorage
/// </summary>
/// <returns></returns>
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>
@@ -463,6 +441,18 @@ namespace MP.Data.Services
return answ;
}
/// <summary>
/// scrive il record OperatoreDTO nel localstorage
/// </summary>
/// <returns></returns>
public async Task<bool> SetCurrOperDtoLSAsync(string currTkn)
{
bool answ = false;
await localStorage.SetItemAsync("currTkn", currTkn);
answ = true;
return answ;
}
/// <summary>
/// Scrive il valore di IPV4 del device nel localstoragee
/// </summary>
@@ -515,7 +505,6 @@ namespace MP.Data.Services
return answ;
}
/// <summary>
/// Recupero singola preferenza utente
/// </summary>
+30 -2
View File
@@ -1617,6 +1617,36 @@ namespace MP.Data.Services
return answ;
}
public TimeSpan GetKeyTTL(string redKey)
{
TimeSpan answ = TimeSpan.FromMinutes(-1);
try
{
answ = redisDb.KeyTimeToLive(redKey) ?? new TimeSpan();
}
catch (Exception exc)
{
Log.Info($"Errore GetKeyTTL | currKey: {redKey}{Environment.NewLine}{exc}");
}
return answ;
}
/// <summary>
/// Legge l'oggetto operatore+device loggato e restituisce la sua TTL
/// </summary>
/// <param name="matrOpr"></param>
/// <param name="currDevGuid"></param>
/// <returns></returns>
public TimeSpan OperatoreGetGuidTTL(int matrOpr, Guid currDevGuid)
{
TimeSpan answ = new TimeSpan();
// cerco in redis...
string currKey = $"{redisUserDataKey}:CurrOpr:{matrOpr}:CurrDevGuid:{currDevGuid}";
answ = GetKeyTTL(currKey);
return answ;
}
/// <summary>
/// Legge l'oggetto operatore loggato
/// </summary>
@@ -1633,8 +1663,6 @@ namespace MP.Data.Services
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (rawData.HasValue)
{
//var encrData = SteamCrypto.DecryptString(rawData, passPhrase);
//answ = JsonConvert.DeserializeObject<string>(rawData);
answ = rawData;
}
if (answ == null)