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 { protected void Page_Load(object sender, EventArgs e) { } /// /// 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); try { trovate = DataProxy.DP.taDipendenti.getByAuthKey(idxDipendente, md5UserAuthKey).Rows.Count + DataProxy.DP.taDipendenti.getByAuthKey(idxDipendente, plainUserAuthKey).Rows.Count; } catch { logger.lg.scriviLog("Errore ricerca key in chiaro/MD5 x utente", tipoLog.ERROR); } if (trovate > 0) { try { fatto = DataProxy.DP.enrollDevice(md5UserAuthKey, IPv4, DeviceName, userAgent, idxDipendente); if (fatto) { Response.Redirect("~/Timbrature.aspx"); } } 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); } } /// /// resetto tutto /// /// /// protected void btnAnnulla_Click(object sender, EventArgs e) { txtUserAuthKey.Text = ""; } } }