コード例 #1
0
ファイル: AccountInfoForm.cs プロジェクト: enersia/pocketwit
        private void menuItem2_Click(object sender, EventArgs e)
        {
            lblError.Visible = false;

            if (cmbServers.SelectedItem == null)
            {
                return;
            }
            Application.DoEvents();
            Cursor.Current = Cursors.WaitCursor; //doesn't appear to be shown.

            lblError.Visible = false;
            _AccountInfo.UserName = txtUserName.Text;
            _AccountInfo.Password = txtPassword.Text;
            _AccountInfo.ServerURL = Yedda.Servers.ServerList[(string)cmbServers.SelectedItem];
            _AccountInfo.Enabled = true;
            _AccountInfo.IsDefault = chkDefault.Checked;
            Yedda.Twitter T = Yedda.Servers.CreateConnection(_AccountInfo);

            if ((string)cmbServers.SelectedItem == "twitter")
            {
                OAuthAuthorizer authorizer = new OAuthAuthorizer();

                if ((!string.IsNullOrEmpty(_AccountInfo.OAuth_token_secret) || string.IsNullOrEmpty(txtPassword.Text))
                    && !cbRevalidate.Checked )
                {
                    //No need to verify without when no password is passed and token is still set.
                    Cursor.Current = Cursors.Default;
                    this.DialogResult = DialogResult.OK;
                    return;
                }

                if (string.IsNullOrEmpty(txtUserName.Text))
                {
                    lblError.Text = "Please enter a username for this account.";
                    lblError.Visible = true;
                    Cursor.Current = Cursors.Default;
                    return;
                }
                if (string.IsNullOrEmpty(txtPassword.Text))
                {
                    lblError.Text = "Please enter a password for authorizing.";
                    lblError.Visible = true;
                    Cursor.Current = Cursors.Default;
                    return;
                }
                if (!authorizer.AcquireXAuth(txtUserName.Text, txtPassword.Text))
                {
                    lblError.Text = "Unable to authorize. Wrong credentials or no connection?";
                    lblError.Visible = true;
                    Cursor.Current = Cursors.Default;
                    return;
                }

                _AccountInfo.OAuth_token = authorizer.AccessToken;
                _AccountInfo.OAuth_token_secret = authorizer.AccessTokenSecret;
                //_AccountInfo.UserName = authorizer.AccessScreenname;

                if (string.IsNullOrEmpty(_AccountInfo.OAuth_token))
                {
                    //I know, not very nice, but it reduces errors a bit.
                    Thread.Sleep(1000);
                    authorizer.AcquireXAuth(txtUserName.Text, txtPassword.Text);
                    _AccountInfo.OAuth_token = authorizer.AccessToken;
                    _AccountInfo.OAuth_token_secret = authorizer.AccessTokenSecret;

                    if (string.IsNullOrEmpty(_AccountInfo.OAuth_token))
                    {
                        lblError.Text = "Unable to get access token from Twitter.";
                        lblError.Visible = true;
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(txtUserName.Text)) { return; }
                if (!T.Verify())
                {
                    lblError.Text = "Invalid credentials or network unavailable.";
                    lblError.Visible = true;
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }

            Cursor.Current = Cursors.Default;
            this.DialogResult = DialogResult.OK;
        }
コード例 #2
0
ファイル: AccountInfoForm.cs プロジェクト: enersia/pocketwit
        private void Ll_Twitter_Click(object sender, EventArgs e)
        {
            lblError.Visible = false;

            OAuthAuthorizer authorizer = new OAuthAuthorizer();

            //request
            authorizer.AcquireRequestToken();
            RequestToken = authorizer.RequestToken;
            RequestTokenSecret = authorizer.RequestTokenSecret;

            if (string.IsNullOrEmpty(RequestToken))
            {
                Localization.LocalizedMessageBox.Show("Unable to retrieve token, try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, null);
                return; //don't try the rest...
            }

            Localization.LocalizedMessageBox.Show("Your browser will be opened to authorise PockeTwit with Twitter. Please note the pincode on the webpage.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1, null);

            //auth
            Uri url = new Uri(authorizer.CurrentConfig.AuthorizeUrl + "?oauth_token=" + RequestToken);
            urlToLaunch = url.ToString();
            Thread t = new Thread(new ThreadStart(LaunchBrowserLink));
            t.Start();
        }