using SteamWare; using System; using System.Web; using System.Web.UI; namespace MoonProTablet.WebUserControls { public partial class mod_enrollByAuthKey : BaseUserControl { #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) { logger.lg.scriviLog(string.Format("Errore in registrazione nuovo device con AuthKey utente: {0}{1}", 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) { Page page = this.Page; bool fatto = false; // controllo se ho i dati... string plainUserAuthKey = txtUserAuthKey.Text.Trim(); // in primis cerco il dipendente data la authKey... int MatrOpr = 0; string generOpr = ""; 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) { logger.lg.scriviLog(string.Format("Errore in registrazione device: {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); } if (fatto) { try { generOpr = controllerMapo.getCognomeNomeDaMatr(MatrOpr); // registro login DataLayerObj.taDiarioDich.insertQuery("UserLogin", "", DateTime.Now, MatrOpr, $"Login: {generOpr}"); } catch { } Response.Redirect(memLayer.ML.CRS("mainPage"), true); HttpContext.Current.ApplicationInstance.CompleteRequest(); page.Visible = false; } } /// /// Page load (vuoto) /// /// /// protected void Page_Load(object sender, EventArgs e) { } #endregion Protected Methods } }