private void AttemptToLoginAsync() { this.Focus(); if (!ValidateUserName()) { PromptUserForInput(_localizedStrings.Prompts.MissingUserName, usernameTextBox); return; } if (!ValidatePassword()) { PromptUserForInput(_localizedStrings.Prompts.MissingPassword, passwordPasswordBox); return; } string username = usernameTextBox.Text; string password = passwordPasswordBox.Password; string url = Constants.WORDPRESS_XMLRPC_URL; rpc = new GetUsersBlogsRPC(url, username, password); rpc.Completed += OnGetUsersBlogsCompleted; rpc.ExecuteAsync(); ApplicationBar.IsVisible = false; App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.LoggingIn); }
private void AttemptToLoginAsync() { this.Focus(); if (!ValidateUrl(urlTextBox.Text)) { PromptUserForInput(_localizedStrings.Prompts.MissingUrl, urlTextBox); return; } if (!ValidateUserName()) { PromptUserForInput(_localizedStrings.Prompts.MissingUserName, usernameTextBox); return; } if (!ValidatePassword()) { PromptUserForInput(_localizedStrings.Prompts.MissingPassword, passwordPasswordBox); return; } string username = usernameTextBox.Text; string password = passwordPasswordBox.Password; string url = urlTextBox.Text.Trim(); if (url.EndsWith("/")) { url = url.Substring(0, url.Length - 1); //remove the trailing slash } if (url.EndsWith("/wp-admin")) { url = url.Replace("/wp-admin", ""); } if (!url.EndsWith("/xmlrpc.php")) { url = url + "/xmlrpc.php"; } this.DebugLog("XML-RPC URL: " + url); if (!ValidateUrl(url)) { PromptUserForInput(_localizedStrings.Prompts.MissingUrl, urlTextBox); return; } rpc = new GetUsersBlogsRPC(url, username, password); rpc.Completed += OnGetUsersBlogsCompleted; rpc.ExecuteAsync(); useRecoveryFunctions = true; ApplicationBar.IsVisible = false; //hide the application bar App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.LoggingIn); }
private void AttemptToLoginAsync() { this.Focus(); if (!ValidateUrl(urlTextBox.Text)) { PromptUserForInput(_localizedStrings.Prompts.MissingUrl, urlTextBox); return; } if (!ValidateUserName()) { PromptUserForInput(_localizedStrings.Prompts.MissingUserName, usernameTextBox); return; } if (!ValidatePassword()) { PromptUserForInput(_localizedStrings.Prompts.MissingPassword, passwordPasswordBox); return; } string username = usernameTextBox.Text; string password = passwordPasswordBox.Password; string url = urlTextBox.Text.Trim(); if (url.EndsWith("/")) url = url.Substring(0, url.Length - 1); //remove the trailing slash if (url.EndsWith("/wp-admin")) url = url.Replace("/wp-admin", ""); if (!url.EndsWith("/xmlrpc.php")) url = url + "/xmlrpc.php"; this.DebugLog("XML-RPC URL: " + url); if (!ValidateUrl(url)) { PromptUserForInput(_localizedStrings.Prompts.MissingUrl, urlTextBox); return; } rpc = new GetUsersBlogsRPC(url, username, password); rpc.Completed += OnGetUsersBlogsCompleted; rpc.ExecuteAsync(); useRecoveryFunctions = true; ApplicationBar.IsVisible = false; //hide the application bar App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.LoggingIn); }
void downloadRSDdocumentCompleted(object sender, DownloadStringCompletedEventArgs e) { rsdWebClient.DownloadStringCompleted -= downloadRSDdocumentCompleted; string apiLink = null; if (e.Error == null) { try { string rsdDocumentString = e.Result; //clean the junk b4 the xml preamble. if (!rsdDocumentString.StartsWith("<?xml")) { //clean the junk b4 the xml preamble this.DebugLog("cleaning the junk before the xml preamble"); int indexOfFirstLt = rsdDocumentString.IndexOf("<?xml"); if (indexOfFirstLt > -1) rsdDocumentString = rsdDocumentString.Substring(indexOfFirstLt); } try { XDocument xDoc = XDocument.Parse(rsdDocumentString, LoadOptions.None); foreach (XElement apiElement in xDoc.Descendants()) { if (apiElement.Name.LocalName == "api") if (apiElement.Attribute("name").Value == "WordPress") { apiLink = apiElement.Attribute("apiLink").Value; } } } catch (Exception) { } if (apiLink == null || !ValidateUrl(apiLink)) { apiLink = null; //try to use RegExp String pattern = @"<api\s*?name=\""WordPress\"".*?apiLink=\""(.*?)\"""; Regex regex = new Regex(pattern, RegexOptions.IgnoreCase); if (regex.IsMatch(rsdDocumentString)) { Match firstMatch = regex.Match(rsdDocumentString); rsdDocumentString = rsdDocumentString.Substring(firstMatch.Index, firstMatch.Length); rsdDocumentString = rsdDocumentString.Substring(rsdDocumentString.IndexOf("apiLink=\"")); rsdDocumentString = rsdDocumentString.Replace("apiLink=\"", ""); rsdDocumentString = rsdDocumentString.Substring(0, rsdDocumentString.IndexOf("\"")); if (ValidateUrl(rsdDocumentString)) apiLink = rsdDocumentString; } } } catch (Exception) { } } if (apiLink != null) { //restart getUserBlogs with this URL string username = usernameTextBox.Text; string password = passwordPasswordBox.Password; rpc = new GetUsersBlogsRPC(apiLink, username, password); rpc.Completed += OnGetUsersBlogsCompleted; rpc.ExecuteAsync(); } else this.showErrorMsgOnRecovery(null); //No match or error. Show "no WP site found at this URL..." }
void downloadRSDdocumentCompleted(object sender, DownloadStringCompletedEventArgs e) { rsdWebClient.DownloadStringCompleted -= downloadRSDdocumentCompleted; string apiLink = null; if (e.Error == null) { try { string rsdDocumentString = e.Result; //clean the junk b4 the xml preamble. if (!rsdDocumentString.StartsWith("<?xml")) { //clean the junk b4 the xml preamble this.DebugLog("cleaning the junk before the xml preamble"); int indexOfFirstLt = rsdDocumentString.IndexOf("<?xml"); if (indexOfFirstLt > -1) { rsdDocumentString = rsdDocumentString.Substring(indexOfFirstLt); } } try { XDocument xDoc = XDocument.Parse(rsdDocumentString, LoadOptions.None); foreach (XElement apiElement in xDoc.Descendants()) { if (apiElement.Name.LocalName == "api") { if (apiElement.Attribute("name").Value == "WordPress") { apiLink = apiElement.Attribute("apiLink").Value; } } } } catch (Exception) { } if (apiLink == null || !ValidateUrl(apiLink)) { apiLink = null; //try to use RegExp String pattern = @"<api\s*?name=\""WordPress\"".*?apiLink=\""(.*?)\"""; Regex regex = new Regex(pattern, RegexOptions.IgnoreCase); if (regex.IsMatch(rsdDocumentString)) { Match firstMatch = regex.Match(rsdDocumentString); rsdDocumentString = rsdDocumentString.Substring(firstMatch.Index, firstMatch.Length); rsdDocumentString = rsdDocumentString.Substring(rsdDocumentString.IndexOf("apiLink=\"")); rsdDocumentString = rsdDocumentString.Replace("apiLink=\"", ""); rsdDocumentString = rsdDocumentString.Substring(0, rsdDocumentString.IndexOf("\"")); if (ValidateUrl(rsdDocumentString)) { apiLink = rsdDocumentString; } } } } catch (Exception) { } } if (apiLink != null) { //restart getUserBlogs with this URL string username = usernameTextBox.Text; string password = passwordPasswordBox.Password; rpc = new GetUsersBlogsRPC(apiLink, username, password); rpc.Completed += OnGetUsersBlogsCompleted; rpc.ExecuteAsync(); } else { this.showErrorMsgOnRecovery(null); //No match or error. Show "no WP site found at this URL..." } }