protected void btnIngresar_Click(object sender, EventArgs e) { if (!IsValid) { return; } try { DataContext db = new DcGeneralDataContext(); String mensaje = String.Empty; if (!this.validacion(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.sqlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.htmlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } var dbUser = db.GetTable <Usuario>().FirstOrDefault(u => u.strNombreUsuario == this.txtNombreUsuario.Text.Trim()); if (dbUser == null) { this.lblError.Text = "Nombre de usuario o contraseña incorrectos"; this.lblError.Visible = true; return; } if (dbUser.idEstado != 1) { this.lblError.Text = "Este usuario no está activo por lo cual no puede iniciar sesión"; this.lblError.Visible = true; return; } var passDec = CtrlEncrypt.DesEncriptar(dbUser.strContrasena); if (!passDec.Equals(this.txtContrasena.Text.Trim())) { this.lblError.Text = "Nombre de usuario o contraseña incorrectos"; this.lblError.Visible = true; return; } this.Response.Redirect("~/PaginaPrincipal.aspx", false); } catch (Exception ex) { CtrlCorreo email = new CtrlCorreo(); email.enviarCorreo(ex.Message); this.Response.Redirect("~/PaginasErrores/Error.html", false); } }
protected void btnCorreo_Click(object sender, EventArgs e) { if (!IsValid) { return; } try { CtrlCorreo email = new CtrlCorreo(); DataContext db = new DcGeneralDataContext(); var persona = db.GetTable <Linq.Data.Entity.Persona>().FirstOrDefault(p => p.strEmail == this.txtCorreo.Text.Trim()); if (persona == null) { this.lblError.Visible = true; this.lblError.Text = "El correo ingresado no existe en nuestra base de datos"; return; } var usuario = db.GetTable <Usuario>().FirstOrDefault(u => u.idComPersona == persona.id); if (usuario == null) { this.lblError.Visible = true; this.lblError.Text = "El correo ingresado no está asociado a un usuario"; return; } if (usuario.idEstado > 1) { this.lblError.Visible = true; this.lblError.Text = "El usuario asignado a este correo no se encuentra activo"; return; } var token = CtrlEncrypt.GetSHA256(Guid.NewGuid().ToString()); usuario.strTokenContrasena = token; db.SubmitChanges(); if (email.recuperarContrasenaCorreo(persona.strEmail, persona.strNombre, token)) { Response.Redirect("~/CorreoEnviado.html", false); } else { this.lblError.Visible = true; this.lblError.Text = "Hubo un error al enviar el correo, intenta más tarde."; return; } } catch (Exception ex) { CtrlCorreo email = new CtrlCorreo(); email.enviarCorreo(ex.Message); this.Response.Redirect("~/PaginasErrores/Error.html", false); } }
protected void btnReestablecerContrasena_Click(object sender, EventArgs e) { if (!IsValid) { return; } try { DataContext db = new DcGeneralDataContext(); String mensaje = String.Empty; var user = db.GetTable <Usuario>().FirstOrDefault(u => u.strTokenContrasena == this.key); if (!this.validacion(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.sqlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.htmlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } user.strContrasena = CtrlEncrypt.Encriptar(this.txtContrasena.Text.Trim()); user.strTokenContrasena = null; db.SubmitChanges(); Response.Redirect("~/PaginaPrincipal.aspx", false); } catch (Exception ex) { CtrlCorreo email = new CtrlCorreo(); email.enviarCorreo(ex.Message); this.Response.Redirect("~/PaginasErrores/Error.html", false); } }
protected void btnAceptar_Click(object sender, EventArgs e) { if (!IsValid) { return; } try { DataContext dcGuardar = new DcGeneralDataContext(); Usuario usuario = new Usuario(); DateTime fechaValida; if (this.idUsuarios == 0) { usuario.idComPersona = int.Parse(this.ddlPersona.SelectedValue); usuario.strNombreUsuario = this.txtNombreUsuario.Text.Trim(); usuario.strContrasena = CtrlEncrypt.Encriptar(this.txtContrasena.Text.Trim()); usuario.idEstado = 1; if (DateTime.TryParseExact(this.txtFechaIngreso.Text.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out fechaValida)) { usuario.dtFechaIngreso = fechaValida; } String mensaje = String.Empty; if (!this.validacion(usuario, ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.sqlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.htmlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.sqlValidaConsulta(usuario, ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } dcGuardar.GetTable <Usuario>().InsertOnSubmit(usuario); dcGuardar.SubmitChanges(); this.Response.Redirect("~/PrincipalUsuarios.aspx", false); } if (this.idUsuarios > 0) { usuario = dcGuardar.GetTable <Usuario>().First(u => u.id == this.idUsuarios); usuario.strNombreUsuario = this.txtNombreUsuario.Text.Trim(); usuario.strContrasena = CtrlEncrypt.Encriptar(this.txtContrasena.Text.Trim()); usuario.idEstado = int.Parse(this.ddlEstado.SelectedValue); String mensaje = String.Empty; if (!this.validacion(usuario, ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.sqlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.htmlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.sqlValidaConsultaEditar(usuario, ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } dcGuardar.SubmitChanges(); this.Response.Redirect("~/PrincipalUsuarios.aspx", false); } } catch (Exception ex) { CtrlCorreo email = new CtrlCorreo(); email.enviarCorreo(ex.Message); this.Response.Redirect("~/PaginasErrores/Error.html", false); } }
protected void btnAceptar_Click(object sender, EventArgs e) { try { if (!IsValid) { return; } DataContext dcGuardar = new DcGeneralDataContext(); UTTT.Ejemplo.Linq.Data.Entity.Persona persona = new Linq.Data.Entity.Persona(); int i = 0; DateTime dateValidate = DateTime.Now; if (this.idPersona == 0) { persona.strClaveUnica = this.txtClaveUnica.Text.Trim(); persona.strNombre = this.txtNombre.Text.Trim(); persona.strAMaterno = this.txtAMaterno.Text.Trim(); persona.strAPaterno = this.txtAPaterno.Text.Trim(); persona.idCatSexo = int.Parse(this.ddlSexo.Text); persona.dtFechaNacimiento = (!DateTime.TryParseExact(this.txtFechaNaci.Text.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValidate)) ? (DateTime?)null : dateValidate; persona.intNumHermanos = this.txtHermanos.Text.Trim().Length > 0 ? (int.TryParse(this.txtHermanos.Text.Trim(), out i) ? int.Parse(this.txtHermanos.Text.Trim()) : 0) : 0; persona.strEmail = this.txtCorreo.Text.Trim(); persona.strCP = this.txtCodigoP.Text.Trim(); persona.strRFC = this.txtRFC.Text.Trim(); persona.idEstadoCivil = int.Parse(this.ddlEstadoCivil.Text); String mensaje = String.Empty; if (!this.validacion(persona, ref mensaje)) { this.lblErrorValidacion.Text = mensaje; this.lblErrorValidacion.Visible = true; return; } if (!this.sqlInjectionValida(ref mensaje)) { this.lblErrorValidacion.Text = mensaje; this.lblErrorValidacion.Visible = true; return; } if (!this.htmlInjectionValida(ref mensaje)) { this.lblErrorValidacion.Text = mensaje; this.lblErrorValidacion.Visible = true; return; } if (!this.sqlValidaConsulta(persona, ref mensaje)) { this.lblErrorValidacion.Text = mensaje; this.lblErrorValidacion.Visible = true; return; } dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().InsertOnSubmit(persona); dcGuardar.SubmitChanges(); this.showMessage("El registro se agrego correctamente."); this.Response.Redirect("~/PersonaPrincipal.aspx", false); } if (this.idPersona > 0) { persona = dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().First(c => c.id == idPersona); persona.strClaveUnica = this.txtClaveUnica.Text.Trim(); persona.strNombre = this.txtNombre.Text.Trim(); persona.strAMaterno = this.txtAMaterno.Text.Trim(); persona.strAPaterno = this.txtAPaterno.Text.Trim(); persona.idCatSexo = int.Parse(this.ddlSexo.Text); persona.dtFechaNacimiento = (!DateTime.TryParseExact(this.txtFechaNaci.Text.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValidate)) ? (DateTime?)null : dateValidate; persona.intNumHermanos = this.txtHermanos.Text.Trim().Length > 0 ? (int.TryParse(this.txtHermanos.Text.Trim(), out i) ? int.Parse(this.txtHermanos.Text.Trim()) : 0) : 0; persona.strEmail = this.txtCorreo.Text.Trim(); persona.strCP = this.txtCodigoP.Text.Trim(); persona.strRFC = this.txtRFC.Text.Trim(); persona.idEstadoCivil = int.Parse(this.ddlEstadoCivil.Text); String mensaje = String.Empty; if (!this.validacion(persona, ref mensaje)) { this.lblErrorValidacion.Text = mensaje; this.lblErrorValidacion.Visible = true; return; } if (!this.sqlInjectionValida(ref mensaje)) { this.lblErrorValidacion.Text = mensaje; this.lblErrorValidacion.Visible = true; return; } if (!this.htmlInjectionValida(ref mensaje)) { this.lblErrorValidacion.Text = mensaje; this.lblErrorValidacion.Visible = true; return; } if (!this.sqlValidaConsultaEditar(persona, ref mensaje)) { this.lblErrorValidacion.Text = mensaje; this.lblErrorValidacion.Visible = true; return; } dcGuardar.SubmitChanges(); this.showMessage("El registro se edito correctamente."); this.Response.Redirect("~/PersonaPrincipal.aspx", false); } } catch (Exception _e) { CtrlCorreo correo = new CtrlCorreo(); correo.enviarCorreo(_e.Message); this.Response.Redirect("~/PaginasErrores/Error.html", false); } }