public HomeAuthentication(CoHome home) { InitializeComponent(); this.activeHome = home; lblHogar.Text = activeHome.nick.ToUpper(); homeCover.Load(activeHome.image); }
public CoHome Registry(CoHome home, out CoSesion session, out Boolean internetStatus) { session = new CoSesion(); internetStatus = true; string sessionToken = string.Empty; home = this.rsHome.Save(home, out sessionToken, out internetStatus); if (home.id != 0) { try { this.daHome.Save(home); session.start = DateTime.Now; session.token = sessionToken; int idSession = new BrSesion().Save(session); } catch (Exception ex) { home = null; } } else { home = null; } return(home); }
public CoHome registerHome(out string status, out string code, CoHome coHome) { status = string.Empty; code = string.Empty; try { string requestParams = "{ \"email\": \"" + coHome.mail + "\", \"nick\": \"" + coHome.nick + "\", \"password\": \"" + coHome.password + "\" }"; //string requestParams = ""; //format information you need to pass into that string ('info={ "EmployeeID": [ "1234567", "7654321" ], "Salary": true, HttpWebRequest webRequest; string urlHome = ConfigurationManager.AppSettings["urlRegisterHome"]; webRequest = (HttpWebRequest)WebRequest.Create(urlHome); webRequest.Method = "POST"; webRequest.ContentType = "application/json"; byte[] byteArray = Encoding.UTF8.GetBytes(requestParams); webRequest.ContentLength = byteArray.Length; using (Stream requestStream = webRequest.GetRequestStream()) { requestStream.Write(byteArray, 0, byteArray.Length); } // Get the response. using (WebResponse response = webRequest.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { StreamReader rdr = new StreamReader(responseStream, Encoding.UTF8); var rawJson = new StreamReader(response.GetResponseStream()).ReadToEnd(); JObject json = JObject.Parse(rawJson); status = json["status"].ToString(); code = json["code"].ToString(); //aqui debo insertar en bd local string id = json["data"]["id"].ToString(); // string image = json["data"]["image"].ToString(); string email = json["data"]["email"].ToString(); string nick = json["data"]["nick"].ToString(); string tooken = json["data"]["session"]["token"].ToString(); //string session = json["data"]["sesion"].ToString(); coHome.id = Convert.ToInt32(id); coHome.nick = nick; coHome.mail = email; coHome.tookenHome = tooken; } } return(coHome); } catch (Exception ex) { coHome.id = 0; return(coHome); } }
public ControlCenter(CoHome home, CoSesion session) { InitializeComponent(); alarms1.BringToFront(); this.brBatch = new BrBatch(); this.brBatch.StartProcess(); this.activeHome = home; this.activeSession = session; }
public CoHome Authenticate(CoHome home, out string sessionToken, out Boolean internetStatus) { home = this.rsHome.Authenticate(home, out sessionToken, out internetStatus); if (home.id == 0) { home = null; } return(home); }
internal void validateAuth(out string status, out string code, CoHome coHome) { code = string.Empty; status = string.Empty; try { DaAnimusRest da = new DaAnimusRest(); da.validateAuth(out status, out code, coHome); } catch (Exception ex) { coHome.id = 0; } }
public CoHome registerHome(out string status, out string code, CoHome coHome) { code = string.Empty; status = string.Empty; try { DaAnimusRest da = new DaAnimusRest(); return(da.registerHome(out status, out code, coHome)); } catch (Exception ex) { coHome.id = 0; return(coHome); } }
private void btnRegistro_Click(object sender, EventArgs e) { string msg = string.Empty; if (ValidateFields(out msg) == false) { nameForm = "LoginAnimus"; msgForm = msg; msgNotification ms = new msgNotification(); ms.ShowDialog(); return; } //si el email ya existe lo tengo que mandar a iniciar session Boolean exists = this.ValidateExistsEmail(); if (exists == true) { txtCorreo.Text = string.Empty; txtNick.Text = string.Empty; nameForm = "LoginAnimus"; msgForm = "La cuenta de correo existe, debe ingresar por la opción ya tengo una cuenta."; msgNotification ms = new msgNotification(); ms.ShowDialog(); return; } CoHome home = new CoHome(); home.nick = txtNick.Text; home.mail = txtCorreo.Text; home.password = txtPassword.Text; Boolean internetStatus = true; CoSesion session = null; home = this.brHome.Registry(home, out session, out internetStatus); if (!internetStatus) { this.InternetStatus(internetStatus); return; } else { this.Hide(); ControlCenter controlCenter = new ControlCenter(home, session); controlCenter.ShowDialog(); } }
/*SQLiteConnection sqliteConn; * SQLiteCommand sqliteCmd; * SQLiteDataReader sqliteDatareader; * SQLiteTransaction sqliteTransaction; * SQLiteDataAdapter sqliteAdapter; * * String connectionString = ConfigurationManager.AppSettings["connectionString"]; * String nameDataBase = ConfigurationManager.AppSettings["nameDataBase"]; * String pathImage = ConfigurationManager.AppSettings["pathImage"]; * internal void GenerateDataBase() * { * try * { * DaGenerateScript da = new DaGenerateScript(); * da.CreateDatabase(); * } * catch (Exception ex) * { * * } * }*/ /* * query = "INSERT INTO Camera VALUES(?, ? , ?)"; * DbParameter[] parameters = { * new DbParameter("name", camera.name.ToString()), * new DbParameter("status", ((camera.status) ? 1 : 0).ToString()), * new DbParameter("associate", ((camera.associate) ? 1 : 0).ToString()) * }; * DbContext.InsertOrUpdate(query, parameters); */ public CoHome Save(CoHome home) { var query = "INSERT INTO Home VALUES(?, ? , ?, ?)"; DbParameter[] parameters = { new DbParameter("id", home.id.ToString()), new DbParameter("nick", home.nick), new DbParameter("mail", home.mail), new DbParameter("image", home.image) }; int id = DbContext.InsertOrUpdate(query, parameters); home.id = id; return(home); }
public CoHome Exists() { var query = "SELECT * FROM Home LIMIT 1;"; var result = DbContext.Select(query); if (result.Count() > 0) { CoHome home = new CoHome { id = Convert.ToInt32(result[0]["id"].ToString()), nick = result[0]["nick"].ToString(), mail = result[0]["mail"].ToString(), image = result[0]["image"].ToString() }; return(home); } else { return(null); } }
public CoHome Save(CoHome home, out string sessionToken, out Boolean internetStatus) { internetStatus = true; sessionToken = string.Empty; JObject request = new JObject(); request.Add("email", home.mail); request.Add("nick", home.nick); request.Add("password", home.password); //string requestParams = "{ \"email\": \"" + home.mail + "\", \"nick\": \"" + home.nick + "\", \"password\": \"" + home.password + "\" }"; try { HttpWebRequest webRequest = this.CreatePost("home", request.ToString(), out internetStatus, false); if (internetStatus) { internetStatus = true; using (WebResponse response = webRequest.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { var rawJson = new StreamReader(response.GetResponseStream()).ReadToEnd(); CoRestResponse parsedPresponse = this.ParseResponse(rawJson); if (parsedPresponse != null && parsedPresponse.status) { home.id = Convert.ToInt32(parsedPresponse.data["id"].ToString()); home.nick = parsedPresponse.data["nick"].ToString(); home.mail = parsedPresponse.data["email"].ToString(); sessionToken = parsedPresponse.data["session"]["token"].ToString(); } } } } } catch (Exception ex) { internetStatus = false; } return(home); }
private void btnSaveHome_Click(object sender, EventArgs e) { if (txtPassword.Text != "") { this.activeHome.password = txtPassword.Text; Boolean internetStatus = true; string sessionToken = string.Empty; this.activeHome = this.brHome.Authenticate(this.activeHome, out sessionToken, out internetStatus); if (!internetStatus) { MessageBox.Show("No existe conexión a internet, intentelo más tarde"); return; } if (this.activeHome != null && this.activeHome.id != 0) { CoSesion session = new CoSesion(); session.start = DateTime.Now; session.token = sessionToken; int idSession = new BrSesion().Save(session); if (idSession != 0) { session.id = idSession; this.Hide(); ControlCenter c = new ControlCenter(this.activeHome, session); c.ShowDialog(); } } else { MessageBox.Show("Usuario o Password Incorrecto"); return; } } }
private void btnSaveHome_Click(object sender, EventArgs e) { try { if (ValidatePassword(txtPassword.Text) == false) { return; } if (btnSaveHome.Text.ToUpper().Trim().Contains("HOGAR")) { // INSERT HOGAR. //devuelde id select last_insert_rowid(); if (mailPassword != "" && nickPassword != "" && txtPassword.Text != "") { CoHome coHome = new CoHome(); coHome.nick = nickPassword; coHome.password = txtPassword.Text; coHome.mail = mailPassword; string status = string.Empty; string code = string.Empty; string fullimagepath = Path.Combine(Application.StartupPath); string path = System.IO.Directory.GetCurrentDirectory().Replace("\\bin\\Debug", ""); path = path + "\\" + "usr.txt"; //Consumir post al insert casa coHome = new BrAnimusRest().registerHome(out status, out code, coHome); if (status.ToUpper().Trim() != "OK" || code != "201") { MetroFramework.MetroMessageBox.Show(this, "No existe conexión con el servidor, vuelva a reintentarlo.", "Animus", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (coHome.id != 0) { string response = string.Empty; //insertamos home en base de datos //new BrHome().InsertHome(coHome, out response); //GUARDA ARCHIVO CON HOME,ID,MAIL,PASS if (File.Exists(path) && response == "OK") { //remove text archive //File.Delete(path); //create archive idHome = coHome.id; string createText = coHome.id + ";" + coHome.mail + ";" + coHome.nick; File.WriteAllText(path, createText); homeControl = coHome; //this.Close(); //DashBoardMenu dashBoard = new DashBoardMenu(); //dashBoard.ShowDialog(); this.Close(); //ControlCenter c = new ControlCenter(); //c.ShowDialog(); } } } } else // validate auth { if (mailPassword != "" && txtPassword.Text != "") { CoHome coHome = new CoHome(); coHome.mail = mailPassword; coHome.password = txtPassword.Text; string status = string.Empty; string code = string.Empty; //consume validate password new BrAnimusRest().validateAuth(out status, out code, coHome); if (status.ToUpper().Trim() != "OK" || code == "402") { MetroFramework.MetroMessageBox.Show(this, "Usuario o Password Incorrecto.", "Animus", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (status.ToUpper().Trim() != "OK" || code != "201") { MetroFramework.MetroMessageBox.Show(this, "No existe conexión con el servidor, vuelva a reintentarlo.", "Animus", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (coHome.id != 0) { // mando a llamar al dashboard //this.Hide(); //DashBoardMenu d = new DashBoardMenu(); //d.ShowDialog(); homeControl = coHome; this.Hide(); //ControlCenter c = new ControlCenter(); //c.ShowDialog(); } else { MetroFramework.MetroMessageBox.Show(this, "No se pudo rescatar los datos del usuario, favor reintentar.", "Animus", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } } #region //CoHome coHome = new CoHome(); //coHome.nickHome = nickPassword; //coHome.password = txtPassword.Text; //coHome.mail = mailPassword; //if (imageHomePath != "") // coHome.pathImageHome = imageHomePath; //if (nameArchiveHome != "") // coHome.imageHome = nameArchiveHome; //int homeIdRescue = 0; ////vamos a validar si existe el home con el correo y nick //int countExist = new BrHome().HomeExits(coHome, out homeIdRescue); //if (countExist == 0) //{ // //inserto home // idHome = new BrHome().InsertHome(coHome); // if (idHome > 0) // { // //Mando A llamar menu // this.Hide(); // DashBoardMenu dashBoard = new DashBoardMenu(); // dashBoard.ShowDialog(); // } // else // { // MetroFramework.MetroMessageBox.Show(this, "No se pudo registrar el Hogar, pongase en contacto con el administrador.", "Animus", MessageBoxButtons.OK, MessageBoxIcon.Information); // } //} //else //{ // if (countExist == 1 && homeIdRescue != 0) // { // coHome.idHome = homeIdRescue; // //validar password // Boolean validatePass = new BrHome().validatePassword(coHome); // if (validatePass == false) // { // MetroFramework.MetroMessageBox.Show(this, "La contraseña es incorrecta.", "Animus", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // idHome = homeIdRescue; // //Mando A llamar menu // this.Hide(); // DashBoardMenu dashBoard = new DashBoardMenu(); // dashBoard.ShowDialog(); // } // else // { // MetroFramework.MetroMessageBox.Show(this, "No se pudieron rescatar los datos del Hogar, pongase en contacto con el administrador.", "Animus", MessageBoxButtons.OK, MessageBoxIcon.Information); // } //} #endregion } catch (Exception ex) { } }