private async void LoginBtnClick(object sender, RoutedEventArgs e) { try { Spinner.Work(); UserForm.Password = Password.Password; if (!isLogin) { UserForm.ConfirmPassword = ConfirmPassword.Password; await TwatsAppService.Register(UserForm, HandleRegisterError); } await TwatsAppService.Login(UserForm, HandleLoginError); DialogResult = true; Close(); } catch (LoginException) { } catch (Exception ex) { AlertLabel.Visibility = Visibility.Visible; AlertContent.Text = ex.Message; } finally { Spinner.Stop(); } }
/// <summary> /// Authenticates the user, if it is his first launch it will take him to login screen /// else, it would authenticate based on Properties.settings.default /// </summary> /// <returns> a boolean indicating if the user successfully logged in</returns> private async Task <bool> Authenticate() { NoRefresh = true; try { if (HasAllSettings()) { await TwatsAppService.Login(new AccountBindingModel { UserName = Properties.Settings.Default.Username, Password = Properties.Settings.Default.Password }, ex => { throw new LoginException(); }); NoRefresh = false; return(true); } return(RequestLoginInNewWindow()); } catch (LoginException) { return(RequestLoginInNewWindow()); } }