mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Account deletion for known users and fix UI
This commit is contained in:
parent
a3f9b2eceb
commit
a5103bc21b
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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', '');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user