aggiunta gestione login con guid dispositivo

This commit is contained in:
zaccaria.majid
2023-12-13 18:18:45 +01:00
parent db9d67e841
commit ec94724c79
10 changed files with 81 additions and 47 deletions
+27 -21
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!;
@@ -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,23 +124,35 @@ 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 (!string.IsNullOrEmpty(CurrOprTknLS))
{
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 (string.IsNullOrEmpty(CurrOprTknRedis))
@@ -149,19 +162,12 @@ namespace MP_TAB_SERV.Components
NavMan.NavigateTo("reg-new-device", true);
}
}
else if (!string.IsNullOrEmpty(CurrOprTknRedis))
else if (!string.IsNullOrEmpty(CurrOprTknRedis) && CurrOprTknRedis == CurrOprTknLS)
{
if (MsgServ.RigaOper == null)
{
await RefreshLogIn(decodedUrl);
}
//if (!NavMan.Uri.Contains("status-map"))
//{
//}
//if (LastOpenedPage != "")
//{
// NavMan.NavigateTo(LastOpenedPage, true);
//}
}
}
}
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>6.16.2312.1315</Version>
<Version>6.16.2312.1317</Version>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>MP_TAB_SERV</RootNamespace>
</PropertyGroup>
+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();
}
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MAPOSPEC </i>
<h4>Versione: 6.16.2312.1315</h4>
<h4>Versione: 6.16.2312.1317</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
6.16.2312.1315
6.16.2312.1317
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.16.2312.1315</version>
<version>6.16.2312.1317</version>
<url>https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/MP-TAB-SERV.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+6 -2
View File
@@ -94,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()
{
@@ -110,7 +111,7 @@ 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, true);
@@ -127,7 +128,7 @@ 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, true);
@@ -149,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; }
}
}
+33 -8
View File
@@ -251,8 +251,9 @@ 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);
//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,17 +265,17 @@ 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 SetCurrOperDtoLSAsync(hash);
if (saveOpr)
{
await TDService.OperatoreSetRedis(rigaOpr.MatrOpr, hash);
await TDService.OperatoreSetRedis(rigaOpr.MatrOpr, hash, devGuid);
}
answ = true;
}
@@ -287,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;
@@ -426,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);