using MapoDb; using SteamWare; using SteamWare.Logger; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace MP_MAG.WebUserControls { public partial class mod_enrollByAuthKey : System.Web.UI.UserControl { #region Internal Fields /// /// Oggetto datalayer specifico /// internal DataLayer DataLayerObj = new DataLayer(); #endregion Internal Fields #region Private Methods /// /// prova a fare enroll device data chiave... /// /// /// /// /// /// /// /// private bool tryEnroll(int MatrOpr, string userAgent, bool fatto, string DeviceName, string IPv4, string userKey) { try { fatto = DataLayerObj.enrollDevice(userKey, IPv4, DeviceName, userAgent, MatrOpr); } catch (Exception exc) { Logging.Instance.Info($"Errore in registrazione nuovo device con AuthKey utente: {Environment.NewLine}{exc}", tipoLog.EXCEPTION); } return fatto; } #endregion Private Methods #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) { bool fatto = false; // controllo se ho i dati... string plainUserAuthKey = txtUserAuthKey.Text.Trim(); // in primis cerco il dipendente data la authKey... int MatrOpr = 0; try { MatrOpr = Convert.ToInt32(ddlIdxDipendente.SelectedValue); } catch { } try { // controllo dipendente... che sia selezionato uno valido if (MatrOpr > 0) { // recupero dati... string userAgent = ""; string DeviceName = ""; string IPv4 = ""; userAgent = Request.UserAgent; DeviceName = Request.UserHostName; IPv4 = Request.UserHostName; // calcolo authKey MD5... string md5UserAuthKey = SteamCrypto.EncryptString(plainUserAuthKey, memLayer.ML.CRS("cookieName")); if (DataLayerObj.taOp.getByMatrAuthKey(MatrOpr, md5UserAuthKey).Rows.Count > 0) { fatto = tryEnroll(MatrOpr, userAgent, fatto, DeviceName, IPv4, md5UserAuthKey); } // provo con "plainUserKey" else if (DataLayerObj.taOp.getByMatrAuthKey(MatrOpr, plainUserAuthKey).Rows.Count > 0) { fatto = tryEnroll(MatrOpr, userAgent, fatto, DeviceName, IPv4, plainUserAuthKey); } 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) { Logging.Instance.Info($"Errore in registrazione device: {Environment.NewLine}{exc}", tipoLog.EXCEPTION); } if (fatto) { Response.Redirect(memLayer.ML.CRS("mainPageMag"), true); } } protected void Page_Load(object sender, EventArgs e) { } #endregion Protected Methods } }