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,7 +75,11 @@ namespace GreenshotPhotobucketPlugin {
|
|||
}
|
||||
|
||||
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) {
|
||||
yield break;
|
||||
|
|
|
@ -47,8 +47,10 @@ namespace GreenshotPhotobucketPlugin {
|
|||
albumPath = "!";
|
||||
}
|
||||
|
||||
OAuthSession oAuth = createSession();
|
||||
|
||||
OAuthSession oAuth = createSession(true);
|
||||
if (oAuth == null) {
|
||||
return null;
|
||||
}
|
||||
IDictionary<string, object> signedParameters = new Dictionary<string, object>();
|
||||
// add album
|
||||
if (albumPath == null) {
|
||||
|
@ -83,6 +85,9 @@ namespace GreenshotPhotobucketPlugin {
|
|||
config.TokenSecret = oAuth.TokenSecret;
|
||||
}
|
||||
}
|
||||
if (responseString == null) {
|
||||
return null;
|
||||
}
|
||||
LOG.Info(responseString);
|
||||
PhotobucketInfo PhotobucketInfo = PhotobucketInfo.FromUploadResponse(responseString);
|
||||
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
|
||||
/// </summary>
|
||||
/// <returns>OAuthSession</returns>
|
||||
private static OAuthSession createSession() {
|
||||
private static OAuthSession createSession(bool autoLogin) {
|
||||
OAuthSession oAuth = new OAuthSession(PhotobucketCredentials.ConsumerKey, PhotobucketCredentials.ConsumerSecret);
|
||||
oAuth.AutoLogin = autoLogin;
|
||||
oAuth.CheckVerifier = false;
|
||||
// This url is configured in the Photobucket API settings in the Photobucket site!!
|
||||
oAuth.CallbackUrl = "http://getgreenshot.org";
|
||||
|
@ -108,6 +114,9 @@ namespace GreenshotPhotobucketPlugin {
|
|||
|
||||
oAuth.LoginTitle = "Photobucket authorization";
|
||||
if (string.IsNullOrEmpty(config.SubDomain) || string.IsNullOrEmpty(config.Token) || string.IsNullOrEmpty(config.Username)) {
|
||||
if (!autoLogin) {
|
||||
return null;
|
||||
}
|
||||
if (!oAuth.Authorize()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -140,8 +149,10 @@ namespace GreenshotPhotobucketPlugin {
|
|||
}
|
||||
string responseString;
|
||||
|
||||
OAuthSession oAuth = createSession();
|
||||
|
||||
OAuthSession oAuth = createSession(false);
|
||||
if (oAuth == null) {
|
||||
return null;
|
||||
}
|
||||
IDictionary<string, object> signedParameters = new Dictionary<string, object>();
|
||||
try {
|
||||
string apiUrl = string.Format("http://api.photobucket.com/album/{0}", config.Username);
|
||||
|
@ -157,6 +168,9 @@ namespace GreenshotPhotobucketPlugin {
|
|||
config.TokenSecret = oAuth.TokenSecret;
|
||||
}
|
||||
}
|
||||
if (responseString == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(responseString);
|
||||
|
|
|
@ -192,6 +192,11 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
}
|
||||
|
||||
public bool AutoLogin {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
@ -206,6 +211,7 @@ namespace GreenshotPlugin.Core {
|
|||
this.RequestTokenMethod = HTTPMethod.GET;
|
||||
this.AccessTokenMethod = HTTPMethod.GET;
|
||||
this.SignatureType = OAuthSignatureTypes.HMACSHA1;
|
||||
this.AutoLogin = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -307,7 +313,7 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
Sign(RequestTokenMethod, RequestTokenUrl, parameters);
|
||||
string response = MakeRequest(RequestTokenMethod, RequestTokenUrl, null, parameters, null);
|
||||
if (response.Length > 0) {
|
||||
if (response != null && response.Length > 0) {
|
||||
response = NetworkHelper.UrlDecode(response);
|
||||
LOG.DebugFormat("Request token response: {0}", response);
|
||||
requestTokenResponseParameters = NetworkHelper.ParseQueryString(response);
|
||||
|
@ -366,7 +372,7 @@ namespace GreenshotPlugin.Core {
|
|||
IDictionary<string, object> parameters = new Dictionary<string, object>();
|
||||
Sign(AccessTokenMethod, AccessTokenUrl, parameters);
|
||||
string response = MakeRequest(AccessTokenMethod, AccessTokenUrl, null, parameters, null);
|
||||
if (response.Length > 0) {
|
||||
if (response != null && response.Length > 0) {
|
||||
response = NetworkHelper.UrlDecode(response);
|
||||
LOG.DebugFormat("Access token response: {0}", response);
|
||||
accessTokenResponseParameters = NetworkHelper.ParseQueryString(response);
|
||||
|
@ -480,7 +486,7 @@ namespace GreenshotPlugin.Core {
|
|||
while (retries-- > 0) {
|
||||
// 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 (!Authorize()) {
|
||||
if (!AutoLogin || !Authorize()) {
|
||||
throw new Exception("Not authorized");
|
||||
}
|
||||
}
|
||||
|
@ -709,10 +715,16 @@ namespace GreenshotPlugin.Core {
|
|||
webRequest.ContentLength = 0;
|
||||
}
|
||||
|
||||
string responseData = NetworkHelper.GetResponse(webRequest);
|
||||
string responseData = null;
|
||||
try {
|
||||
responseData = NetworkHelper.GetResponse(webRequest);
|
||||
LOG.DebugFormat("Response: {0}", responseData);
|
||||
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Couldn't retrieve response: ", ex);
|
||||
throw;
|
||||
} finally {
|
||||
webRequest = null;
|
||||
}
|
||||
|
||||
return responseData;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue