Twitter auth works now

This commit is contained in:
Jaex 2015-04-28 04:33:53 +03:00
parent 842b8139cb
commit 33065a8b78
4 changed files with 5755 additions and 1385 deletions

View file

@ -3182,6 +3182,7 @@ private void InitializeComponent()
//
resources.ApplyResources(this.txtTwitterDescription, "txtTwitterDescription");
this.txtTwitterDescription.Name = "txtTwitterDescription";
this.txtTwitterDescription.TextChanged += new System.EventHandler(this.txtTwitterDescription_TextChanged);
//
// atcImgurAccountType
//
@ -3339,9 +3340,11 @@ private void InitializeComponent()
// oauthTwitter
//
resources.ApplyResources(this.oauthTwitter, "oauthTwitter");
this.oauthTwitter.IsRefreshable = false;
this.oauthTwitter.Name = "oauthTwitter";
this.oauthTwitter.OpenButtonClicked += new ShareX.UploadersLib.OAuthControl.OpenButtonClickedEventHandler(this.oauthTwitter_OpenButtonClicked);
this.oauthTwitter.CompleteButtonClicked += new ShareX.UploadersLib.OAuthControl.CompleteButtonClickedEventHandler(this.oauthTwitter_CompleteButtonClicked);
this.oauthTwitter.ClearButtonClicked += new ShareX.UploadersLib.OAuthControl.ClearButtonclickedEventHandler(this.oauthTwitter_ClearButtonClicked);
//
// actRapidShareAccountType
//

View file

