Syncer: Allow syncadaptor to customise the login prompt

optimising-macrocalls
jeremy@jermolene.com 2020-10-14 12:41:51 +01:00
rodzic 651fb777ab
commit 69c12618d9
2 zmienionych plików z 31 dodań i 2 usunięć

Wyświetl plik

@ -400,7 +400,7 @@ Syncer.prototype.handleLoginEvent = function() {
var self = this;
this.getStatus(function(err,isLoggedIn,username) {
if(!err && !isLoggedIn) {
$tw.passwordPrompt.createPrompt({
var promptInfo = $tw.passwordPrompt.createPrompt({
serviceName: $tw.language.getString("LoginToTiddlySpace"),
callback: function(data) {
self.login(data.username,data.password,function(err,isLoggedIn) {
@ -409,6 +409,10 @@ Syncer.prototype.handleLoginEvent = function() {
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);
}
}
});
};

Wyświetl plik

@ -1,5 +1,5 @@
created: 20130825162100000
modified: 20200113094126878
modified: 20201014124049248
tags: dev moduletypes
title: SyncAdaptorModules
type: text/vnd.tiddlywiki
@ -80,6 +80,31 @@ Attempts to login to the server with specified credentials. This method is optio
|password |Password |
|callback |Callback function invoked with parameter `err` |
!! `customiseLoginPrompt(promptInfo)`
Provides an opportunity to customise the login prompt.
|!Parameter |!Description |
|promptInfo |The `promptInfo` object returned by `$tw.passwordPrompt.createPrompt()` |
Here's an example of customising the login prompt to include a "forgotten password" button:
```
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)`
Attempts to logout of the server. This method is optional.