Update metodi REST x gestione Enroll
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using EgwControlCenter.Core.DTO;
|
||||
using DeviceId;
|
||||
using EgwControlCenter.Core.DTO;
|
||||
using EgwControlCenter.Core.Models;
|
||||
using EgwCoreLib.Utils;
|
||||
using Newtonsoft.Json;
|
||||
@@ -79,14 +80,90 @@ namespace EgwControlCenter.Core
|
||||
private Random rnd = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce un codice di auth temporaneo da autorizzare
|
||||
/// Restituisce un codice di auth temporaneo INT da impiegare x autorizzare
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetAuthPassocde()
|
||||
public async Task<int> GetAuthPassocde()
|
||||
{
|
||||
// fixme todo !!! implementare da lettura remota oppure gen locale...
|
||||
int tempCode = rnd.Next(10000000, 99999999);
|
||||
return tempCode;
|
||||
int tVal = 0;
|
||||
//verifico che NON ci sia una richiesta già in corso...
|
||||
if (CurrEnrollData.IdReq == 0)
|
||||
{
|
||||
// in primis preparo dizionario dei dati da allegare alla richiesta
|
||||
Dictionary<string, string> reqInfo = new Dictionary<string, string>();
|
||||
// preparo dati DeviceId da allegare in coda
|
||||
string deviceId = new DeviceIdBuilder()
|
||||
.AddMachineName()
|
||||
.AddUserName()
|
||||
.AddOsVersion()
|
||||
.OnWindows(windows => windows
|
||||
.AddMacAddressFromWmi(excludeWireless: true, excludeNonPhysical: true)
|
||||
.AddProcessorId()
|
||||
.AddMotherboardSerialNumber()
|
||||
.AddSystemDriveSerialNumber())
|
||||
.ToString();
|
||||
// aggiungo dati MachineInfo...
|
||||
reqInfo = MachineDataValidator.userInfo;
|
||||
foreach (var item in MachineDataValidator.netInfo)
|
||||
{
|
||||
if (!reqInfo.ContainsKey(item.Key))
|
||||
{
|
||||
reqInfo.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
// raggiungo DevideID
|
||||
reqInfo.Add("DeviceID", deviceId);
|
||||
|
||||
// faccio la chiamata rest e salvo risposta...
|
||||
CurrEnrollData = await CurrCheck.GetNewEnroll(reqInfo);
|
||||
}
|
||||
|
||||
// risposta valida se trovo un id richeista > 0...
|
||||
if (CurrEnrollData.IdReq > 0)
|
||||
{
|
||||
tVal = CurrEnrollData.Passcode;
|
||||
}
|
||||
return tVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se sia stato assegnato il codice licenza x una richiesta di enroll e nel caso recupera licenza e restituisce il codice da salvare in conf
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<string> CheckAssignIdxLic()
|
||||
{
|
||||
string tVal = "";
|
||||
// verifico dati richeista enroll, altrimenti faccio refresh richiesta...
|
||||
if (CurrEnrollData.IdReq == 0)
|
||||
{
|
||||
int newCode = await GetAuthPassocde();
|
||||
}
|
||||
// recupero info
|
||||
EnrollRequestDTO updRec = await CurrCheck.CheckCurrEnroll();
|
||||
if (updRec.IdReq > 0)
|
||||
{
|
||||
CurrEnrollData = updRec;
|
||||
// se la licenza è valida --> procedo!
|
||||
if( updRec.IdxLic>0)
|
||||
{
|
||||
LicenzaDTO currLic = await CurrCheck.GetEnrollLic();
|
||||
// se licenza valida --> restituisco e salvo!
|
||||
if(currLic.IsValid && currLic.IsActive)
|
||||
{
|
||||
tVal = currLic.Chiave;
|
||||
}
|
||||
}
|
||||
}
|
||||
return tVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Richiesta enroll corrente (se presente come file oppure nuova...)
|
||||
/// </summary>
|
||||
private EnrollRequestDTO CurrEnrollData
|
||||
{
|
||||
get => CurrCheck.CurrEnrollData;
|
||||
set => CurrCheck.CurrEnrollData = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user