using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using SteamWare; using GPW_data; namespace GPW.WebUserControls { public partial class mod_enrollByAuthKey : System.Web.UI.UserControl { #region Protected Methods /// /// resetto tutto /// /// /// protected void btnAnnulla_Click(object sender, EventArgs e) { txtUserAuthKey.Text = ""; } /// /// salvo nuovo device... /// /// /// protected void btnConferma_Click(object sender, EventArgs e) { // controllo se ho i dati... string plainUserAuthKey = txtUserAuthKey.Text.Trim(); // in primis cerco il dipendente data la authKey... int idxDipendente = 0; try { idxDipendente = Convert.ToInt32(ddlIdxDipendente.SelectedValue); } catch { } try { // controllo dipendente... che sia selezionato uno valido if (idxDipendente > 0) { // dichiarazione variabili string userAgent = ""; bool fatto = false; string DeviceName = ""; string IPv4 = ""; string md5UserAuthKey = ""; int trovate = 0; try { // recupero dati da session userAgent = Request.UserAgent; DeviceName = Request.UserHostName; IPv4 = Request.UserHostName; } catch { logger.lg.scriviLog("Errore recupero dati da sessione x user, device, IP", tipoLog.ERROR); } // calcolo authKey... cerco se ne trovo x utente encrypted o unencrypted md5UserAuthKey = SteamCrypto.EncryptString(plainUserAuthKey, "AuthGPW"); logger.lg.scriviLog(string.Format("Richiesta auth smart device per idxDipendente {0} con key MD5 {1}", idxDipendente, md5UserAuthKey), tipoLog.INFO); int trovatePlain = 0; int trovateMd5 = 0; try { trovateMd5 = DataProxy.DP.taDipendenti.getByAuthKey(idxDipendente, md5UserAuthKey).Rows.Count; trovatePlain = DataProxy.DP.taDipendenti.getByAuthKey(idxDipendente, plainUserAuthKey).Rows.Count; trovate = trovatePlain + trovateMd5; } catch { logger.lg.scriviLog("Errore ricerca key in chiaro/MD5 x utente", tipoLog.ERROR); } if (trovate > 0) { try { if (trovateMd5 > 0) { // salvo cognomeNome fatto = DataProxy.DP.enrollDevice(md5UserAuthKey, IPv4, DeviceName, userAgent, idxDipendente); } else if (trovatePlain > 0) { fatto = DataProxy.DP.enrollDevice(plainUserAuthKey, IPv4, DeviceName, userAgent, idxDipendente); } if (fatto) { string CognomeNome = "USER ND"; try { DS_Applicazione.DipendentiRow rigaDip = DataProxy.DP.getRowDip(idxDipendente); CognomeNome = $"{rigaDip.Cognome} {rigaDip.Nome} [{idxDipendente}]"; } catch { } memLayer.ML.setSessionVal("cognomeNome", CognomeNome); Response.Redirect("~/Timbrature.aspx"); } else { } } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in registrazione nuovo device con AuthKey CIFRATA x utente: {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); } } else { lblWarning.Text = "AuthKey non trovata! richiedere reset ad Admin."; lblWarning.Visible = true; } } else { lblWarning.Text = "Dipendente non trovato!"; lblWarning.Visible = true; } } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in registrazione device: {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); } } protected void Page_Load(object sender, EventArgs e) { } #endregion Protected Methods } }