/// <summary> /// Processes Login button click /// </summary> /// <param name="sender">event source</param> /// <param name="e">event parametres</param> private void LoginButton_Click(object sender, RoutedEventArgs e) { // Open authorization page in new window browser b = new browser(this); b.ShowDialog(); // If authorization succeeded in Response we have redirected url if (Response != null) { // getting id & token Response = Response.Substring(Response.IndexOf('#') + 1); string[] parsedAns = Response.Split('&'); foreach (var s in parsedAns) { if (s.IndexOf("user_id") == 0) { id = s.Substring("user_id=".Length); } // if (s.IndexOf("user_id") == 0) else if (s.IndexOf("access_token") == 0) { token = s.Substring("access_token=".Length); } // if (s.IndexOf("access_token") == 0) } // foreach (var s in parsedAns) ErrorText.Content = "Шаг 2: введите адрес и нажмите Проверить"; ErrorText.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)); // get user's name and take it in title // create request string string req = "https://api.vk.com/method/"; req += "users.get.xml?"; req += "uids=" + id + "&"; req += "first_name,last_name&"; req += "access_token=" + token; // create request WebRequest request = WebRequest.Create(req); // send request and get response WebResponse response = request.GetResponse(); // save response in Xmlocument XmlDocument xml = new XmlDocument(); xml.LoadXml(new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd()); // gets name from xml (response->user->first_name/last_name) this.TitleLabel.Content = "Find: " + xml["response"]["user"]["first_name"].InnerText + " " + xml["response"]["user"]["last_name"].InnerText; XmlNode node = xml["response"]["user"]; // create current user currentUser = new User(node); FindIDTextBox.Focus(); } // if (Response != null) // else remember about login else ErrorText.Foreground = new SolidColorBrush(Color.FromRgb(223, 0, 0)); } // LoginButton_Click
/// <summary> /// Processes Login button click /// </summary> /// <param name="sender">event source</param> /// <param name="e">event parametres</param> private void LoginButton_Click(object sender, RoutedEventArgs e) { // Open authorization page in new window browser b = new browser(this); b.ShowDialog(); // If authorization succeeded in Response we have redirected url if (Response != null) { // getting id & token Response = Response.Substring(Response.IndexOf('#') + 1); string[] parsedAns = Response.Split('&'); foreach (var s in parsedAns) { if (s.IndexOf("user_id") == 0) { id = s.Substring("user_id=".Length); } // if (s.IndexOf("user_id") == 0) else if (s.IndexOf("access_token") == 0) { token = s.Substring("access_token=".Length); } // if (s.IndexOf("access_token") == 0) } // foreach (var s in parsedAns) ErrorText.Content = "Шаг 2: введите адрес и нажмите Проверить"; ErrorText.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)); // get user's name and take it in title // create request string string req = "https://api.vk.com/method/"; req += "users.get.xml?"; req += "uids=" + id + "&"; req += "first_name,last_name&"; req += "access_token=" + token; // create request WebRequest request = WebRequest.Create(req); // send request and get response WebResponse response = request.GetResponse(); // save response in Xmlocument XmlDocument xml = new XmlDocument(); xml.LoadXml(new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd()); // gets name from xml (response->user->first_name/last_name) this.TitleLabel.Content = "Find: " + xml["response"]["user"]["first_name"].InnerText + " " + xml["response"]["user"]["last_name"].InnerText; XmlNode node = xml["response"]["user"]; // create current user currentUser = new User(node); FindIDTextBox.Focus(); } // if (Response != null) // else remember about login else ErrorText.Foreground = new SolidColorBrush(Color.FromRgb(223, 0, 0)); }