コード例 #1
0
 //Authentificate from json file and returns VKAccaunt instance
 public VKAccount AuthentificateFromFile(string UserDataJSON, string SecretUserJSON)
 {
     Account = new VKAccount();
     UserVk  = new VkApi(service);
     try
     {
         Account = JsonConvert.DeserializeObject <VKAccount>(UserDataJSON);
         var obj = JsonConvert.DeserializeObject <VKAccount>(SecretUserJSON);
         Account.Password = obj.Password;
         Account.Login    = obj.Login;
         Settings set = Settings.Audio;
         UserVk.Authorize(new ApiAuthParams
         {
             AccessToken   = Account.Token,
             ApplicationId = appID,
             Settings      = set
         });
         GiveAllInfoToAccountObject();
     }
     catch (VkNet.Exception.VkApiException ex)
     {
         MusicMessageBox box = new MusicMessageBox();
         box.Show();
         box.ShowWindow(null, ex.Message);
     }
     return(Account);
 }
コード例 #2
0
 //Authentificate and returns VKAccaunt instance
 public VKAccount Authentificate(bool saveProfileToJson = false)
 {
     Account = new VKAccount(Password, Login);
     UserVk  = new VkApi(service);
     try
     {
         Settings set = Settings.Audio;
         UserVk.Authorize(new ApiAuthParams
         {
             Password      = this.Password,
             Login         = this.Login,
             ApplicationId = appID,
             Settings      = set
         });
         if (UserVk.IsAuthorized)
         {
             GiveAllInfoToAccountObject();
             if (saveProfileToJson)
             {
                 SaveAs(UserDataFile.Name, JsonConvert.SerializeObject(UserVk));
                 using (JsonTextWriter writer = new JsonTextWriter(new StreamWriter(SecretDataFile.Name, true)))
                 {
                     //string json = JsonConvert.SerializeObject(Account);
                     writer.WriteStartObject();
                     writer.WritePropertyName("Name");
                     writer.WriteValue(Account.Name);
                     writer.WritePropertyName("SurName");
                     writer.WriteValue(Account.SurName);
                     writer.WritePropertyName("Password");
                     writer.WriteValue(Account.Password);
                     writer.WritePropertyName("Login");
                     writer.WriteValue(Account.Login);
                     writer.WriteEndObject();
                 }
                 SaveAs(UserAccauntDataFile.Name, JsonConvert.SerializeObject(UserVk.Account.GetInfo()));
             }
         }
         else
         {
             MusicMessageBox box = new MusicMessageBox();
             box.Show();
             box.ShowWindow(null, MessageFlags.WrongAuth);
         }
     }
     catch (Exception ex)
     {
         MusicMessageBox box = new MusicMessageBox();
         box.Show();
         box.ShowWindow(null, ex.Message);
     }
     return(Account);
 }
コード例 #3
0
        private async void Signin_btn_Click(object sender, EventArgs e)
        {
            LoadBar loadbar = new LoadBar();

            loadbar.Show();
            this.Hide();
            loadbar.Refresh();
            var client = new VKManager(login_box.Text, password_box.Text);

            if (remember_me.CheckState == CheckState.Checked)
            {
                Task t = new Task(() =>
                {
                    account = client.Authentificate(true);
                });
                t.Start();
                await t;
            }
            else if (remember_me.CheckState == CheckState.Unchecked)
            {
                Task t = new Task(() =>
                {
                    account = client.Authentificate(false);
                });
                t.Start();
                await t;
            }
            loadbar.Close();
            if (account.IsAuthorized)
            {
                player        = new Player(account);
                player.Client = client;
                player.Show();
                player.Refresh();
            }
            else
            {
                MusicMessageBox box = new MusicMessageBox();
                box.Show();
                box.ShowWindow(this, MessageFlags.WrongAuth);
            }
            this.Close();
        }