From b7bbcfa05659808c1e51a4f2f5f1d6afbc2ed3a1 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 6 Oct 2014 10:22:09 +0100 Subject: [PATCH] Prompt twice when setting password Fixes #364 --- boot/boot.js | 33 +++++++++++++++++++++----------- core/modules/startup/password.js | 1 + 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index 02307f600..2ac978d72 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -477,6 +477,7 @@ submitText: text to use for submit button (defaults to "Login") serviceName: text of the human readable service name noUserName: set true to disable username prompt 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 */ $tw.utils.PasswordPrompt.prototype.createPrompt = function(options) { @@ -493,6 +494,11 @@ $tw.utils.PasswordPrompt.prototype.createPrompt = function(options) { children.push(dm("input",{ 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) { children.push(dm("button",{ text: "Cancel", @@ -527,18 +533,23 @@ $tw.utils.PasswordPrompt.prototype.createPrompt = function(options) { data[element.name] = element.value; } }); - // Call the callback - if(options.callback(data)) { - // Remove the prompt if the callback returned true - self.removePrompt(promptInfo); + // Check that the passwords match + if(options.repeatPassword && data.password !== data.password2) { + alert("Passwords do not match"); } else { - // Clear the password if the callback returned false - $tw.utils.each(form.elements,function(element) { - if(element.name === "password") { - element.value = ""; - } - }); - } + // Call the callback + if(options.callback(data)) { + // Remove the prompt if the callback returned true + 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(); return false; },true); diff --git a/core/modules/startup/password.js b/core/modules/startup/password.js index 41902e9e9..8913d0833 100644 --- a/core/modules/startup/password.js +++ b/core/modules/startup/password.js @@ -25,6 +25,7 @@ exports.startup = function() { noUserName: true, submitText: "Set password", canCancel: true, + repeatPassword: true, callback: function(data) { if(data) { $tw.crypto.setPassword(data.password);