summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorThomas Tempelmann <tempelmann@gmail.com>2015-06-16 11:42:36 +0200
committerThomas Tempelmann <tempelmann@gmail.com>2015-06-16 11:42:36 +0200
commit114f122186451d57aa490af554d84fd092e2dd2b (patch)
treef52a77d66444437b1fc668479c5f4c80c93a621c /js
parent580311c8b421992389cef82fb74fd99182c0d1c7 (diff)
downloadwwwsqldesigner-114f122186451d57aa490af554d84fd092e2dd2b.zip
wwwsqldesigner-114f122186451d57aa490af554d84fd092e2dd2b.tar.gz
wwwsqldesigner-114f122186451d57aa490af554d84fd092e2dd2b.tar.bz2
Fixes Dropbox authentication (now calling reset() when needed, and properly done asynchronously)
Diffstat (limited to 'js')
-rw-r--r--js/config.js12
-rw-r--r--js/io.js97
2 files changed, 57 insertions, 52 deletions
diff --git a/js/config.js b/js/config.js
index a3b372a..afcd8b0 100644
--- a/js/config.js
+++ b/js/config.js
@@ -18,13 +18,13 @@ var CONFIG = {
/*
* 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
- * https://www.dropbox.com/developers/apps and use "Create app" to add a new app. Call it, for instance,
- * "wwwsqldesigner", and give it the "App Folder" permission. Unter "OAuth 2", "Redirect URIs", add
- * the URL to the "dropbox-oauth-receiver.html" file on your server. E.g, if you install wwwsqldesigner
- * on your local web server under "http://localhost/sqldesigner/", then add
+ * https://www.dropbox.com/developers/apps and use "Create app" to add a new "Dropbox API app".
+ * Limit the app to its own folder. Call it, for instance, "wwwsqldesigner".
+ * Under "OAuth 2", "Redirect URIs", add the URL to the "dropbox-oauth-receiver.html" file on your server.
+ * 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.
- * 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"
}
diff --git a/js/io.js b/js/io.js
index facbb78..1a6ef58 100644
--- a/js/io.js
+++ b/js/io.js
@@ -250,7 +250,8 @@ SQL.IO.prototype.showDropboxError = function(error) {
// If you're using dropbox.js, the only cause behind this error is that
// the user token expired.
// 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;
case Dropbox.ApiError.NOT_FOUND:
@@ -288,76 +289,80 @@ SQL.IO.prototype.showDropboxError = function(error) {
alert (prefix+msg);
};
-SQL.IO.prototype.showDropboxAuthenticate = function() {
+SQL.IO.prototype.showDropboxAuthenticate = function(connectedCallBack) {
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
- this.dropboxClient.authDriver(new Dropbox.AuthDriver.Popup({ receiverUrl: "dropbox-oauth-receiver.html" }));
+ 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
- var success = false;
- this.dropboxClient.authenticate( function(error, client) {
+ var sql_io = this;
+ sql_io.dropboxClient.authenticate( function(error, client) {
if (error) {
- this.showDropboxError(error);
- return;
+ sql_io.showDropboxError(error);
+ } else {
+ // We're authenticated
+ connectedCallBack();
}
- success = true;
return;
});
- return success;
+
+ return true;
}
SQL.IO.prototype.dropboxsave = function() {
- if (!this.showDropboxAuthenticate()) return;
-
- var key = this.promptName("serversaveprompt", ".xml");
- if (!key) { return; }
+ var sql_io = this;
+ sql_io.showDropboxAuthenticate( function() {
+ var key = sql_io.promptName("serversaveprompt", ".xml");
+ if (!key) { return; }
- var filename = (key || "default") + ".xml";
+ var filename = (key || "default") + ".xml";
- var sql_io = this;
- sql_io.listresponse("Saving...", 200);
- var xml = this.owner.toXML();
- this.dropboxClient.writeFile(filename, xml, function(error, stat) {
- if (error) {
- sql_io.listresponse("", 200);
- return this.showDropboxError(error);
- }
- sql_io.listresponse(filename+" "+_("was saved to Dropbox"), 200);
+ sql_io.listresponse("Saving...", 200);
+ var xml = sql_io.owner.toXML();
+ sql_io.dropboxClient.writeFile(filename, xml, function(error, stat) {
+ if (error) {
+ sql_io.listresponse("", 200);
+ return sql_io.showDropboxError(error);
+ }
+ sql_io.listresponse(filename+" "+_("was saved to Dropbox"), 200);
+ });
});
}
SQL.IO.prototype.dropboxload = function() {
- if (!this.showDropboxAuthenticate()) return;
-
- var key = this.promptName("serverloadprompt", ".xml");
- if (!key) { return; }
+ var sql_io = this;
+ sql_io.showDropboxAuthenticate( function() {
+ var key = sql_io.promptName("serverloadprompt", ".xml");
+ if (!key) { return; }
- var filename = (key || "default") + ".xml";
+ var filename = (key || "default") + ".xml";
- var sql_io = this;
- sql_io.listresponse("Loading...", 200);
- this.dropboxClient.readFile(filename, function(error, data) {
- sql_io.listresponse("", 200);
- if (error) {
- return this.showDropboxError(error);
- }
- sql_io.fromXMLText(data);
+ sql_io.listresponse("Loading...", 200);
+ sql_io.dropboxClient.readFile(filename, function(error, data) {
+ sql_io.listresponse("", 200);
+ if (error) {
+ return sql_io.showDropboxError(error);
+ }
+ sql_io.fromXMLText(data);
+ });
});
}
SQL.IO.prototype.dropboxlist = function() {
- if (!this.showDropboxAuthenticate()) return;
-
var sql_io = this;
- sql_io.listresponse("Loading...", 200);
- this.dropboxClient.readdir("/", function(error, entries) {
- if (error) {
- sql_io.listresponse("", 200);
- return this.showDropboxError(error);
- }
- var data = entries.join("\n")+"\n";
- sql_io.listresponse(data, 200);
+ sql_io.showDropboxAuthenticate( function() {
+ sql_io.listresponse("Loading...", 200);
+ sql_io.dropboxClient.readdir("/", function(error, entries) {
+ if (error) {
+ sql_io.listresponse("", 200);
+ return sql_io.showDropboxError(error);
+ }
+ var data = entries.join("\n")+"\n";
+ sql_io.listresponse(data, 200);
+ });
});
}