Пример #1
0
        private void btnIngresar_Click(object sender, EventArgs e)
        {
            bool result = true;

            if (string.IsNullOrEmpty(this.txtUsuario.Text))
            {
                this.errorValidator.SetError(this.txtUsuario, "Ingresar Nombre Usuario.");
                result = false;
            }
            else
            {
                this.errorValidator.SetError(this.txtUsuario, string.Empty);
            }
            if (string.IsNullOrEmpty(this.txtClave.Text))
            {
                this.errorValidator.SetError(this.txtClave, "Ingresar Contraseña.");
                result = false;
            }
            else
            {
                this.errorValidator.SetError(this.txtClave, string.Empty);
            }

            if (result)
            {
                string userDomain = FindName(txtUsuario.Text);
                if (string.IsNullOrEmpty(userDomain))
                {
                    MessageBox.Show(this.ParentForm, "Usted No tiene acceso al Sistema", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    bool existeUsuario = UserExists(txtUsuario.Text);
                    if (existeUsuario)
                    {
                        if (AutenticarEnDominio(userDomain, txtUsuario.Text, txtClave.Text))
                        {
                            UsuarioRepository usuarioRepository = new UsuarioRepository();

                            if (usuarioRepository.GetByUsername(txtUsuario.Text) == null)
                            {
                                MessageBox.Show(this.ParentForm, "Este Usuario de Dominio " + txtUsuario.Text + " no pertenece al Sistema", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                            else
                            {
                                UsuarioSession.UserName = this.txtUsuario.Text;
                                UsuarioSession.Clave = txtClave.Text;
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show(this.ParentForm, "Password incorrecto para AD", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this.ParentForm, "Este usuario no se encuentra en AD", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }