mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 07:32:59 +00:00 
			
		
		
		
	Syncer: Allow syncadaptor to customise the login prompt
This commit is contained in:
		| @@ -400,7 +400,7 @@ 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) { | ||||||
| 			$tw.passwordPrompt.createPrompt({ | 			var promptInfo = $tw.passwordPrompt.createPrompt({ | ||||||
| 				serviceName: $tw.language.getString("LoginToTiddlySpace"), | 				serviceName: $tw.language.getString("LoginToTiddlySpace"), | ||||||
| 				callback: function(data) { | 				callback: function(data) { | ||||||
| 					self.login(data.username,data.password,function(err,isLoggedIn) { | 					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 | 					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: 20200113094126878 | modified: 20201014124049248 | ||||||
| tags: dev moduletypes | tags: dev moduletypes | ||||||
| title: SyncAdaptorModules | title: SyncAdaptorModules | ||||||
| type: text/vnd.tiddlywiki | type: text/vnd.tiddlywiki | ||||||
| @@ -80,6 +80,31 @@ 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)` | ||||||
|  |  | ||||||
|  | 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)` | !! `logout(callback)` | ||||||
|  |  | ||||||
| Attempts to logout of the server. This method is optional. | Attempts to logout of the server. This method is optional. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jeremy@jermolene.com
					jeremy@jermolene.com