Fix 'change user password' overriding existing data

pull/1/head
yflory 4 years ago committed by ansuz
parent 6176d73c86
commit 7bbbbbad77

@ -1604,6 +1604,26 @@ define([
var allocated = Login.allocateBytes(bytes); var allocated = Login.allocateBytes(bytes);
blockKeys = allocated.blockKeys; blockKeys = allocated.blockKeys;
})); }));
}).nThen(function (waitFor) {
var blockUrl = Block.getBlockUrl(blockKeys);
// Check whether there is a block at that location
Util.fetch(blockUrl, waitFor(function (err, block) {
// If there is no block or the block is invalid, continue.
if (err) {
console.log("no block found");
return;
}
var decryptedBlock = Block.decrypt(block, blockKeys);
if (!decryptedBlock) {
console.error("Found a login block but failed to decrypt");
return;
}
// If there is already a valid block, abort! We risk overriding another user's data
waitFor.abort();
cb({ error: 'EEXISTS' });
}));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
// Write the new login block // Write the new login block
var temp = { var temp = {

@ -488,6 +488,7 @@ define([
UI.removeLoadingScreen(); UI.removeLoadingScreen();
if (obj && obj.error) { if (obj && obj.error) {
// TODO // TODO
// XXX EEXISTS error message?
UI.alert(Messages.settings_changePasswordError); UI.alert(Messages.settings_changePasswordError);
} }
}); });

Loading…
Cancel
Save