Update login con jumper OK...
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace GPW.CORE.Comp
|
||||
{
|
||||
/// <summary>
|
||||
/// utils x cifrature e Crypto
|
||||
/// </summary>
|
||||
public class SteamCrypto
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// decifra un messaggio con una password
|
||||
/// </summary>
|
||||
/// <param name="Message"></param>
|
||||
/// <param name="Passphrase"></param>
|
||||
/// <returns></returns>
|
||||
public static string DecryptString(string Message, string Passphrase)
|
||||
{
|
||||
string answ = Message;
|
||||
byte[] Results = new byte[8];
|
||||
UTF8Encoding UTF8 = new UTF8Encoding();
|
||||
|
||||
// Step 1. We hash the passphrase using MD5 We use the MD5 hash generator as the result
|
||||
// is a 128 bit byte array which is a valid length for the TripleDES encoder we use below
|
||||
|
||||
var HashProvider = MD5.Create();
|
||||
//MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
|
||||
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
|
||||
|
||||
// Step 2. Create a new TripleDESCryptoServiceProvider object
|
||||
var TDESAlgorithm = TripleDES.Create();
|
||||
//TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
|
||||
|
||||
// Step 3. Setup the decoder
|
||||
TDESAlgorithm.Key = TDESKey;
|
||||
TDESAlgorithm.Mode = CipherMode.ECB;
|
||||
TDESAlgorithm.Padding = PaddingMode.PKCS7;
|
||||
|
||||
// Step 4. Convert the input string to a byte[]
|
||||
byte[] DataToDecrypt = new byte[8];
|
||||
try
|
||||
{
|
||||
DataToDecrypt = Convert.FromBase64String(Message);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
if (DataToDecrypt != null)
|
||||
{
|
||||
// Step 5. Attempt to decrypt the string
|
||||
try
|
||||
{
|
||||
ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
|
||||
Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clear the TripleDes and Hashprovider services of any sensitive information
|
||||
TDESAlgorithm.Clear();
|
||||
HashProvider.Clear();
|
||||
}
|
||||
// Step 6. Return the decrypted string in UTF8 format
|
||||
answ = UTF8.GetString(Results);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// cifra un messaggio con una password
|
||||
/// </summary>
|
||||
/// <param name="Message"></param>
|
||||
/// <param name="Passphrase"></param>
|
||||
/// <returns></returns>
|
||||
public static string EncryptString(string Message, string Passphrase)
|
||||
{
|
||||
byte[] Results;
|
||||
UTF8Encoding UTF8 = new UTF8Encoding();
|
||||
|
||||
// Step 1. We hash the passphrase using MD5 We use the MD5 hash generator as the result
|
||||
// is a 128 bit byte array which is a valid length for the TripleDES encoder we use below
|
||||
|
||||
var HashProvider = MD5.Create();
|
||||
//MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
|
||||
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
|
||||
|
||||
// Step 2. Create a new TripleDESCryptoServiceProvider object
|
||||
var TDESAlgorithm = TripleDES.Create();
|
||||
//TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
|
||||
|
||||
// Step 3. Setup the encoder
|
||||
TDESAlgorithm.Key = TDESKey;
|
||||
TDESAlgorithm.Mode = CipherMode.ECB;
|
||||
TDESAlgorithm.Padding = PaddingMode.PKCS7;
|
||||
|
||||
// Step 4. Convert the input string to a byte[]
|
||||
byte[] DataToEncrypt = UTF8.GetBytes(Message);
|
||||
|
||||
// Step 5. Attempt to encrypt the string
|
||||
try
|
||||
{
|
||||
ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();
|
||||
Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clear the TripleDes and Hashprovider services of any sensitive information
|
||||
TDESAlgorithm.Clear();
|
||||
HashProvider.Clear();
|
||||
}
|
||||
|
||||
// Step 6. Return the encrypted string as a base64 encoded string
|
||||
return Convert.ToBase64String(Results);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// genera hash di una stringa in MD5 (es x hash gravatar)
|
||||
/// </summary>
|
||||
/// <param name="Message"></param>
|
||||
/// <returns></returns>
|
||||
public static string getHashStringMD5(string Message)
|
||||
{
|
||||
string hash = "";
|
||||
using (MD5 md5Hash = MD5.Create())
|
||||
{
|
||||
hash = GetMd5Hash(md5Hash, Message);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crea un hash MD5
|
||||
/// </summary>
|
||||
/// <param name="md5Hash"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMd5Hash(MD5 md5Hash, string input)
|
||||
{
|
||||
// Convert the input string to a byte array and compute the hash.
|
||||
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
|
||||
|
||||
// Create a new Stringbuilder to collect the bytes and create a string.
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
|
||||
// Loop through each byte of the hashed data and format each one as a hexadecimal string.
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
sBuilder.Append(data[i].ToString("x2"));
|
||||
}
|
||||
|
||||
// Return the hexadecimal string.
|
||||
return sBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a random string with a given size
|
||||
/// </summary>
|
||||
/// <param name="size"></param>
|
||||
/// <param name="lowerCase"></param>
|
||||
/// <returns></returns>
|
||||
public static string RandomString(int size, bool lowerCase = false)
|
||||
{
|
||||
var builder = new StringBuilder(size);
|
||||
|
||||
// Unicode/ASCII Letters are divided into two blocks (Letters 65–90 / 97–122): The first
|
||||
// group containing the uppercase letters and the second group containing the lowercase.
|
||||
|
||||
// char is a single Unicode character
|
||||
char offset = lowerCase ? 'a' : 'A';
|
||||
const int lettersOffset = 26; // A...Z or a..z: length=26
|
||||
|
||||
for (var i = 0; i < size; i++)
|
||||
{
|
||||
var @char = (char)_random.Next(offset, offset + lettersOffset);
|
||||
builder.Append(@char);
|
||||
}
|
||||
|
||||
return lowerCase ? builder.ToString().ToLower() : builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify a hash against a string.
|
||||
/// </summary>
|
||||
/// <param name="md5Hash"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="hash"></param>
|
||||
/// <returns></returns>
|
||||
public static bool VerifyMd5Hash(MD5 md5Hash, string input, string hash)
|
||||
{
|
||||
// Hash the input.
|
||||
string hashOfInput = GetMd5Hash(md5Hash, input);
|
||||
|
||||
// Create a StringComparer an compare the hashes.
|
||||
StringComparer comparer = StringComparer.OrdinalIgnoreCase;
|
||||
|
||||
if (0 == comparer.Compare(hashOfInput, hash))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static readonly Random _random = new Random();
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace GPW.CORE.Data.DbModels
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
[Table("AnagDevice")]
|
||||
[Table("AnagDevices")]
|
||||
public partial class AnagDeviceModel
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
|
||||
@@ -26,12 +26,14 @@ namespace GPW.CORE.Smart.Components
|
||||
protected IJSRuntime JSRuntime { get; set; } = null!;
|
||||
[Inject]
|
||||
protected MessageService MService { get; set; } = null!;
|
||||
[Inject]
|
||||
protected CoreSmartDataService CDService { get; set; } = null!;
|
||||
|
||||
protected AnagDeviceModel registeredDevice { get; set; } = new AnagDeviceModel();
|
||||
protected DipendentiModel registeredUser { get; set; } = new DipendentiModel();
|
||||
//protected AnagDeviceModel registeredDevice { get; set; } = new AnagDeviceModel();
|
||||
//protected DipendentiModel registeredUser { get; set; } = new DipendentiModel();
|
||||
|
||||
protected string currIp { get; set; } = "";
|
||||
protected string deviceSecret { get; set; } = "";
|
||||
//protected string currIp { get; set; } = "";
|
||||
//protected string deviceSecret { get; set; } = "";
|
||||
protected string Nome { get; set; } = "";
|
||||
protected string Cognome { get; set; } = "";
|
||||
protected int idxDipendente { get; set; } = 0;
|
||||
@@ -41,26 +43,105 @@ namespace GPW.CORE.Smart.Components
|
||||
}
|
||||
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstrender = false)
|
||||
protected override async Task OnAfterRenderAsync(bool firstrender)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
if (MService.RigaDip != null)
|
||||
{
|
||||
Nome = MService.RigaDip.Nome;
|
||||
Cognome = MService.RigaDip.Cognome;
|
||||
idxDipendente = MService.RigaDip.IdxDipendente;
|
||||
}
|
||||
if (MService.RigaDip != null)
|
||||
{
|
||||
navManager.NavigateTo("/", true);
|
||||
}
|
||||
else
|
||||
if (firstrender)
|
||||
{
|
||||
if (!navManager.Uri.Contains("jumper"))
|
||||
{
|
||||
navManager.NavigateTo("jumper", true);
|
||||
await checkUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica dati utente e pagina
|
||||
/// </summary>
|
||||
private async Task checkUser()
|
||||
{
|
||||
// se idxDip NON valido
|
||||
if (MService.IdxDipendente <= 0)
|
||||
{
|
||||
await tryDeviceLogin();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (idxDipendente <= 0)
|
||||
{
|
||||
setupUserData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupUserData()
|
||||
{
|
||||
if (MService.RigaDip != null && MService.IdxDipendente > 0)
|
||||
{
|
||||
idxDipendente = MService.IdxDipendente;
|
||||
Cognome = MService.RigaDip.Cognome;
|
||||
Nome = MService.RigaDip.Nome;
|
||||
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);
|
||||
MService.RigaDip = rigaDip;
|
||||
// salvo in sessStorage idxDip...
|
||||
await MService.setIdxDipAsync(rigaDev.IdxDipendente);
|
||||
setupUserData();
|
||||
//navManager.NavigateTo("/", false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
navManager.NavigateTo("RegNewDevice");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
navManager.NavigateTo("RegNewDevice");
|
||||
}
|
||||
//if (MService.RigaDip != null)
|
||||
//{
|
||||
// Nome = MService.RigaDip.Nome;
|
||||
// Cognome = MService.RigaDip.Cognome;
|
||||
// idxDipendente = MService.RigaDip.IdxDipendente;
|
||||
//}
|
||||
//if (MService.RigaDip != null)
|
||||
//{
|
||||
// navManager.NavigateTo("/", true);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (!navManager.Uri.Contains("jumper"))
|
||||
// {
|
||||
// navManager.NavigateTo("jumper", true);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using GPW.CORE.Data.DbModels;
|
||||
using GPW.CORE.Comp;
|
||||
using GPW.CORE.Data.DbModels;
|
||||
using GPW.CORE.Data.DTO;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
@@ -110,8 +111,6 @@ namespace GPW.CORE.Smart.Data
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
List<DipendentiModel>? dbResult = new List<DipendentiModel>();
|
||||
|
||||
|
||||
string? rawData = await redisDb.StringGetAsync(rKeyDipendenti);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
@@ -136,11 +135,42 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<DipendentiModel>();
|
||||
}
|
||||
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"DipendentiGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<AnagDeviceModel?> DeviceBySecret(string devSecret)
|
||||
{
|
||||
string source = "DB";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
AnagDeviceModel? dbResult = new AnagDeviceModel();
|
||||
dbResult = dbController.AnagDeviceByKey(devSecret);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"DeviceBySecret | {source} in: {ts.TotalMilliseconds} ms");
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crea un record device
|
||||
/// </summary>
|
||||
/// <param name="newRecord"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DeviceInsert(AnagDeviceModel newRecord)
|
||||
{
|
||||
string source = "DB";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
bool fatto = dbController.AnagDeviceInsert(newRecord);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"DeviceInsert | {source} in: {ts.TotalMilliseconds} ms");
|
||||
await Task.Delay(1);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -161,6 +191,17 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbController.rollBackEntity(item);
|
||||
}
|
||||
public string EncriptData(string rawData)
|
||||
{
|
||||
return SteamCrypto.EncryptString(rawData, passPhrase);
|
||||
}
|
||||
|
||||
public string DeriptData(string encData)
|
||||
{
|
||||
return SteamCrypto.DecryptString(encData, passPhrase);
|
||||
}
|
||||
|
||||
protected const string passPhrase = "EB6BD8BE-638F-481E-85E4-F89012DA95BB";
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -265,8 +306,6 @@ namespace GPW.CORE.Smart.Data
|
||||
|
||||
private readonly IEmailSender _emailSender;
|
||||
|
||||
private readonly IMemoryCache memoryCache;
|
||||
|
||||
private List<string> cachedDataList = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
@@ -332,8 +371,6 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
// brutalmente rimuovo intero contenuto DB... DANGER
|
||||
//await server.FlushDatabaseAsync();
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
@@ -377,7 +414,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<AnagKeyValueModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -412,7 +449,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<AnagClientiModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -447,7 +484,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<AnagFasiModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -479,7 +516,7 @@ namespace GPW.CORE.Smart.Data
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB + caching per AnagFasiSearch: {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -512,7 +549,7 @@ namespace GPW.CORE.Smart.Data
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB + caching per AnagFasiByProj: {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
/// <summary>
|
||||
/// Elenco Giustificativi
|
||||
@@ -543,7 +580,7 @@ namespace GPW.CORE.Smart.Data
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB + caching per AnagGiust: {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
/// <summary>
|
||||
/// Recupera l'elenco gruppi abilitati x il dipendente
|
||||
@@ -578,7 +615,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<AnagGruppiModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -614,7 +651,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new AnagOrariModel();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -649,7 +686,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<AnagProgettiModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -669,7 +706,7 @@ namespace GPW.CORE.Smart.Data
|
||||
}
|
||||
}
|
||||
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -706,7 +743,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new CalcOreFasiModel();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -743,7 +780,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new CalcOreProgettiModel();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -780,7 +817,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<CalFesteFerieModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -819,7 +856,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<CheckVc19Model>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -856,7 +893,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<ConfigModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -960,7 +997,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<CORE.Data.DTO.WeekStatDTO>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1001,7 +1038,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<ParetoRegAttModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<bool> RegAttDelete(RegAttivitaModel currItem)
|
||||
@@ -1028,7 +1065,7 @@ namespace GPW.CORE.Smart.Data
|
||||
public async Task<RegAttivitaModel> RegAttLastByDip(int IdxDipendente, bool onlyActive)
|
||||
{
|
||||
RegAttivitaModel dbResult = dbController.RegAttLastByDip(IdxDipendente, onlyActive);
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<bool> RegAttUpdate(RegAttivitaModel currItem)
|
||||
@@ -1121,7 +1158,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<RegMalattieModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
/// <summary>
|
||||
/// Restituisce elenco malattie globali
|
||||
@@ -1156,7 +1193,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<RegMalattieModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1280,7 +1317,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<RegRichiesteModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1364,7 +1401,7 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
dbResult = new List<RilievoTempModel>();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<bool> RilTempUpdate(RilievoTempModel currItem)
|
||||
@@ -1400,7 +1437,7 @@ namespace GPW.CORE.Smart.Data
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB + caching per TimbratureDay: {ts.TotalMilliseconds} ms");
|
||||
return await Task.FromResult(dbResult);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<bool> TimbratureDelete(TimbratureModel currItem)
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
using GPW.CORE.Data;
|
||||
using Blazored.LocalStorage;
|
||||
using Blazored.SessionStorage;
|
||||
using GPW.CORE.Data;
|
||||
using GPW.CORE.Data.DbModels;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Session;
|
||||
using Org.BouncyCastle.Asn1;
|
||||
|
||||
namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
public class MessageService
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private string _pageIcon = "";
|
||||
|
||||
private string _pageName = "";
|
||||
|
||||
private DipendentiModel? _rigaDip;
|
||||
private string _searchVal = "";
|
||||
private bool showSearch;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Fields
|
||||
|
||||
public int orarioDip = 0;
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MessageService(ILocalStorageService genLocalStorage, ISessionStorageService sessStore)
|
||||
{
|
||||
localStorage = genLocalStorage;
|
||||
sessionStore = sessStore;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Events
|
||||
|
||||
public event Action EA_HideSearch = null!;
|
||||
@@ -108,7 +108,6 @@ namespace GPW.CORE.Smart.Data
|
||||
}
|
||||
|
||||
public bool PayloadOk { get; set; } = false;
|
||||
|
||||
public RegAttivitaModel? recordRA { get; set; } = null;
|
||||
|
||||
public DipendentiModel? RigaDip
|
||||
@@ -118,8 +117,8 @@ namespace GPW.CORE.Smart.Data
|
||||
{
|
||||
if (_rigaDip != value)
|
||||
{
|
||||
// salvo
|
||||
_rigaDip = value;
|
||||
|
||||
if (EA_SearchUpdated != null)
|
||||
{
|
||||
EA_SearchUpdated?.Invoke();
|
||||
@@ -146,7 +145,6 @@ namespace GPW.CORE.Smart.Data
|
||||
}
|
||||
|
||||
public int selWeekNum { get; set; } = 0;
|
||||
|
||||
public int selYear { get; set; } = DateTime.Today.Year;
|
||||
|
||||
public bool ShowSearch
|
||||
@@ -179,6 +177,88 @@ namespace GPW.CORE.Smart.Data
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore di DeviceSecret da localstorage
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<string> getDevSecretAsync()
|
||||
{
|
||||
string answ = "";
|
||||
var result = await localStorage.GetItemAsync<string>("DevSec");
|
||||
if (result != null)
|
||||
{
|
||||
answ = result;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrive il valore di DeviceSecret nel localstoragee
|
||||
/// </summary>
|
||||
/// <param name="devSec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> setDevSecretAsync(string devSec)
|
||||
{
|
||||
bool answ = false;
|
||||
await localStorage.SetItemAsync("DevSec", devSec);
|
||||
answ = true;
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore di idxDip da localstorage
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<int> getIdxDipAsync()
|
||||
{
|
||||
int answ = -2;
|
||||
var result = await sessionStore.GetItemAsync<int>("idxDip");
|
||||
if (result != null)
|
||||
{
|
||||
answ = result;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrive il valore di idxDip nel localstoragee
|
||||
/// </summary>
|
||||
/// <param name="devSec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> setIdxDipAsync(int idxDip)
|
||||
{
|
||||
bool answ = false;
|
||||
await sessionStore.SetItemAsync("idxDip", idxDip);
|
||||
answ = true;
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected ILocalStorageService localStorage { get; set; } = null!;
|
||||
protected ISessionStorageService sessionStore { get; set; } = null!;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private string _pageIcon = "";
|
||||
|
||||
private string _pageName = "";
|
||||
|
||||
private DipendentiModel? _rigaDip;
|
||||
private string _searchVal = "";
|
||||
private bool showSearch;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void ReportPageUpd()
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Blazored.LocalStorage" Version="4.2.0" />
|
||||
<PackageReference Include="Blazored.SessionStorage" Version="2.3.0" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.6.86" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
@page "/CheckDevice"
|
||||
|
||||
<h3>CheckDevice</h3>
|
||||
|
||||
@code {
|
||||
|
||||
}
|
||||
@@ -18,6 +18,8 @@ using Blazored.LocalStorage;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using GPW.CORE.Smart.Data;
|
||||
using GPW.CORE.Data.DbModels;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using System.Net;
|
||||
|
||||
namespace GPW.CORE.Smart.Pages
|
||||
{
|
||||
@@ -40,10 +42,27 @@ namespace GPW.CORE.Smart.Pages
|
||||
protected List<DipendentiModel>? currDipList;
|
||||
protected DipendentiModel? currDip;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await Task.Delay(50);
|
||||
if (firstRender)
|
||||
{
|
||||
await tryUrlLogin();
|
||||
}
|
||||
}
|
||||
|
||||
private Random rnd = new Random();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Prova login da dati URL
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task tryUrlLogin()
|
||||
{
|
||||
//MService.RigaDip = null;
|
||||
var uri = navManager.ToAbsoluteUri(navManager.Uri);
|
||||
await Task.Delay(1);
|
||||
// recupero da URL
|
||||
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("idxDipendente", out var _idxDipendente))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_idxDipendente))
|
||||
@@ -58,17 +77,58 @@ namespace GPW.CORE.Smart.Pages
|
||||
authKey = _authKey;
|
||||
}
|
||||
}
|
||||
|
||||
string devName = "";
|
||||
DateTime adesso = DateTime.Now;
|
||||
string dtData = $"{DateTime.UtcNow:yyyy-MM-dd_ZHH:mm:ss}";
|
||||
string devAgent = await JSRuntime.InvokeAsync<string>("getUserAgent");
|
||||
var dimension = await JSRuntime.InvokeAsync<WindowDimension>("getWindowDimensions");
|
||||
string screenSize = $"{dimension.Width}x{dimension.Height}";
|
||||
string devIp = $"";
|
||||
string randData = SteamCrypto.RandomString(32, true);
|
||||
currDipList = await CDService.DipendentiGetAll();
|
||||
currDip = currDipList.Where(x => x.IdxDipendente == idxDipendente && x.AuthKey == authKey).FirstOrDefault();
|
||||
|
||||
MService.RigaDip = currDip;
|
||||
|
||||
if (currDip != null)
|
||||
{
|
||||
navManager.NavigateTo(navManager.Uri, true);
|
||||
}
|
||||
// verifico authKey...
|
||||
if (currDip.AuthKey == authKey)
|
||||
{
|
||||
// creo la DeviceSecret
|
||||
string devSec = CDService.EncriptData($"{dtData}|{idxDipendente}|{devName}|{randData}");
|
||||
// ...e la salvo sul DB
|
||||
AnagDeviceModel newDev = new AnagDeviceModel()
|
||||
{
|
||||
IdxDipendente = idxDipendente,
|
||||
DeviceSecret = devSec,
|
||||
DataOraEnabled = adesso,
|
||||
DataOraLastSeen = adesso,
|
||||
ScreenSize = screenSize,
|
||||
DeviceName = devName,
|
||||
Description = devAgent,
|
||||
LastIpv4 = devIp
|
||||
};
|
||||
bool fatto = await CDService.DeviceInsert(newDev);
|
||||
if (fatto)
|
||||
{
|
||||
// ...e nel browser tramite message service
|
||||
await MService.setDevSecretAsync(devSec);
|
||||
await MService.setIdxDipAsync(idxDipendente);
|
||||
|
||||
// infine salvo dati dipendente e rimando a login
|
||||
MService.RigaDip = currDip;
|
||||
navManager.NavigateTo("/", true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
navManager.NavigateTo("RegNewDevice");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class WindowDimension
|
||||
{
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
@page "/RegNewDevice"
|
||||
|
||||
<h3>RegNewDevice</h3>
|
||||
|
||||
Pagina x richiesta registrazione nuovo device
|
||||
|
||||
<p>
|
||||
opzione x inviare email (data lista dipendenti) - solo x admin?
|
||||
</p>
|
||||
|
||||
<p>
|
||||
opzione SOLO X ADMIN x resettare authKey dip + inviare email (data lista dipendenti)
|
||||
</p>
|
||||
<p>
|
||||
istruzioni x uso pagina jumper
|
||||
</p>
|
||||
|
||||
@code {
|
||||
|
||||
}
|
||||
@@ -28,6 +28,8 @@
|
||||
<a class="dismiss">🗙</a>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="~/lib/WindowSize.js"></script>
|
||||
<script type="text/javascript" src="~/lib/UserAgent.js"></script>
|
||||
<script src="_framework/blazor.server.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using GPW.CORE.Data;
|
||||
using Blazored.LocalStorage;
|
||||
using Blazored.SessionStorage;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -37,6 +38,7 @@ builder.Services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
||||
builder.Services.AddScoped<MessageService>();
|
||||
|
||||
builder.Services.AddBlazoredLocalStorage();
|
||||
builder.Services.AddBlazoredSessionStorage();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
window.getUserAgent = () => {
|
||||
return navigator.userAgent;
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
window.getWindowDimensions = function () {
|
||||
return {
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user