private async void OnConnectClick(object Sender, RoutedEventArgs E) { ProgressDialogController controller = await(( MetroWindow )Window.GetWindow(this)).ShowProgressAsync("Signing in.", "Attempting to sign in with the new credentials."); controller.SetIndeterminate( ); Settings.Default.OSUsername = Username.Text; Settings.Default.Save( ); Client tester = new Client(MainWindow.UserAgent); BackgroundWorker worker = new BackgroundWorker( ); worker.DoWork += (sender, args) => { Tuple <string, string> info = args.Argument as Tuple <string, string>; LogInOutput output = tester.LogIn(info.Item1, info.Item2, info.Item1.Length != info.Item2.Length || info.Item1.Length > 0); args.Result = output; }; worker.RunWorkerCompleted += async(O, Args) => { await controller.CloseAsync( ); LogInOutput output = ( LogInOutput )Args.Result; this.IsSignedIn = output.LogInSuccesful; StatusImage.Visibility = Visibility.Visible; StatusLabel.Visibility = Visibility.Visible; StatusLabel.Content = !this.IsSignedIn ? output.StatusString.Substring(4) : string.Empty; }; worker.RunWorkerAsync(new Tuple <string, string>(Username.Text, Password.Password)); }
private async void OnFlyoutFirstOpen( ) { if (MainWindow.Client.IsLoggedIn) { return; } controller = await window.ShowProgressAsync("Signing in.", "Signing into opensubtitles.org."); controller.SetIndeterminate( ); LogInOutput output = await SignInClient( ); if (output.LogInSuccesful && MainWindow.Client.IsLoggedIn) { controller.SetTitle("Downloading subtitle languages."); controller.SetMessage("Downloading the available subtitle languages from opensubtitles.org."); this.languages = await GetSubtitleLanguages( ); this.LanguageList.ItemsSource = this.languages; CollectionView languagesView = ( CollectionView )CollectionViewSource.GetDefaultView(LanguageList.ItemsSource); languagesView.SortDescriptions.Add(new SortDescription("LanguageName", ListSortDirection.Ascending)); } else { await window.ShowMessageAsync("Signing in failed", $"Unable to sign in to opensubtitles.org. Please try again later. (Status: {output.Status}, {output.StatusStringWithoutCode})"); } await controller.CloseAsync( ); OnFlyoutOpen( ); }
/// <summary> /// Logs in to the opensubtitles.org website. /// </summary> /// <param name="username">The client's username.</param> /// <param name="password">The client's password.</param> /// <param name="encrypt">Whether or not to encrypt the password before sending. If the password is provided as plain-text, set this to true. If the password has already been encrypted with MD5, set it to false.</param> /// <returns>The result of the login.</returns> public LogInOutput LogIn(string username, string password, bool encrypt = true) { if (encrypt) { MD5 alg = MD5.Create( ); byte[] pwBytes = System.Text.Encoding.ASCII.GetBytes(password); byte[] hash = alg.ComputeHash(pwBytes); password = Hasher.ToHexadecimal(hash); } XmlRpcStruct ret = clientProxy.LogIn(username, password, "eng", this.UserAgent); this.login = new LogInOutput(ret); keepAliveTimer.Start( ); return(login); }