b830d7a54e
- update modal wait - update deploy - check attivazioni + frequente
369 lines
11 KiB
C#
369 lines
11 KiB
C#
using EgwCoreLib.Razor.Data;
|
|
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Smart8.Components.Pages;
|
|
using GPW.CORE.Smart8.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Http;
|
|
using NLog;
|
|
|
|
namespace GPW.CORE.Smart8.Components.Layout
|
|
{
|
|
public partial class MainLayout
|
|
{
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected CoreSmartDataService CDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IConfiguration configuration { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected LicenseService LicServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MessageService MService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavMan { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Verifica informazioni condivise applicazione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task<bool> checkActivations()
|
|
{
|
|
bool allOk = false;
|
|
if (LicServ.ValidData)
|
|
{
|
|
// se non fosse tutto ok
|
|
if (!LicServ.HasActivData)
|
|
{
|
|
// chiamo refresh licenze da remoto
|
|
allOk = await LicServ.RefreshLicense();
|
|
}
|
|
// se non avesse info applicativo...
|
|
if (!LicServ.HasAppData)
|
|
{
|
|
await LicServ.RefreshApplic();
|
|
}
|
|
}
|
|
|
|
await Task.Delay(1);
|
|
return allOk;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica informazioni condivise applicazione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task<bool> checkSharedInfo()
|
|
{
|
|
bool allOk = false;
|
|
if (!LicServ.ValidData)
|
|
{
|
|
// salvo cod app da Conf...
|
|
LicServ.Applicazione = CDService.CodApp;
|
|
// effettuo lettura dati preliminari da AKV (eventualmente in cache...)
|
|
List<AnagKeyValueModel>? rawAkvList = await CDService.AKVList();
|
|
if (rawAkvList != null)
|
|
{
|
|
LicServ.AKVList = rawAkvList;
|
|
allOk = LicServ.InitAkv();
|
|
}
|
|
}
|
|
|
|
await Task.Delay(1);
|
|
return allOk;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica info specifiche utente
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task<bool> checkUserLicense()
|
|
{
|
|
bool answ = false;
|
|
// verifico utente attivo
|
|
answ = MService.IsActive;
|
|
if (answ)
|
|
{
|
|
var rawActList = LicServ.ActivList;
|
|
// recupero hash utente
|
|
string hashImpiego = MService.HashDip;
|
|
// confronto con elenco attivazioni dello shared service...
|
|
var foundRec = rawActList.Where(x => x.CodImpiego == hashImpiego);
|
|
answ = foundRec.Count() > 0;
|
|
// salvo status payloadOk
|
|
MService.PayloadOk = answ;
|
|
}
|
|
|
|
await Task.Delay(1);
|
|
return answ;
|
|
}
|
|
|
|
protected async Task DoVerifyActiv()
|
|
{
|
|
MService.PayloadOk = false;
|
|
await Task.Delay(1);
|
|
await VerifyActiv();
|
|
}
|
|
|
|
protected async Task ForceReset()
|
|
{
|
|
string nextPage = NavMan.ToBaseRelativePath(NavMan.Uri);
|
|
// tengo solo parte finale...
|
|
if (nextPage.Contains("/"))
|
|
{
|
|
nextPage = nextPage.Substring(nextPage.LastIndexOf("/") + 1);
|
|
}
|
|
await Task.Delay(1);
|
|
await DoVerifyActiv();
|
|
NavMan.NavigateTo($"{baseUrl}ForceReset?nextPage={nextPage}", true);
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstrender)
|
|
{
|
|
await Task.Delay(1);
|
|
if (firstrender)
|
|
{
|
|
if (!NavMan.Uri.Contains("jumper"))
|
|
{
|
|
await checkUser();
|
|
// verifico attivazione dipendente...
|
|
await checkUserLicense();
|
|
}
|
|
}
|
|
Log.Info($"MainLayout.OnAfterRenderAsync | firstrender: {firstrender}");
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await DoVerifyActiv();
|
|
string baseUrl = configuration.GetValue<string>("OptConf:BaseUrl") ?? "~/";
|
|
var versione = typeof(Program).Assembly.GetName().Version;
|
|
currConfig = new ConfigDTO()
|
|
{
|
|
BaseUrl = baseUrl,
|
|
Versione = $"{versione}"
|
|
};
|
|
|
|
await ReloadData();
|
|
#if false
|
|
if (!DipOk)
|
|
{
|
|
try
|
|
{
|
|
if (!NavMan.Uri.Contains("jumper"))
|
|
{
|
|
await checkUser();
|
|
// verifico attivazione dipendente...
|
|
await checkUserLicense();
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Info($"MainLayout | No user data: reloading{Environment.NewLine}{exc}");
|
|
await Task.Delay(1500);
|
|
NavMan.NavigateTo($"{baseUrl}Index");
|
|
}
|
|
}
|
|
#endif
|
|
Log.Info($"MainLayout.OnInitialized | url: {baseUrl} | v:{versione}");
|
|
}
|
|
|
|
protected async Task ReturnHome()
|
|
{
|
|
// svuoto cache
|
|
await CDService.FlushRedisCache();
|
|
// ritorno in home
|
|
NavMan.NavigateTo($"{currConfig.BaseUrl}Home", true);
|
|
}
|
|
|
|
protected async Task VerifyActiv()
|
|
{
|
|
// preliminarmente verifica shared info
|
|
await checkSharedInfo();
|
|
// refresh attivazioni se necessario
|
|
await checkActivations();
|
|
// verifico e salvo dati attivazione dipendente...
|
|
userOk = await checkUserLicense();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private ConfigDTO currConfig = new ConfigDTO();
|
|
private string currIpv4 = "";
|
|
|
|
/// <summary>
|
|
/// Info utente corrente x display
|
|
/// </summary>
|
|
private UserDTO? currUser = null;
|
|
|
|
private bool dataLoaded = false;
|
|
|
|
private string LocalNet = "10.74";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string baseUrl
|
|
{
|
|
get => configuration.GetValue<string>("OptConf:BaseUrl") ?? "~/";
|
|
}
|
|
|
|
private bool DipOk
|
|
{
|
|
get => (currUser != null && currUser.IdxDip > 0);
|
|
}
|
|
|
|
[Inject]
|
|
private IHttpContextAccessor httpContextAccessor { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Verifica se IP sia locale
|
|
/// </summary>
|
|
private bool isIpLocal
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
if (!string.IsNullOrEmpty(currIpv4))
|
|
{
|
|
answ = currIpv4.Contains(LocalNet);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private bool userOk { get; set; } = false;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task checkOtherData()
|
|
{
|
|
currIpv4 = await MService.getDevIpAsync();
|
|
if (string.IsNullOrEmpty(currIpv4))
|
|
{
|
|
// ricalcolo e salvo...
|
|
if (httpContextAccessor.HttpContext != null)
|
|
{
|
|
var remoteIp = $"{httpContextAccessor.HttpContext.Connection?.RemoteIpAddress}";
|
|
// provo a recuperare ipV4...
|
|
currIpv4 = IpUtils.getLocalIpv4(remoteIp);
|
|
await MService.setDevIpv4Async(currIpv4);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica dati utente e pagina
|
|
/// </summary>
|
|
private async Task checkUser()
|
|
{
|
|
dataLoaded = false;
|
|
// se idxDip NON valido
|
|
if (!DipOk)
|
|
{
|
|
await tryDeviceLogin();
|
|
// verifico se ho dipendente...
|
|
if (currUser != null && currUser.IdxDip > 0)
|
|
{
|
|
// segnalo update...
|
|
await setupUserData();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dataLoaded = true;
|
|
}
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
var confNet = await CDService.ConfigGetKey("LocalNet");
|
|
LocalNet = confNet != null ? confNet.valore : "10";
|
|
}
|
|
|
|
private async Task setupUserData()
|
|
{
|
|
if (DipOk)
|
|
{
|
|
// verifico o calcolo IP...
|
|
await checkOtherData();
|
|
|
|
Log.Info($"MainLayout.setupUserData | idxDip: {currUser.IdxDip}");
|
|
|
|
dataLoaded = true;
|
|
// segnalo update...
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prova login da dati Device (in LocalStorage)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task tryDeviceLogin()
|
|
{
|
|
// cerco in localstorage il devicesecret
|
|
string devSecret = await MService.getDevSecretAsync();
|
|
await Task.Delay(50);
|
|
if (!string.IsNullOrEmpty(devSecret))
|
|
{
|
|
// cerco sul DB...
|
|
var rigaDev = await CDService.DeviceBySecret(devSecret);
|
|
// se trovato
|
|
if (rigaDev != null)
|
|
{
|
|
// recupero dati dip e inizializzo message service
|
|
var elencoDip = await CDService.DipendentiGetAll();
|
|
if (elencoDip != null)
|
|
{
|
|
var rigaDip = elencoDip.FirstOrDefault(x => x.IdxDipendente == rigaDev.IdxDipendente);
|
|
if (rigaDip != null)
|
|
{
|
|
MService.RigaDip = rigaDip;
|
|
currUser = new UserDTO()
|
|
{
|
|
IdxDip = rigaDip.IdxDipendente,
|
|
Cognome = rigaDip.Cognome ?? "-",
|
|
Nome = rigaDip.Nome ?? "...",
|
|
Attivo = rigaDip.Attivo,
|
|
AuthKey = rigaDip.AuthKey,
|
|
Cf = rigaDip.Cf,
|
|
DataNascita = rigaDip.DataNascita,
|
|
Email = rigaDip.Email,
|
|
Gruppo = rigaDip.Gruppo,
|
|
Matricola = rigaDip.Matricola,
|
|
Dominio = rigaDip.Dominio,
|
|
Utente = rigaDip.Utente
|
|
};
|
|
await setupUserData();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NavMan.NavigateTo($"{baseUrl}RegNewDevice");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NavMan.NavigateTo($"{baseUrl}RegNewDevice");
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |