|
|
|
@ -1604,6 +1604,26 @@ define([
|
|
|
|
|
var allocated = Login.allocateBytes(bytes);
|
|
|
|
|
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) {
|
|
|
|
|
// Write the new login block
|
|
|
|
|
var temp = {
|
|
|
|
|