diff --git a/lib/challenge-commands/base.js b/lib/challenge-commands/base.js index 41549e613..2e23d1dee 100644 --- a/lib/challenge-commands/base.js +++ b/lib/challenge-commands/base.js @@ -82,8 +82,8 @@ const removeBlock = Commands.REMOVE_BLOCK = function (Env, body, cb) { }; removeBlock.complete = function (Env, body, cb) { - const { publicKey, reason } = body; - Block.removeLoginBlock(Env, publicKey, reason, cb); + const { publicKey, edPublic, reason } = body; + Block.removeLoginBlock(Env, publicKey, reason, edPublic, cb); }; diff --git a/lib/challenge-commands/totp.js b/lib/challenge-commands/totp.js index 303b7a93b..ca44e0010 100644 --- a/lib/challenge-commands/totp.js +++ b/lib/challenge-commands/totp.js @@ -513,10 +513,10 @@ const removeBlock = Commands.TOTP_REMOVE_BLOCK = function (Env, body, cb) { }; removeBlock.complete = function (Env, body, cb) { - const { publicKey, reason } = body; + const { publicKey, edPublic, reason } = body; nThen(function (w) { // Remove the block - Block.removeLoginBlock(Env, publicKey, reason, w((err) => { + Block.removeLoginBlock(Env, publicKey, reason, edPublic, w((err) => { if (err) { w.abort(); return void cb(err); diff --git a/lib/commands/block.js b/lib/commands/block.js index 6ccef235b..aeb41ec04 100644 --- a/lib/commands/block.js +++ b/lib/commands/block.js @@ -185,7 +185,6 @@ Block.writeLoginBlock = function (Env, msg, _cb) { } }); - console.log(isSSO, Env.storeSSOUsers); if (validatedInvite) { Invitation.use(Env, inviteToken, publicKey, userData, (err) => { if (!err) { return; } @@ -195,8 +194,7 @@ Block.writeLoginBlock = function (Env, msg, _cb) { publicKey }); }); - } else if (isSSO && Env.storeSSOUsers) { - console.log('LALALA'); + } else if (isSSO && Env.storeSSOUsers && !registrationProof) { let edPublic = Array.isArray(userData) && userData[1]; let name = Array.isArray(userData) && userData[0]; if (!edPublic) { return; } @@ -229,7 +227,7 @@ Block.writeLoginBlock = function (Env, msg, _cb) { information, we can just sign some constant and use that as proof. */ -Block.removeLoginBlock = function (Env, publicKey, reason, _cb) { +Block.removeLoginBlock = function (Env, publicKey, reason, edPublic, _cb) { var cb = Util.once(Util.mkAsync(_cb)); BlockStore.archive(Env, publicKey, reason, function (err) { @@ -240,6 +238,11 @@ Block.removeLoginBlock = function (Env, publicKey, reason, _cb) { cb(err); }); + if (edPublic && reason !== 'PASSWORD_CHANGE') { + Users.delete(Env, edPublic, (err) => { + if (err) { Env.Log.error('KNOWN_USER_DELETION_ERROR', { error: err, key: edPublic }); } + }); + } // We should also try to remove the SSO data. Errors will be logged // but they don't have to be shown to the user. The account data diff --git a/lib/commands/invitation.js b/lib/commands/invitation.js index 05c0e6151..bafae4f10 100644 --- a/lib/commands/invitation.js +++ b/lib/commands/invitation.js @@ -60,7 +60,6 @@ Invitation.use = (Env, id, blockId, userData, _cb) => { data.edPublic = edPublic; data.type = 'invite:' + id; let adminKey = data.createdBy; - console.log(Env.storeInvitedUsers, 'ICI', Env.storeInvitedUsers, Env.storeSSOUsers); if (Env.storeInvitedUsers) { Users.add(Env, edPublic, data, adminKey, (err) => { if (err) { diff --git a/lib/commands/users.js b/lib/commands/users.js index 37f2203a9..3fc161190 100644 --- a/lib/commands/users.js +++ b/lib/commands/users.js @@ -7,7 +7,6 @@ const Util = require("../common-util"); Users.getAll = (Env, cb) => { User.getAll(Env, (err, data) => { if (err) { return void cb(err); } - console.log(data); cb(null, data); }); }; @@ -17,7 +16,6 @@ Users.add = (Env, edPublic, data, adminKey, _cb) => { data.createdBy = adminKey; data.time = +new Date(); const safeKey = Util.escapeKeyCharacters(edPublic); - console.log(edPublic, data); User.write(Env, safeKey, data, (err) => { if (err) { return void cb(err); } cb(); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 36cef9279..9721e3fa2 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1912,6 +1912,7 @@ define([ common.deleteAccount = function (data, cb) { data = data || {}; + common.CP_onAccountDeletion = true; var bytes = data.bytes; // From Scrypt var auth = data.auth; // MFA data @@ -2125,6 +2126,7 @@ define([ Block.removeLoginBlock({ reason: 'PASSWORD_CHANGE', auth: auth, + edPublic: edPublic, blockKeys: oldBlockKeys, }, waitFor(function (err) { if (err) { return void console.error(err); } @@ -2340,7 +2342,7 @@ define([ LocalStore.logout(function () { common.stopWorker(); common.drive.onDeleted.fire(data.reason); - }); + }, true); }; var lastPing = +new Date(); @@ -2898,13 +2900,17 @@ define([ if (!o && n) { LocalStore.loginReload(); } else if (o && !n) { - LocalStore.logout(); + if (!common.CP_onAccountDeletion) { LocalStore.logout(); } } else if (o && n && o !== n) { common.passwordUpdated = true; window.location.reload(); } }); + common.drive.onDeleted.reg(function () { + common.CP_onAccountDeletion = true; + }); LocalStore.onLogout(function () { + if (common.CP_onAccountDeletion) { return; } console.log('onLogout: disconnect'); common.stopWorker(); }); diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 99cf943c9..e8723d321 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -861,7 +861,6 @@ define([ // Owned drive if (metadata && metadata.owners && metadata.owners.length === 1 && metadata.owners.indexOf(edPublic) !== -1) { - var token; nThen(function (waitFor) { Block.checkRights({ auth: auth, @@ -876,8 +875,7 @@ define([ }).nThen(function (waitFor) { self.accountDeletion = clientId; // Log out from other workers - var token = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER); - store.proxy[Constants.tokenKey] = token; + store.proxy[Constants.tokenKey] = 'DELETED'; onSync(null, waitFor()); }).nThen(function (waitFor) { // Delete Pin Store @@ -896,6 +894,7 @@ define([ Block.removeLoginBlock({ reason: 'ARCHIVE_OWNED', auth: auth, + edPublic: edPublic, blockKeys: blockKeys, }, waitFor(function (err) { if (err) { console.error(err); } @@ -904,7 +903,8 @@ define([ removeOwnedPads(true, waitFor); }).nThen(function () { // Log out current worker - postMessage(clientId, "DELETE_ACCOUNT", token, function () {}); + broadcast([clientId], "DRIVE_DELETED", 'ARCHIVE_OWNED'); + postMessage(clientId, "DELETE_ACCOUNT", 'DELETED', function () {}); store.network.disconnect(); cb({ state: true @@ -2926,6 +2926,7 @@ define([ broadcast([], "UPDATE_METADATA"); }); proxy.on('change', [Constants.tokenKey], function () { + if (store.isDeleted || proxy[Constants.tokenKey] === 'DELETED') { return; } broadcast([], "UPDATE_TOKEN", { token: proxy[Constants.tokenKey] }); }); @@ -3061,9 +3062,8 @@ define([ .on('error', function (info) { if (info.error && info.error === 'EDELETED') { if (store.ownDeletion) { return; } - broadcast([], "LOGOUT", { - reason: info.message - }); + store.isDeleted = true; + broadcast([], "DRIVE_DELETED", info.message); } }); diff --git a/www/common/outer/login-block.js b/www/common/outer/login-block.js index a929373e6..439c34994 100644 --- a/www/common/outer/login-block.js +++ b/www/common/outer/login-block.js @@ -196,7 +196,7 @@ define([ }, cb); }; Block.removeLoginBlock = function (data, cb) { - const { reason, blockKeys, auth } = data; + const { reason, blockKeys, auth, edPublic } = data; var command = 'REMOVE_BLOCK'; if (auth && auth.type) { command = `${auth.type.toUpperCase()}_` + command; } @@ -204,6 +204,7 @@ define([ ServerCommand(blockKeys.sign, { command: command, auth: auth && auth.data, + edPublic: edPublic, reason: reason }, cb); }; diff --git a/www/common/outer/sharedworker.js b/www/common/outer/sharedworker.js index 408b88fdd..41cf9938b 100644 --- a/www/common/outer/sharedworker.js +++ b/www/common/outer/sharedworker.js @@ -104,7 +104,7 @@ var init = function (client, cb) { cfg.broadcast = function (excludes, cmd, data, cb) { cb = cb || function () {}; Object.keys(self.tabs).forEach(function (cId) { - if (excludes.indexOf(cId) !== -1) { return; } + if (excludes.indexOf(+cId) !== -1) { return; } self.tabs[cId].chan.query(cmd, data, function (err, data2) { if (err) { return void cb({error: err}); } cb(data2); diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index df1f4d91a..625a0dfe6 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -1012,6 +1012,7 @@ define([ } catch (e) {} ctx.sframeChan.on('EV_LOGOUT', function () { + if (window.CP_ownAccountDeletion) { return; } $(window).on('keyup', function (e) { if (e.keyCode === 27) { UI.removeLoadingScreen(); diff --git a/www/settings/inner.js b/www/settings/inner.js index bb33bd793..e23459d9d 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -626,10 +626,12 @@ define([ } })); }).nThen(function () { + window.CP_ownAccountDeletion = true; sframeChan.query("Q_SETTINGS_DELETE_ACCOUNT", { bytes: bytes, auth: auth }, function(err, data) { + if (err) { window.CP_ownAccountDeletion = false; } UI.removeLoadingScreen(); if (data && data.error) { $button.prop('disabled', '');