mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Add support for username/password parameters for tm-login message
This commit is contained in:
parent
5cc1600072
commit
f7f55e8eff
@ -113,8 +113,16 @@ function Syncer(options) {
|
|||||||
return confirmationMessage;
|
return confirmationMessage;
|
||||||
});
|
});
|
||||||
// Listen out for login/logout/refresh events in the browser
|
// Listen out for login/logout/refresh events in the browser
|
||||||
$tw.rootWidget.addEventListener("tm-login",function() {
|
$tw.rootWidget.addEventListener("tm-login",function(event) {
|
||||||
|
var username = event && event.paramObject && event.paramObject.username,
|
||||||
|
password = event && event.paramObject && event.paramObject.password;
|
||||||
|
if(username && password) {
|
||||||
|
// Login with username and password
|
||||||
|
self.login(username,password,function() {});
|
||||||
|
} else {
|
||||||
|
// No username and password, so we display a prompt
|
||||||
self.handleLoginEvent();
|
self.handleLoginEvent();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
$tw.rootWidget.addEventListener("tm-logout",function() {
|
$tw.rootWidget.addEventListener("tm-logout",function() {
|
||||||
self.handleLogoutEvent();
|
self.handleLogoutEvent();
|
||||||
@ -400,6 +408,20 @@ Syncer.prototype.handleLoginEvent = function() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
this.getStatus(function(err,isLoggedIn,username) {
|
this.getStatus(function(err,isLoggedIn,username) {
|
||||||
if(!err && !isLoggedIn) {
|
if(!err && !isLoggedIn) {
|
||||||
|
if(self.syncadaptor && self.syncadaptor.displayLoginPrompt) {
|
||||||
|
self.syncadaptor.displayLoginPrompt(self);
|
||||||
|
} else {
|
||||||
|
self.displayLoginPrompt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Dispay a password prompt
|
||||||
|
*/
|
||||||
|
Syncer.prototype.displayLoginPrompt = function() {
|
||||||
|
var self = this;
|
||||||
var promptInfo = $tw.passwordPrompt.createPrompt({
|
var promptInfo = $tw.passwordPrompt.createPrompt({
|
||||||
serviceName: $tw.language.getString("LoginToTiddlySpace"),
|
serviceName: $tw.language.getString("LoginToTiddlySpace"),
|
||||||
callback: function(data) {
|
callback: function(data) {
|
||||||
@ -409,12 +431,6 @@ Syncer.prototype.handleLoginEvent = function() {
|
|||||||
return true; // Get rid of the password prompt
|
return true; // Get rid of the password prompt
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Let the sync adaptor adjust the prompt
|
|
||||||
if(self.syncadaptor && self.syncadaptor.customiseLoginPrompt) {
|
|
||||||
self.syncadaptor.customiseLoginPrompt(promptInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
created: 20130825162100000
|
created: 20130825162100000
|
||||||
modified: 20201014124049248
|
modified: 20201025162413404
|
||||||
tags: dev moduletypes
|
tags: dev moduletypes
|
||||||
title: SyncAdaptorModules
|
title: SyncAdaptorModules
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -80,30 +80,14 @@ Attempts to login to the server with specified credentials. This method is optio
|
|||||||
|password |Password |
|
|password |Password |
|
||||||
|callback |Callback function invoked with parameter `err` |
|
|callback |Callback function invoked with parameter `err` |
|
||||||
|
|
||||||
!! `customiseLoginPrompt(promptInfo)`
|
!! `displayLoginPrompt(syncer)`
|
||||||
|
|
||||||
Provides an opportunity to customise the login prompt.
|
Invoked by the syncer to display a custom login promopt. This method is optional.
|
||||||
|
|
||||||
|!Parameter |!Description |
|
|!Parameter |!Description |
|
||||||
|promptInfo |The `promptInfo` object returned by `$tw.passwordPrompt.createPrompt()` |
|
|syncer |Reference to the syncer object making the call |
|
||||||
|
|
||||||
Here's an example of customising the login prompt to include a "forgotten password" button:
|
The custom login prompt should send the widget message `tm-login` with the username and password in parameters ''username'' and ''password''.
|
||||||
|
|
||||||
```
|
|
||||||
SyncAdaptor.prototype.customiseLoginPrompt = function(promptInfo) {
|
|
||||||
promptInfo.form.appendChild($tw.utils.domMaker("button",{
|
|
||||||
attributes: {type: "submit"},
|
|
||||||
text: "Forgot password",
|
|
||||||
eventListeners: [{
|
|
||||||
name: "click",
|
|
||||||
handlerFunction: function(event) {
|
|
||||||
promptInfo.owner.removePrompt(promptInfo);
|
|
||||||
alert("Forgot password");
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
!! `logout(callback)`
|
!! `logout(callback)`
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
created: 20140811112445887
|
created: 20140811112445887
|
||||||
modified: 20140811113336694
|
modified: 20201025163134940
|
||||||
tags: Messages
|
tags: Messages
|
||||||
title: WidgetMessage: tm-login
|
title: WidgetMessage: tm-login
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -9,3 +9,4 @@ The login message prompts the user for a username and password and attempts to l
|
|||||||
|
|
||||||
The login message is handled by the TiddlyWiki core SyncMechanism which invokes the current [[SyncAdaptorModule|SyncAdaptorModules]] (typically the ''tiddlywiki/tiddlywebadaptor'' plugin).
|
The login message is handled by the TiddlyWiki core SyncMechanism which invokes the current [[SyncAdaptorModule|SyncAdaptorModules]] (typically the ''tiddlywiki/tiddlywebadaptor'' plugin).
|
||||||
|
|
||||||
|
<<.from-version "5.1.23">> The login message can optionally accept parameters called ''username'' and ''password'' that immediately attempts to login with the specified credentials without displaying the prompt
|
||||||
|
Loading…
Reference in New Issue
Block a user