1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 19:47:20 +00:00

Prompt twice when setting password

Fixes #364
This commit is contained in:
Jermolene 2014-10-06 10:22:09 +01:00
parent 0c8e538077
commit b7bbcfa056
2 changed files with 23 additions and 11 deletions

View File

@ -477,6 +477,7 @@ submitText: text to use for submit button (defaults to "Login")
serviceName: text of the human readable service name serviceName: text of the human readable service name
noUserName: set true to disable username prompt noUserName: set true to disable username prompt
canCancel: set true to enable a cancel button (callback called with null) canCancel: set true to enable a cancel button (callback called with null)
repeatPassword: set true to prompt for the password twice
callback: function to be called on submission with parameter of object {username:,password:}. Callback must return `true` to remove the password prompt callback: function to be called on submission with parameter of object {username:,password:}. Callback must return `true` to remove the password prompt
*/ */
$tw.utils.PasswordPrompt.prototype.createPrompt = function(options) { $tw.utils.PasswordPrompt.prototype.createPrompt = function(options) {
@ -493,6 +494,11 @@ $tw.utils.PasswordPrompt.prototype.createPrompt = function(options) {
children.push(dm("input",{ children.push(dm("input",{
attributes: {type: "password", name: "password", placeholder: "Password"} attributes: {type: "password", name: "password", placeholder: "Password"}
})); }));
if(options.repeatPassword) {
children.push(dm("input",{
attributes: {type: "password", name: "password2", placeholder: "Repeat password"}
}));
}
if(options.canCancel) { if(options.canCancel) {
children.push(dm("button",{ children.push(dm("button",{
text: "Cancel", text: "Cancel",
@ -527,18 +533,23 @@ $tw.utils.PasswordPrompt.prototype.createPrompt = function(options) {
data[element.name] = element.value; data[element.name] = element.value;
} }
}); });
// Call the callback // Check that the passwords match
if(options.callback(data)) { if(options.repeatPassword && data.password !== data.password2) {
// Remove the prompt if the callback returned true alert("Passwords do not match");
self.removePrompt(promptInfo);
} else { } else {
// Clear the password if the callback returned false // Call the callback
$tw.utils.each(form.elements,function(element) { if(options.callback(data)) {
if(element.name === "password") { // Remove the prompt if the callback returned true
element.value = ""; self.removePrompt(promptInfo);
} } else {
}); // Clear the password if the callback returned false
} $tw.utils.each(form.elements,function(element) {
if(element.name === "password" || element.name === "password2") {
element.value = "";
}
});
}
}
event.preventDefault(); event.preventDefault();
return false; return false;
},true); },true);

View File

@ -25,6 +25,7 @@ exports.startup = function() {
noUserName: true, noUserName: true,
submitText: "Set password", submitText: "Set password",
canCancel: true, canCancel: true,
repeatPassword: true,
callback: function(data) { callback: function(data) {
if(data) { if(data) {
$tw.crypto.setPassword(data.password); $tw.crypto.setPassword(data.password);