Ejemplo n.º 1
0
        private void TokenAuth(string access_token)
        {
            LoadingDialog Loading = new LoadingDialog();

            Loading.Show();
            Application.DoEvents();
            WebRequest  request  = WebRequest.Create("https://api.vk.com/method/users.get?access_token=" + access_token);
            WebResponse response = request.GetResponse();
            var         encoding = UTF8Encoding.ASCII;
            string      userid;

            using (var reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
            {
                string  response_text = reader.ReadToEnd();
                JObject response_json = JObject.Parse(response_text);
                userid = (string)response_json.SelectToken("response[0].uid");
            }
            var vk = new VkApi();

            vk.Authorize(access_token, long.Parse(userid));
            var user_info = vk.Users.Get(vk.UserId.Value);

            GlobalVars.self_id = long.Parse(userid);
            GlobalVars.api     = vk;
            Main frm = new Main();

            frm.Show();
            Loading.Close();
            this.Hide();
        }
Ejemplo n.º 2
0
        private void selfprofile_button_Click(object sender, EventArgs e)
        {
            LoadingDialog Loading = new LoadingDialog();

            Loading.Show();
            Application.DoEvents();
            Userprofile profile = new Userprofile();

            profile.Show();
            Loading.Close();
        }
Ejemplo n.º 3
0
        private void SomeoneProfile_Button_Click(object sender, EventArgs e)
        {
            LoadingDialog Loading = new LoadingDialog();

            Loading.Show();
            Application.DoEvents();
            Userprofile profile = new Userprofile();

            profile.Target_id = long.Parse(SomeoneProfile_id.Text);
            profile.Show();
            Loading.Close();
        }
Ejemplo n.º 4
0
        private void LoginByPassword_Button_Click(object sender, EventArgs e)
        {
            LoadingDialog Loading = new LoadingDialog();

            Loading.Show();
            Application.DoEvents();
            string facode = string.Empty;
            string platform;
            Dictionary <int, string> platforms = new Dictionary <int, string>
            {
                { 0, "client_id=2274003&client_secret=hHbZxrka2uZ6jB1inYsH" },
                { 1, "client_id=3140623&client_secret=VeWdmVclDCtn6ihuP1nt" },
                { 2, "client_id=3682744&client_secret=mY6CDUswIVdJLCD3j15n" },
                { 3, "client_id=3502561&client_secret=omvP3y2MZmpREFZJDNHd" }
            };
            string username = WebUtility.UrlEncode(Login_text.Text);
            string password = WebUtility.UrlEncode(Password_text.Text);

            if (TSV_Code.Enabled)
            {
                if (TSV_Code.Text != "")
                {
                    facode = "&code=" + TSV_Code.Text;
                }
                else
                {
                    MessageBox.Show("Enter 2FA code to login", "Error");
                    return;
                }
            }
            int platformIndex = PlatformSelector.SelectedIndex;

            platform = platforms[platformIndex];
            string     requestUrl = "https://oauth.vk.com/token?scope=all&" + platform + "&lang=en&grant_type=password&username="******"&password="******"access_token").ToString();
                    Loading.Close();
                    TokenAuth(access_token);
                }
            }
            catch (WebException err)
            {
                using (WebResponse response = err.Response)
                {
                    string          text         = string.Empty;
                    HttpWebResponse httpResponse = (HttpWebResponse)response;
                    using (Stream data = response.GetResponseStream())
                        using (var reader = new StreamReader(data))
                        {
                            text = reader.ReadToEnd();
                        }
                    JObject error = JObject.Parse(text);
                    if (error.SelectToken("error").ToString() == "need_captcha")
                    {
                        Captcha captcha_processor = new Captcha
                        {
                            CaptchaUrl = WebUtility.UrlDecode(error.SelectToken("captcha_img").ToString()),
                            CaptchaSid = error.SelectToken("captcha_sid").ToString(),
                            RequestUrl = requestUrl
                        };
                        captcha_processor.ShowDialog();
                        if (captcha_processor.Success)
                        {
                            JObject login_response = JObject.Parse(captcha_processor.Response);
                            string  access_token   = login_response.SelectToken("access_token").ToString();
                            Loading.Close();
                            TokenAuth(access_token);
                        }
                        else
                        {
                            MessageBox.Show("Bad captcha or Login/Password. Try again.", "Error");
                            return;
                        }
                    }
                    else
                    {
                        Loading.Close();
                        MessageBox.Show(text, "Error code: " + httpResponse.StatusCode);
                        return;
                    }
                }
            }
        }