mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Preventing that the Photobucket login is shown while using the Dynamic-Destination picker "mouse-over".
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2505 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
9850096c3b
commit
652ca64e9f
3 changed files with 46 additions and 16 deletions
|
@ -75,12 +75,16 @@ namespace GreenshotPhotobucketPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<IDestination> DynamicDestinations() {
|
public override IEnumerable<IDestination> DynamicDestinations() {
|
||||||
List<string> albums = PhotobucketUtils.RetrievePhotobucketAlbums();
|
List<string> albums = null;
|
||||||
|
try {
|
||||||
|
albums = PhotobucketUtils.RetrievePhotobucketAlbums();
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
|
||||||
if (albums == null || albums.Count == 0) {
|
if (albums == null || albums.Count == 0) {
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
foreach(string album in albums) {
|
foreach (string album in albums) {
|
||||||
yield return new PhotobucketDestination(plugin, album);
|
yield return new PhotobucketDestination(plugin, album);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,10 @@ namespace GreenshotPhotobucketPlugin {
|
||||||
albumPath = "!";
|
albumPath = "!";
|
||||||
}
|
}
|
||||||
|
|
||||||
OAuthSession oAuth = createSession();
|
OAuthSession oAuth = createSession(true);
|
||||||
|
if (oAuth == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
IDictionary<string, object> signedParameters = new Dictionary<string, object>();
|
IDictionary<string, object> signedParameters = new Dictionary<string, object>();
|
||||||
// add album
|
// add album
|
||||||
if (albumPath == null) {
|
if (albumPath == null) {
|
||||||
|
@ -83,6 +85,9 @@ namespace GreenshotPhotobucketPlugin {
|
||||||
config.TokenSecret = oAuth.TokenSecret;
|
config.TokenSecret = oAuth.TokenSecret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (responseString == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
LOG.Info(responseString);
|
LOG.Info(responseString);
|
||||||
PhotobucketInfo PhotobucketInfo = PhotobucketInfo.FromUploadResponse(responseString);
|
PhotobucketInfo PhotobucketInfo = PhotobucketInfo.FromUploadResponse(responseString);
|
||||||
LOG.Debug("Upload to Photobucket was finished");
|
LOG.Debug("Upload to Photobucket was finished");
|
||||||
|
@ -93,8 +98,9 @@ namespace GreenshotPhotobucketPlugin {
|
||||||
/// Helper method to create an OAuth session object for contacting the Photobucket API
|
/// Helper method to create an OAuth session object for contacting the Photobucket API
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>OAuthSession</returns>
|
/// <returns>OAuthSession</returns>
|
||||||
private static OAuthSession createSession() {
|
private static OAuthSession createSession(bool autoLogin) {
|
||||||
OAuthSession oAuth = new OAuthSession(PhotobucketCredentials.ConsumerKey, PhotobucketCredentials.ConsumerSecret);
|
OAuthSession oAuth = new OAuthSession(PhotobucketCredentials.ConsumerKey, PhotobucketCredentials.ConsumerSecret);
|
||||||
|
oAuth.AutoLogin = autoLogin;
|
||||||
oAuth.CheckVerifier = false;
|
oAuth.CheckVerifier = false;
|
||||||
// This url is configured in the Photobucket API settings in the Photobucket site!!
|
// This url is configured in the Photobucket API settings in the Photobucket site!!
|
||||||
oAuth.CallbackUrl = "http://getgreenshot.org";
|
oAuth.CallbackUrl = "http://getgreenshot.org";
|
||||||
|
@ -108,6 +114,9 @@ namespace GreenshotPhotobucketPlugin {
|
||||||
|
|
||||||
oAuth.LoginTitle = "Photobucket authorization";
|
oAuth.LoginTitle = "Photobucket authorization";
|
||||||
if (string.IsNullOrEmpty(config.SubDomain) || string.IsNullOrEmpty(config.Token) || string.IsNullOrEmpty(config.Username)) {
|
if (string.IsNullOrEmpty(config.SubDomain) || string.IsNullOrEmpty(config.Token) || string.IsNullOrEmpty(config.Username)) {
|
||||||
|
if (!autoLogin) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (!oAuth.Authorize()) {
|
if (!oAuth.Authorize()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -140,8 +149,10 @@ namespace GreenshotPhotobucketPlugin {
|
||||||
}
|
}
|
||||||
string responseString;
|
string responseString;
|
||||||
|
|
||||||
OAuthSession oAuth = createSession();
|
OAuthSession oAuth = createSession(false);
|
||||||
|
if (oAuth == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
IDictionary<string, object> signedParameters = new Dictionary<string, object>();
|
IDictionary<string, object> signedParameters = new Dictionary<string, object>();
|
||||||
try {
|
try {
|
||||||
string apiUrl = string.Format("http://api.photobucket.com/album/{0}", config.Username);
|
string apiUrl = string.Format("http://api.photobucket.com/album/{0}", config.Username);
|
||||||
|
@ -157,6 +168,9 @@ namespace GreenshotPhotobucketPlugin {
|
||||||
config.TokenSecret = oAuth.TokenSecret;
|
config.TokenSecret = oAuth.TokenSecret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (responseString == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
XmlDocument doc = new XmlDocument();
|
XmlDocument doc = new XmlDocument();
|
||||||
doc.LoadXml(responseString);
|
doc.LoadXml(responseString);
|
||||||
|
|
|
@ -191,6 +191,11 @@ namespace GreenshotPlugin.Core {
|
||||||
useHTTPHeadersForAuthorization = value;
|
useHTTPHeadersForAuthorization = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AutoLogin {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -206,6 +211,7 @@ namespace GreenshotPlugin.Core {
|
||||||
this.RequestTokenMethod = HTTPMethod.GET;
|
this.RequestTokenMethod = HTTPMethod.GET;
|
||||||
this.AccessTokenMethod = HTTPMethod.GET;
|
this.AccessTokenMethod = HTTPMethod.GET;
|
||||||
this.SignatureType = OAuthSignatureTypes.HMACSHA1;
|
this.SignatureType = OAuthSignatureTypes.HMACSHA1;
|
||||||
|
this.AutoLogin = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -307,7 +313,7 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
Sign(RequestTokenMethod, RequestTokenUrl, parameters);
|
Sign(RequestTokenMethod, RequestTokenUrl, parameters);
|
||||||
string response = MakeRequest(RequestTokenMethod, RequestTokenUrl, null, parameters, null);
|
string response = MakeRequest(RequestTokenMethod, RequestTokenUrl, null, parameters, null);
|
||||||
if (response.Length > 0) {
|
if (response != null && response.Length > 0) {
|
||||||
response = NetworkHelper.UrlDecode(response);
|
response = NetworkHelper.UrlDecode(response);
|
||||||
LOG.DebugFormat("Request token response: {0}", response);
|
LOG.DebugFormat("Request token response: {0}", response);
|
||||||
requestTokenResponseParameters = NetworkHelper.ParseQueryString(response);
|
requestTokenResponseParameters = NetworkHelper.ParseQueryString(response);
|
||||||
|
@ -317,7 +323,7 @@ namespace GreenshotPlugin.Core {
|
||||||
ret = this.Token;
|
ret = this.Token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -366,7 +372,7 @@ namespace GreenshotPlugin.Core {
|
||||||
IDictionary<string, object> parameters = new Dictionary<string, object>();
|
IDictionary<string, object> parameters = new Dictionary<string, object>();
|
||||||
Sign(AccessTokenMethod, AccessTokenUrl, parameters);
|
Sign(AccessTokenMethod, AccessTokenUrl, parameters);
|
||||||
string response = MakeRequest(AccessTokenMethod, AccessTokenUrl, null, parameters, null);
|
string response = MakeRequest(AccessTokenMethod, AccessTokenUrl, null, parameters, null);
|
||||||
if (response.Length > 0) {
|
if (response != null && response.Length > 0) {
|
||||||
response = NetworkHelper.UrlDecode(response);
|
response = NetworkHelper.UrlDecode(response);
|
||||||
LOG.DebugFormat("Access token response: {0}", response);
|
LOG.DebugFormat("Access token response: {0}", response);
|
||||||
accessTokenResponseParameters = NetworkHelper.ParseQueryString(response);
|
accessTokenResponseParameters = NetworkHelper.ParseQueryString(response);
|
||||||
|
@ -378,7 +384,7 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Token;
|
return Token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -480,7 +486,7 @@ namespace GreenshotPlugin.Core {
|
||||||
while (retries-- > 0) {
|
while (retries-- > 0) {
|
||||||
// If we are not trying to get a Authorization or Accestoken, and we don't have a token, create one
|
// If we are not trying to get a Authorization or Accestoken, and we don't have a token, create one
|
||||||
if (string.IsNullOrEmpty(Token)) {
|
if (string.IsNullOrEmpty(Token)) {
|
||||||
if (!Authorize()) {
|
if (!AutoLogin || !Authorize()) {
|
||||||
throw new Exception("Not authorized");
|
throw new Exception("Not authorized");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -709,10 +715,16 @@ namespace GreenshotPlugin.Core {
|
||||||
webRequest.ContentLength = 0;
|
webRequest.ContentLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
string responseData = NetworkHelper.GetResponse(webRequest);
|
string responseData = null;
|
||||||
LOG.DebugFormat("Response: {0}", responseData);
|
try {
|
||||||
|
responseData = NetworkHelper.GetResponse(webRequest);
|
||||||
webRequest = null;
|
LOG.DebugFormat("Response: {0}", responseData);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.Error("Couldn't retrieve response: ", ex);
|
||||||
|
throw;
|
||||||
|
} finally {
|
||||||
|
webRequest = null;
|
||||||
|
}
|
||||||
|
|
||||||
return responseData;
|
return responseData;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue