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);
     }
 }
예제 #2
0
 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);
     }
 }
예제 #3
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 Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.Response.Buffer = true;
                this.session         = (SessionManager)this.Session["SessionManager"];
                this.idUsuarios      = this.session.Parametros["idUsuario"] != null?
                                       int.Parse(this.session.Parametros["idUsuario"].ToString()) : 0;

                if (this.idUsuarios == 0)
                {
                    this.baseEntity = new Usuario();
                    this.tipoAccion = 1;
                }
                else
                {
                    this.baseEntity = dcGlobal.GetTable <Usuario>().First(u => u.id == this.idUsuarios);
                    this.tipoAccion = 2;
                }
                this.txtContrasena.Attributes.Add("type", "password");
                this.txtContrasena2.Attributes.Add("type", "password");
                if (!IsPostBack)
                {
                    if (this.session.Parametros["baseEntity"] == null)
                    {
                        this.session.Parametros.Add("baseEntity", this.baseEntity);
                    }
                    List <Linq.Data.Entity.Persona> personas = this.dcGlobal.GetTable <Linq.Data.Entity.Persona>().ToList();
                    this.ddlPersona.DataTextField  = "NombreCompleto";
                    this.ddlPersona.DataValueField = "id";
                    if (this.idUsuarios == 0)
                    {
                        this.lblAccion.Text        = "Agregar";
                        this.ddlPersona.DataSource = personas;
                        this.ddlPersona.DataBind();
                    }
                    else
                    {
                        this.lblAccion.Text           = "Editar";
                        this.txtPersonaEditar.Visible = true;
                        this.ddlEstado.Visible        = true;
                        this.ddlPersona.Visible       = false;
                        this.txtFechaIngreso.Visible  = false;
                        List <EstadoUsuario> estadosUsuario = dcGlobal.GetTable <EstadoUsuario>().ToList();
                        this.ddlEstado.DataTextField  = "strValor";
                        this.ddlEstado.DataValueField = "id";
                        this.ddlEstado.DataSource     = estadosUsuario;
                        this.ddlEstado.DataBind();
                        this.setItem(ref this.ddlEstado, baseEntity.EstadoUsuario.strValor);
                        this.txtPersonaEditar.Text = baseEntity.Persona.NombreCompleto;
                        this.txtNombreUsuario.Text = baseEntity.strNombreUsuario;
                        this.txtFechaIngreso.Text  = baseEntity.dtFechaIngreso.ToString("dd/MM/yyyy");
                        this.txtContrasena.Text    = CtrlEncrypt.DesEncriptar(baseEntity.strContrasena);
                        this.txtContrasena2.Text   = CtrlEncrypt.DesEncriptar(baseEntity.strContrasena);
                    }
                }
                if (this.idUsuarios > 0)
                {
                    this.txtPersonaEditar.Text    = baseEntity.Persona.NombreCompleto;
                    this.txtPersonaEditar.Visible = true;
                    this.txtFechaIngreso.Visible  = false;
                }
            }
            catch (Exception ex)
            {
                this.Response.Redirect("~/PrincipalUsuarios.aspx", 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);
     }
 }