using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using SteamWare; using MapoDb; namespace MoonProTablet.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) { 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.confReadString("cookieName")); if (DataLayer.obj.taOp.getByMatrAuthKey(MatrOpr, md5UserAuthKey).Rows.Count > 0) { fatto = tryEnroll(MatrOpr, userAgent, fatto, DeviceName, IPv4, md5UserAuthKey); } // provo con "plainUserKey" else if (DataLayer.obj.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) { Response.Redirect(memLayer.ML.confReadString("mainPage"), true); } } /// /// prova a fare enroll device data chiave... /// /// /// /// /// /// /// /// private bool tryEnroll(int MatrOpr, string userAgent, bool fatto, string DeviceName, string IPv4, string userKey) { try { fatto = DataLayer.obj.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; } /// /// resetto tutto /// /// /// protected void btnAnnulla_Click(object sender, EventArgs e) { txtUserAuthKey.Text = ""; } } }