private async void BtnRegister_Click(object sender, RoutedEventArgs e) { if(!CheckBoxPrivacyPolicy.IsChecked == true) return; var email = TextBoxRegisterEmail.Text; if(string.IsNullOrEmpty(email) || !Regex.IsMatch(email, @".*@.*\..*")) { DisplayLoginError("Please enter an valid email address"); return; } if(string.IsNullOrEmpty(TextBoxRegisterPassword.Password)) { DisplayLoginError("Please enter a password"); return; } if(TextBoxRegisterPassword.Password.Length < 6) { DisplayLoginError("Your password needs to be at least 6 characters"); return; } if(string.IsNullOrEmpty(TextBoxRegisterPasswordConfirm.Password)) { DisplayLoginError("Please confirm your password"); return; } if(!TextBoxRegisterPassword.Password.Equals(TextBoxRegisterPasswordConfirm.Password)) { DisplayLoginError("Entered passwords do not match"); return; } IsEnabled = false; _controller = await this.ShowProgressAsync("Registering account...", ""); var result = await HearthStatsAPI.RegisterAsync(email, TextBoxRegisterPassword.Password); if(result.Success) { _controller.SetTitle("Logging in..."); result = await HearthStatsAPI.LoginAsync(email, TextBoxRegisterPassword.Password); } else if(result.Message.Contains("422")) DisplayLoginError("Email already registered"); else DisplayLoginError(result.Message); TextBoxRegisterPassword.Clear(); TextBoxRegisterPasswordConfirm.Clear(); if(result.Success) { var mw = new MainWindow(); mw.Show(); Close(); } }
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( ); }