@ -34,6 +34,7 @@ You should have received a copy of the GNU General Public License
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace ShareX.UploadersLib
@ -606,16 +607,16 @@ private void oauth2Imgur_CompleteButtonClicked(string code)
ImgurAuthComplete(code);
}
private void oauth2Imgur_RefreshButtonClicked()
{
ImgurAuthRefresh();
}
private void oauth2Imgur_ClearButtonClicked()
{
Config.ImgurOAuth2Info = null;
}
private void oauth2Imgur_RefreshButtonClicked()
{
ImgurAuthRefresh();
}
private void atcImgurAccountType_AccountTypeChanged(AccountType accountType)
{
Config.ImgurAccountType = accountType;
@ -2111,25 +2112,7 @@ private void llAdflyLink_LinkClicked(object sender, LinkLabelLinkClickedEventArg
#region Twitter
private bool TwitterUpdateSelected()
{
Config.TwitterSelectedAccount = lbTwitterAccounts.SelectedIndex;
if (Config.TwitterSelectedAccount > -1)
{
OAuthInfo oauth = lbTwitterAccounts.SelectedItem as OAuthInfo;
if (oauth != null)
{
txtTwitterDescription.Text = oauth.Description;
oauthTwitter.Enabled = true;
return true;
}
}
oauthTwitter.Enabled = false;
return false;
}
private bool twitterUpdatingDescription;
private void btnTwitterAdd_Click(object sender, EventArgs e)
{
@ -2161,7 +2144,30 @@ private void btnTwitterRemove_Click(object sender, EventArgs e)
private void lbTwitterAccounts_SelectedIndexChanged(object sender, EventArgs e)
{
TwitterUpdateSelected();
if (!twitterUpdatingDescription)
{
TwitterUpdateSelected();
}
}
private void txtTwitterDescription_TextChanged(object sender, EventArgs e)
{
OAuthInfo oauth = GetSelectedTwitterAccount();
if (oauth != null)
{
oauth.Description = txtTwitterDescription.Text;
try
{
twitterUpdatingDescription = true;
lbTwitterAccounts.Items[lbTwitterAccounts.SelectedIndex] = lbTwitterAccounts.SelectedItem;
}
finally
{
twitterUpdatingDescription = false;
}
}
}
private void oauthTwitter_OpenButtonClicked()
@ -2171,7 +2177,12 @@ private void oauthTwitter_OpenButtonClicked()
private void oauthTwitter_CompleteButtonClicked(string code)
{
TwitterAuthComplete();
TwitterAuthComplete(code);
}
private void oauthTwitter_ClearButtonClicked()
{
TwitterAuthClear();
}
#endregion Twitter

File diff suppressed because it is too large Load diff

View file

@ -44,7 +44,7 @@ public partial class UploadersConfigForm
{
#region Imgur
public void ImgurAuthOpen()
private void ImgurAuthOpen()
{
try
{
@ -69,7 +69,7 @@ public void ImgurAuthOpen()
}
}
public void ImgurAuthComplete(string code)
private void ImgurAuthComplete(string code)
{
try
{
@ -86,7 +86,6 @@ public void ImgurAuthComplete(string code)
{
oauth2Imgur.Status = OAuthLoginStatus.LoginFailed;
MessageBox.Show(Resources.UploadersConfigForm_Login_failed, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
atcImgurAccountType.SelectedAccountType = AccountType.Anonymous;
}
btnImgurRefreshAlbumList.Enabled = result;
@ -98,7 +97,7 @@ public void ImgurAuthComplete(string code)
}
}
public void ImgurAuthRefresh()
private void ImgurAuthRefresh()
{
try
{
@ -127,7 +126,7 @@ public void ImgurAuthRefresh()
}
}
public void ImgurRefreshAlbumList()
private void ImgurRefreshAlbumList()
{
try
{
@ -1448,53 +1447,123 @@ public void PushbulletGetDevices()
#region Twitter
public bool CheckTwitterAccounts()
private OAuthInfo GetSelectedTwitterAccount()
{
return Config.TwitterOAuthInfoList.ReturnIfValidIndex(Config.TwitterSelectedAccount);
}
private bool CheckTwitterAccounts()
{
return Config.TwitterOAuthInfoList.IsValidIndex(Config.TwitterSelectedAccount);
}
public void TwitterAuthOpen()
private bool TwitterUpdateSelected()
{
Config.TwitterSelectedAccount = lbTwitterAccounts.SelectedIndex;
if (Config.TwitterSelectedAccount > -1)
{
OAuthInfo oauth = lbTwitterAccounts.SelectedItem as OAuthInfo;
if (oauth != null)
{
txtTwitterDescription.Text = oauth.Description;
oauthTwitter.Enabled = true;
if (OAuthInfo.CheckOAuth(oauth))
{
oauthTwitter.Status = OAuthLoginStatus.LoginSuccessful;
}
else
{
oauthTwitter.Status = OAuthLoginStatus.LoginRequired;
}
return true;
}
}
txtTwitterDescription.Text = string.Empty;
oauthTwitter.Enabled = false;
return false;
}
private void TwitterAuthOpen()
{
if (CheckTwitterAccounts())
{
OAuthInfo acc = new OAuthInfo(APIKeys.TwitterConsumerKey, APIKeys.TwitterConsumerSecret);
Twitter twitter = new Twitter(acc);
string url = twitter.GetAuthorizationURL();
if (!string.IsNullOrEmpty(url))
try
{
acc.Description = Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount].Description;
Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount] = acc;
//ucTwitterAccounts.pgSettings.SelectedObject = acc;
URLHelpers.OpenURL(url);
//btnTwitterLogin.Enabled = true;
OAuthInfo oauth = new OAuthInfo(APIKeys.TwitterConsumerKey, APIKeys.TwitterConsumerSecret);
string url = new Twitter(oauth).GetAuthorizationURL();
if (!string.IsNullOrEmpty(url))
{
oauth.Description = Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount].Description;
Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount] = oauth;
lbTwitterAccounts.Items[Config.TwitterSelectedAccount] = oauth;
URLHelpers.OpenURL(url);
DebugHelper.WriteLine("TwitterAuthOpen - Authorization URL is opened: " + url);
}
else
{
DebugHelper.WriteLine("TwitterAuthOpen - Authorization URL is empty.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), Resources.UploadersConfigForm_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
public void TwitterAuthComplete()
private void TwitterAuthComplete(string code)
{
if (CheckTwitterAccounts())
{
OAuthInfo acc = Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount];
if (acc != null && !string.IsNullOrEmpty(acc.AuthToken) && !string.IsNullOrEmpty(acc.AuthSecret) && !string.IsNullOrEmpty(acc.AuthVerifier))
try
{
Twitter twitter = new Twitter(acc);
bool result = twitter.GetAccessToken(acc.AuthVerifier);
OAuthInfo oauth = GetSelectedTwitterAccount();
if (result)
if (oauth != null && !string.IsNullOrEmpty(oauth.AuthToken) && !string.IsNullOrEmpty(oauth.AuthSecret))
{
acc.AuthVerifier = string.Empty;
Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount] = acc;
//ucTwitterAccounts.pgSettings.SelectedObject = acc;
MessageBox.Show(Resources.UploadersConfigForm_Login_successful, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(Resources.UploadersConfigForm_Login_failed, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
bool result = new Twitter(oauth).GetAccessToken(code);
if (result)
{
oauth.AuthVerifier = string.Empty;
oauthTwitter.Status = OAuthLoginStatus.LoginSuccessful;
MessageBox.Show(Resources.UploadersConfigForm_Login_successful, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
oauthTwitter.Status = OAuthLoginStatus.LoginFailed;
MessageBox.Show(Resources.UploadersConfigForm_Login_failed, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), Resources.UploadersConfigForm_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void TwitterAuthClear()
{
if (CheckTwitterAccounts())
{
OAuthInfo oauth = new OAuthInfo();
OAuthInfo oauth2 = GetSelectedTwitterAccount();
if (oauth2 != null)
{
oauth.Description = oauth2.Description;
}
Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount] = oauth;
}
}