< Log me out >> >>
* HelloThere
diff --git a/tw5dropbox/mainwiki/plugins/tiddlywiki.files b/tw5dropbox/mainwiki/plugins/tiddlywiki.files
index f4d1b632f..d2f3abd74 100644
--- a/tw5dropbox/mainwiki/plugins/tiddlywiki.files
+++ b/tw5dropbox/mainwiki/plugins/tiddlywiki.files
@@ -24,6 +24,14 @@
"module-type": "macro"
}
},
+ {
+ "file": "../../plugins/loginmacro.js",
+ "fields": {
+ "title": "$:/plugins/dropbox/loginmacro.js",
+ "type": "application/javascript",
+ "module-type": "macro"
+ }
+ },
{
"file": "dropbox-main.js",
"fields": {
diff --git a/tw5dropbox/mainwiki/wiki/PageTemplate.tid b/tw5dropbox/mainwiki/wiki/PageTemplate.tid
index b622d2a4a..c146c939c 100644
--- a/tw5dropbox/mainwiki/wiki/PageTemplate.tid
+++ b/tw5dropbox/mainwiki/wiki/PageTemplate.tid
@@ -9,13 +9,8 @@ title: $:/templates/PageTemplate
{{nav{
-<<
-Not logged in
->>
-<<
-Logged in as (($:/plugins/dropbox/UserName))
-<< Log me out >>
->>
+<< << Log me in >> >>
+<< Logged in as (($:/plugins/dropbox/UserName)) - << Log me out >> >>
[[App|TiddlyWiki5 in the Sky with Dropbox]]
diff --git a/tw5dropbox/plugins/dropbox.js b/tw5dropbox/plugins/dropbox.js
index f94bc3d70..7e37154f7 100644
--- a/tw5dropbox/plugins/dropbox.js
+++ b/tw5dropbox/plugins/dropbox.js
@@ -20,6 +20,9 @@ var titleIsLoggedIn = "$:/plugins/dropbox/IsLoggedIn",
titleUserName = "$:/plugins/dropbox/UserName",
titlePublicAppUrl = "$:/plugins/dropbox/PublicAppUrl";
+// Query string marker for forcing authentication
+var queryLoginMarker = "login=true";
+
$tw.plugins.dropbox = {
client: null // Dropbox.js client object
};
@@ -72,6 +75,8 @@ $tw.plugins.dropbox.logout = function() {
// Mark us as logged out
$tw.wiki.deleteTiddler(titleUserName);
$tw.wiki.addTiddler({title: titleIsLoggedIn, text: "no"},true);
+ // Remove any marker from the query string
+ document.location.search = "";
});
};
@@ -87,7 +92,7 @@ $tw.plugins.dropbox.loadWikiFiles = function(path,callback) {
var stat = stats[s];
if(!stat.isFile && stat.isFolder) {
var url = $tw.plugins.dropbox.userInfo.publicAppUrl + stat.path + "/index.html";
- $tw.wiki.addTiddler({title: stat.name, text: "wiki", tags: ["wiki"], urlView: url, urlEdit: url + "?edit=true"});
+ $tw.wiki.addTiddler({title: stat.name, text: "wiki", tags: ["wiki"], urlView: url, urlEdit: url + "?login=true"});
}
}
callback();
@@ -213,6 +218,13 @@ $tw.plugins.dropbox.base64EncodeString = function(data) {
return base64.join("");
};
+// Rewrite the document location to include a force login marker
+$tw.plugins.dropbox.forceLogin = function() {
+ if(document.location.search.indexOf(queryLoginMarker) === -1) {
+ document.location.search = queryLoginMarker;
+ }
+};
+
exports.startup = function() {
if(!$tw.browser) {
return;
@@ -223,8 +235,10 @@ exports.startup = function() {
$tw.plugins.dropbox.client = new Dropbox.Client({key: apiKey, sandbox: true});
// Use the basic redirection authentication driver
$tw.plugins.dropbox.client.authDriver(new Dropbox.Drivers.Redirect({rememberUser: true}));
- // Authenticate ourselves
- $tw.plugins.dropbox.login();
+ // Authenticate ourselves if the marker is in the document query string
+ if(document.location.search.indexOf(queryLoginMarker) !== -1) {
+ $tw.plugins.dropbox.login();
+ }
};
})();
diff --git a/tw5dropbox/plugins/loginmacro.js b/tw5dropbox/plugins/loginmacro.js
new file mode 100644
index 000000000..753abf21b
--- /dev/null
+++ b/tw5dropbox/plugins/loginmacro.js
@@ -0,0 +1,41 @@
+/*\
+title: $:/plugins/dropbox/logoutmacro.js
+type: application/javascript
+module-type: macro
+
+Dropbox login plugin
+
+\*/
+(function(){
+
+/*jslint node: true, browser: true */
+/*global $tw: false */
+"use strict";
+
+exports.info = {
+ name: "dropbox.login",
+ params: {}
+};
+
+exports.handleEvent = function (event) {
+ if(event.type === "click") {
+ $tw.plugins.dropbox.forceLogin();
+ }
+};
+
+exports.executeMacro = function() {
+ // Create the link
+ var child = $tw.Tree.Element(
+ "a",
+ null,
+ this.content,
+ {
+ events: ["click"],
+ eventHandler: this
+ }
+ );
+ child.execute(this.parents,this.tiddlerTitle);
+ return child;
+};
+
+})();
diff --git a/tw5dropbox/plugins/logoutmacro.js b/tw5dropbox/plugins/logoutmacro.js
index 7e3957b32..0757fa138 100644
--- a/tw5dropbox/plugins/logoutmacro.js
+++ b/tw5dropbox/plugins/logoutmacro.js
@@ -38,6 +38,4 @@ exports.executeMacro = function() {
return child;
};
-
-
})();