Avoid timeout in accounts.cryptpad.fr caused by the auth app

pull/1/head
yflory 6 years ago
parent 673dc22159
commit 0e04c4392c

@ -27,25 +27,22 @@ define([
sessionStorage[Constants.userHashKey]; sessionStorage[Constants.userHashKey];
var proxy; var proxy;
nThen(function (waitFor) {
Cryptpad.ready(waitFor()); var whenReady = function (cb) {
}).nThen(function (waitFor) { if (proxy) { return void cb(); }
Cryptpad.getUserObject(waitFor(function (obj) { console.log('CryptPad not ready...');
proxy = obj; setTimeout(function () {
})); whenReady(cb);
}).nThen(function () { }, 100);
console.log('IFRAME READY'); };
Test(function () {
// This is only here to maybe trigger an error.
window.drive = proxy['drive'];
Test.passed();
});
$(window).on("message", function (jqe) { $(window).on("message", function (jqe) {
var evt = jqe.originalEvent; var evt = jqe.originalEvent;
var data = JSON.parse(evt.data); var data = JSON.parse(evt.data);
var domain = evt.origin; var domain = evt.origin;
var srcWindow = evt.source; var srcWindow = evt.source;
var ret = { txid: data.txid }; var ret = { txid: data.txid };
console.log('CP receiving', data);
if (data.cmd === 'PING') { if (data.cmd === 'PING') {
ret.res = 'PONG'; ret.res = 'PONG';
} else if (data.cmd === 'SIGN') { } else if (data.cmd === 'SIGN') {
@ -54,22 +51,41 @@ define([
} else if (!LocalStore.isLoggedIn()) { } else if (!LocalStore.isLoggedIn()) {
ret.error = "NOT_LOGGED_IN"; ret.error = "NOT_LOGGED_IN";
} else { } else {
return void whenReady(function () {
var sig = signMsg(data.data, proxy.edPrivate); var sig = signMsg(data.data, proxy.edPrivate);
ret.res = { ret.res = {
uname: proxy.login_name, uname: proxy.login_name,
edPublic: proxy.edPublic, edPublic: proxy.edPublic,
sig: sig sig: sig
}; };
srcWindow.postMessage(JSON.stringify(ret), domain);
});
} }
} else if (data.cmd === 'UPDATE_LIMIT') { } else if (data.cmd === 'UPDATE_LIMIT') {
return Cryptpad.updatePinLimit(function (e, limit, plan, note) { return void whenReady(function () {
Cryptpad.updatePinLimit(function (e, limit, plan, note) {
ret.res = [limit, plan, note]; ret.res = [limit, plan, note];
srcWindow.postMessage(JSON.stringify(ret), domain); srcWindow.postMessage(JSON.stringify(ret), domain);
}); });
});
} else { } else {
ret.error = "UNKNOWN_CMD"; ret.error = "UNKNOWN_CMD";
} }
srcWindow.postMessage(JSON.stringify(ret), domain); srcWindow.postMessage(JSON.stringify(ret), domain);
}); });
nThen(function (waitFor) {
Cryptpad.ready(waitFor());
}).nThen(function (waitFor) {
Cryptpad.getUserObject(waitFor(function (obj) {
proxy = obj;
}));
}).nThen(function () {
console.log('IFRAME READY');
Test(function () {
// This is only here to maybe trigger an error.
window.drive = proxy['drive'];
Test.passed();
});
}); });
}); });

Loading…
Cancel
Save