Merge pull request #202 from tempelmann/storage
Fixes Dropbox authentication
This commit is contained in:
+6
-6
@@ -18,12 +18,12 @@ var CONFIG = {
|
|||||||
/*
|
/*
|
||||||
* The key below needs to be set individually by you if you want to use the Dropbox load/save feature.
|
* The key below needs to be set individually by you if you want to use the Dropbox load/save feature.
|
||||||
* To do that, first sign up with Dropbox (may require a specific developer / SDK sign-up), go to
|
* To do that, first sign up with Dropbox (may require a specific developer / SDK sign-up), go to
|
||||||
* https://www.dropbox.com/developers/apps and use "Create app" to add a new app. Call it, for instance,
|
* https://www.dropbox.com/developers/apps and use "Create app" to add a new "Dropbox API app".
|
||||||
* "wwwsqldesigner", and give it the "App Folder" permission. Unter "OAuth 2", "Redirect URIs", add
|
* Limit the app to its own folder. Call it, for instance, "wwwsqldesigner".
|
||||||
* the URL to the "dropbox-oauth-receiver.html" file on your server. E.g, if you install wwwsqldesigner
|
* Under "OAuth 2", "Redirect URIs", add the URL to the "dropbox-oauth-receiver.html" file on your server.
|
||||||
* on your local web server under "http://localhost/sqldesigner/", then add
|
* E.g, if you install wwwsqldesigner on your local web server under "http://localhost/sqldesigner/", then add
|
||||||
* http://localhost/sqldesigner/dropbox-oauth-receiver.html as a Redirection URI.
|
* http://localhost/sqldesigner/dropbox-oauth-receiver.html as a Redirection URI.
|
||||||
* Copy the shown "App key" and paste it here below:
|
* Copy the shown "App key" and paste it here below instead of the null value:
|
||||||
*/
|
*/
|
||||||
DROPBOX_KEY: null // "your app key";
|
DROPBOX_KEY: null // such as: "d6stdscwewhl6sa"
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-49
@@ -27,7 +27,8 @@ SQL.Storage.Dropbox.prototype.showDropboxError = function(error) {
|
|||||||
// If you're using dropbox.js, the only cause behind this error is that
|
// If you're using dropbox.js, the only cause behind this error is that
|
||||||
// the user token expired.
|
// the user token expired.
|
||||||
// Get the user through the authentication flow again.
|
// Get the user through the authentication flow again.
|
||||||
msg = _("Invalid Token (expired)");
|
msg = _("Token expired - retry the operation, authenticating again with Dropbox");
|
||||||
|
this.dropboxClient.reset();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Dropbox.ApiError.NOT_FOUND:
|
case Dropbox.ApiError.NOT_FOUND:
|
||||||
@@ -62,61 +63,67 @@ SQL.Storage.Dropbox.prototype.showDropboxError = function(error) {
|
|||||||
// Tell the user an error occurred, ask them to refresh the page.
|
// Tell the user an error occurred, ask them to refresh the page.
|
||||||
}
|
}
|
||||||
|
|
||||||
alert(prefix+msg);
|
alert (prefix+msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
SQL.Storage.Dropbox.prototype.showDropboxAuthenticate = function() {
|
SQL.Storage.Dropbox.prototype.authenticate = function(connectedCallBack) {
|
||||||
if (!this.dropboxClient) return false;
|
if (!this.dropboxClient) return false;
|
||||||
|
|
||||||
// We want to use a popup window for authentication as the default redirection won't work for us as it'll make us lose our schema data
|
// We want to use a popup window for authentication as the default redirection
|
||||||
this.dropboxClient.authDriver(new Dropbox.AuthDriver.Popup({ receiverUrl: "dropbox-oauth-receiver.html" }));
|
// won't work for us as it'll make us lose our schema data
|
||||||
|
var href = window.location.href;
|
||||||
|
var prefix = href.substring(0, href.lastIndexOf("/")) + "/";
|
||||||
|
this.dropboxClient.authDriver(new Dropbox.AuthDriver.Popup({ receiverUrl: prefix+"dropbox-oauth-receiver.html" }));
|
||||||
|
|
||||||
// Now let's authenticate us
|
// Now let's authenticate us
|
||||||
var success = false;
|
var us = this;
|
||||||
this.dropboxClient.authenticate( function(error, client) {
|
this.dropboxClient.authenticate( function(error, client) {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showDropboxError(error);
|
us.showDropboxError(error);
|
||||||
return;
|
} else {
|
||||||
|
// We're authenticated
|
||||||
|
connectedCallBack();
|
||||||
}
|
}
|
||||||
success = true;
|
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
return success;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SQL.Storage.Dropbox.prototype._save = function(keyword) {
|
SQL.Storage.Dropbox.prototype._save = function(keyword) {
|
||||||
if (!this.showDropboxAuthenticate()) return;
|
var us = this;
|
||||||
|
us.authenticate( function() {
|
||||||
|
var xml = us.owner.owner.toXML();
|
||||||
|
var filename = keyword + ".xml";
|
||||||
|
us.owner.owner.window.showThrobber();
|
||||||
|
|
||||||
var xml = this.owner.owner.toXML();
|
us.dropboxClient.writeFile(filename, xml, function(error, stat) {
|
||||||
var filename = keyword + ".xml";
|
us.owner.owner.window.hideThrobber();
|
||||||
this.owner.owner.window.showThrobber();
|
if (error) {
|
||||||
|
us.showDropboxError(error);
|
||||||
this.dropboxClient.writeFile(filename, xml, function(error, stat) {
|
} else {
|
||||||
this.owner.owner.window.hideThrobber();
|
us._keyword = keyword;
|
||||||
if (error) {
|
us.owner.getArea().value = filename+" "+_("was saved to Dropbox");
|
||||||
this.showDropboxError(error);
|
}
|
||||||
} else {
|
}.bind(us));
|
||||||
this._keyword = keyword;
|
});
|
||||||
this.owner.getArea().value = filename+" "+_("was saved to Dropbox");
|
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SQL.Storage.Dropbox.prototype._load = function(keyword) {
|
SQL.Storage.Dropbox.prototype._load = function(keyword) {
|
||||||
if (!this.showDropboxAuthenticate()) return;
|
var us = this;
|
||||||
|
us.authenticate( function() {
|
||||||
|
var filename = keyword + ".xml";
|
||||||
|
us.owner.owner.window.showThrobber();
|
||||||
|
|
||||||
var filename = keyword + ".xml";
|
us.dropboxClient.readFile(filename, function(error, data) {
|
||||||
this.owner.owner.window.showThrobber();
|
us.owner.owner.window.hideThrobber();
|
||||||
|
if (error) {
|
||||||
this.dropboxClient.readFile(filename, function(error, data) {
|
us.showDropboxError(error);
|
||||||
this.owner.owner.window.hideThrobber();
|
} else {
|
||||||
if (error) {
|
us.owner.fromXMLText(data);
|
||||||
this.showDropboxError(error);
|
us._keyword = keyword;
|
||||||
} else {
|
}
|
||||||
this.owner.fromXMLText(data);
|
}.bind(us));
|
||||||
this._keyword = keyword;
|
});
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SQL.Storage.Dropbox.prototype._clickSave = function(e) {
|
SQL.Storage.Dropbox.prototype._clickSave = function(e) {
|
||||||
@@ -132,15 +139,16 @@ SQL.Storage.Dropbox.prototype._clickLoad = function(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SQL.Storage.Dropbox.prototype._clickList = function(e) {
|
SQL.Storage.Dropbox.prototype._clickList = function(e) {
|
||||||
if (!this.showDropboxAuthenticate()) return;
|
var us = this;
|
||||||
|
us.authenticate( function() {
|
||||||
this.owner.owner.window.showThrobber();
|
us.owner.owner.window.showThrobber();
|
||||||
this.dropboxClient.readdir("/", function(error, entries) {
|
us.dropboxClient.readdir("/", function(error, entries) {
|
||||||
this.owner.owner.window.hideThrobber();
|
us.owner.owner.window.hideThrobber();
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showDropboxError(error);
|
us.showDropboxError(error);
|
||||||
} else {
|
} else {
|
||||||
this.owner.getArea().value = entries.join("\n")+"\n"
|
us.owner.getArea().value = entries.join("\n")+"\n"
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(us));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user