1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-03 02:33:15 +00:00

More updates to tw5dropbox

This commit is contained in:
Jeremy Ruston 2012-10-11 15:43:34 +01:00
parent d416781110
commit a4110179fc
7 changed files with 78 additions and 19 deletions

View File

@ -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-app.js",
"fields": {

View File

@ -19,13 +19,8 @@ title: $:/templates/PageTemplate
<div class="container">
{{nav{
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:no><
Not logged in
>>
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:yes><
Logged in as (($:/plugins/dropbox/UserName))
<<dropbox.logout>< Log me out >>
>>
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:no>< <<dropbox.login>< Log me in >> >>
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:yes>< Logged in as (($:/plugins/dropbox/UserName)) - <<dropbox.logout>< Log me out >> >>
<!-- Navigation menu -->
* HelloThere

View File

@ -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": {

View File

@ -9,13 +9,8 @@ title: $:/templates/PageTemplate
<div class="container">
{{nav{
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:no><
Not logged in
>>
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:yes><
Logged in as (($:/plugins/dropbox/UserName))
<<dropbox.logout>< Log me out >>
>>
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:no>< <<dropbox.login>< Log me in >> >>
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:yes>< Logged in as (($:/plugins/dropbox/UserName)) - <<dropbox.logout>< Log me out >> >>
[[App|TiddlyWiki5 in the Sky with Dropbox]]

View File

@ -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();
}
};
})();

View File

@ -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;
};
})();

View File

@ -38,6 +38,4 @@ exports.executeMacro = function() {
return child;
};
})();