Beispiel #1
0
 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);
     }
 }