private void btnAddTwitterPin_Click(object sender, System.Windows.RoutedEventArgs e) { try { OAuthTokenResponse authToken = OAuthUtility.GetAccessToken(_consumerKey, _consumerSecret, _requestToken.Token, txtTwitterOauthPin.Text); accessTokenToken = authToken.Token; accessTokenSecret = authToken.TokenSecret; } catch (Exception e1) { MessageBox.Show(e1.Message + "Can't build access token"); } try { if (ConfigurationManager.AuthenticateUser()) { //MessageBox.Show("Utilizador autenticado"); if (_accountId > -1 && ConfigurationManager.UserAccountExists(this._accountId)) { Account account = ConfigurationManager.GetUserAccount(this._accountId); account.Name = txtTwitterAccountName.Text; account.Enabled = cbTwitterAccountEnabled.IsChecked.Value; } else { Account twitterAccount = new Account(); twitterAccount.Type = Account.TWITTERTYPE; twitterAccount.Name = txtTwitterAccountName.Text; twitterAccount.Enabled = cbTwitterAccountEnabled.IsChecked.Value; twitterAccount.addOption("username", txtTwitterUsername.Text); twitterAccount.addOption("accessTokenToken", accessTokenToken); twitterAccount.addOption("accessTokenSecret", ConfigurationManager.AuthenticatedUser.Encrypt(accessTokenSecret)); ConfigurationManager.AddUserAccount(twitterAccount); MessageBox.Show("Account added with sucess", "Information"); } if (this._parentWindow != null) { this._parentWindow.CancelTwitterAccountEdit(); } } else { MessageBox.Show("No user logged in"); } } catch (Exception) { MessageBox.Show("User Can not be added", "Warning"); } }
// authenticate the user private void btnLogin_Click(object sender, System.Windows.RoutedEventArgs e) { if (ConfigurationManager.AuthenticateUser(txtLoginUsername.Text, pbLoginPassword.Password, (Boolean)cbRememberLogin.IsChecked)) { GetUnifiedAccounts(this, null); ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, MainAppState.Name, true); txtWelcome.Content = "Welcome, " + txtLoginUsername.Text; txtLoginUsername.Text = ""; pbLoginPassword.Password = ""; } else { MessageBox.Show("Authentication failed for user " + txtLoginUsername.Text, "Authentication failed", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// On application start /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loginWindow_Initialized(object sender, System.EventArgs e) { try { // if we can authenticate the default user, skip to the application directly if (ConfigurationManager.AuthenticateUser()) { GetUnifiedAccounts(this, null); ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, MainAppState.Name, true); txtWelcome.Content = "Welcome, " + ConfigurationManager.AuthenticatedUser.Username; } else { ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, LoginState.Name, true); Keyboard.Focus(txtLoginUsername); } } catch (Exception exception) { MessageBox.Show(String.Format(Properties.Resources.ErrorOccurred, exception.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }