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
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);

View File

@ -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);