Esempio n. 1
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            try
            {
                Usuario oUsuario = new Usuario(txtUsuario.Text, txtPassword.Text);
                oUsuario.Cargar();

                ////Si el usuario no existe
                //if (oUsuario.Nombre == "" || oUsuario.Nombre == null)
                //{
                //    //Valida si existe como empleado
                //    Proveedor oEmpleado = new Proveedor();
                //    oEmpleado.Buscar(oUsuario.Id);

                //    //Si existe como empleado
                //    if (oEmpleado.Nombre != "" && oEmpleado.Nombre != null)
                //    {
                //        NegocioPF.Configuracion oConfig = new NegocioPF.Configuracion(oEmpleado.Empresa);
                //        oConfig.Cargar();

                //        //Da de alta al usuario
                //        oUsuario.Id = oEmpleado.Id;
                //        oUsuario.Nombre = oEmpleado.Nombre;
                //        oUsuario.Empresa = oEmpleado.Empresa;
                //        oUsuario.Idioma = ((Idioma)Session["oIdioma"]).Id.ToString();
                //        oUsuario.Empleado = oEmpleado.Id;
                //        oUsuario.Password = "******";
                //        oUsuario.Perfil = oConfig.PerfilEmpleado;
                //        oUsuario.Pregunta = "";
                //        oUsuario.Respuesta = "";
                //        oUsuario.Status = "ACTIVO";
                //        oUsuario.Guardar("UsuarioPF");
                //        txtPassword.Text = "Temporal1";
                //    }
                //}

                if (txtCaptcha.Text.ToString() != Session["randomStr"].ToString())
                {
                    txtCaptcha.Text = "";
                    throw new Exception("MsgErrCaptchaIncorrecto");
                }


                //Si el usuario existe
                if (oUsuario.Nombre != "" && oUsuario.Nombre != null)
                {
                    if (oUsuario.Validar(txtPassword.Text))
                    {
                        oUsuario.Idioma = cboIdioma.SelectedValue;
                        oUsuario.ActualizaIdioma(txtUsuario.Text);

                        //Genera una cookie con el número de usuario
                        HttpCookie aCookie = new HttpCookie("UsuarioPF");
                        aCookie.Value   = txtUsuario.Text;
                        aCookie.Expires = DateTime.Now.AddDays(1);
                        Response.Cookies.Add(aCookie);

                        Bitacora.Registra(oUsuario.Id, "Login", "Acceso al sistema");

                        Session["oUsuario"] = oUsuario;

                        Idioma oIdioma = new Idioma(oUsuario.Idioma);
                        Session["oIdioma"] = oIdioma;

                        if (txtPassword.Text == "Temporal1")
                        {
                            btnCambioPassword_Click(sender, e);
                        }
                        else
                        {
                            Response.Redirect("Principal.aspx");
                        }
                    }
                }
                else
                {
                    throw new Exception("UsuarioInexistente");
                }
            }
            catch (Exception ex)
            {
                this.Form.DefaultButton = this.btnAceptar.UniqueID;
                MessageBox(null, null, ((Idioma)Session["oIdioma"]).Texto(ex.Message));
            }
        }