|
|
@ -141,76 +141,81 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var onReady = function (f, proxy, Cryptpad, exp) {
|
|
|
|
var onReady = function (f, proxy, Cryptpad, exp) {
|
|
|
|
var fo = exp.fo = FO.init(proxy.drive, {
|
|
|
|
var fo = exp.fo = FO.init(proxy.drive, {
|
|
|
|
Cryptpad: Cryptpad
|
|
|
|
Cryptpad: Cryptpad,
|
|
|
|
|
|
|
|
rt: exp.realtime
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var todo = function () {
|
|
|
|
|
|
|
|
fo.fixFiles();
|
|
|
|
|
|
|
|
|
|
|
|
//storeObj = proxy;
|
|
|
|
//storeObj = proxy;
|
|
|
|
store = initStore(fo, proxy, exp);
|
|
|
|
store = initStore(fo, proxy, exp);
|
|
|
|
if (typeof(f) === 'function') {
|
|
|
|
if (typeof(f) === 'function') {
|
|
|
|
f(void 0, store);
|
|
|
|
f(void 0, store);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var requestLogin = function () {
|
|
|
|
var requestLogin = function () {
|
|
|
|
// log out so that you don't go into an endless loop...
|
|
|
|
// log out so that you don't go into an endless loop...
|
|
|
|
Cryptpad.logout();
|
|
|
|
Cryptpad.logout();
|
|
|
|
|
|
|
|
|
|
|
|
// redirect them to log in, and come back when they're done.
|
|
|
|
// redirect them to log in, and come back when they're done.
|
|
|
|
sessionStorage.redirectTo = window.location.href;
|
|
|
|
sessionStorage.redirectTo = window.location.href;
|
|
|
|
window.location.href = '/login/';
|
|
|
|
window.location.href = '/login/';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var tokenKey = 'loginToken';
|
|
|
|
var tokenKey = 'loginToken';
|
|
|
|
if (Cryptpad.isLoggedIn()) {
|
|
|
|
if (Cryptpad.isLoggedIn()) {
|
|
|
|
/* This isn't truly secure, since anyone who can read the user's object can
|
|
|
|
/* This isn't truly secure, since anyone who can read the user's object can
|
|
|
|
set their local loginToken to match that in the object. However, it exposes
|
|
|
|
set their local loginToken to match that in the object. However, it exposes
|
|
|
|
a UI that will work most of the time. */
|
|
|
|
a UI that will work most of the time. */
|
|
|
|
|
|
|
|
|
|
|
|
// every user object should have a persistent, random number
|
|
|
|
// every user object should have a persistent, random number
|
|
|
|
if (typeof(proxy.loginToken) !== 'number') {
|
|
|
|
if (typeof(proxy.loginToken) !== 'number') {
|
|
|
|
proxy[tokenKey] = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);
|
|
|
|
proxy[tokenKey] = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// copy User_hash into sessionStorage because cross-domain iframes
|
|
|
|
// copy User_hash into sessionStorage because cross-domain iframes
|
|
|
|
// on safari replaces localStorage with sessionStorage or something
|
|
|
|
// on safari replaces localStorage with sessionStorage or something
|
|
|
|
if (sessionStorage) { sessionStorage.setItem('User_hash', localStorage.getItem('User_hash')); }
|
|
|
|
if (sessionStorage) { sessionStorage.setItem('User_hash', localStorage.getItem('User_hash')); }
|
|
|
|
|
|
|
|
|
|
|
|
var localToken = tryParsing(localStorage.getItem(tokenKey));
|
|
|
|
var localToken = tryParsing(localStorage.getItem(tokenKey));
|
|
|
|
if (localToken === null) {
|
|
|
|
if (localToken === null) {
|
|
|
|
// if that number hasn't been set to localStorage, do so.
|
|
|
|
// if that number hasn't been set to localStorage, do so.
|
|
|
|
localStorage.setItem(tokenKey, proxy.loginToken);
|
|
|
|
localStorage.setItem(tokenKey, proxy.loginToken);
|
|
|
|
} else if (localToken !== proxy[tokenKey]) {
|
|
|
|
} else if (localToken !== proxy[tokenKey]) {
|
|
|
|
// if it has been, and the local number doesn't match that in
|
|
|
|
// if it has been, and the local number doesn't match that in
|
|
|
|
// the user object, request that they reauthenticate.
|
|
|
|
// the user object, request that they reauthenticate.
|
|
|
|
return void requestLogin();
|
|
|
|
return void requestLogin();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof(proxy.allowUserFeedback) !== 'boolean') {
|
|
|
|
|
|
|
|
proxy.allowUserFeedback = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof(proxy.uid) !== 'string' || proxy.uid.length !== 32) {
|
|
|
|
if (typeof(proxy.allowUserFeedback) !== 'boolean') {
|
|
|
|
// even anonymous users should have a persistent, unique-ish id
|
|
|
|
proxy.allowUserFeedback = true;
|
|
|
|
console.log('generating a persistent identifier');
|
|
|
|
}
|
|
|
|
proxy.uid = Cryptpad.createChannelId();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if the user is logged in, but does not have signing keys...
|
|
|
|
if (typeof(proxy.uid) !== 'string' || proxy.uid.length !== 32) {
|
|
|
|
if (Cryptpad.isLoggedIn() && !Cryptpad.hasSigningKeys(proxy)) {
|
|
|
|
// even anonymous users should have a persistent, unique-ish id
|
|
|
|
return void requestLogin();
|
|
|
|
console.log('generating a persistent identifier');
|
|
|
|
}
|
|
|
|
proxy.uid = Cryptpad.createChannelId();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
proxy.on('change', [Cryptpad.displayNameKey], function (o, n) {
|
|
|
|
// if the user is logged in, but does not have signing keys...
|
|
|
|
if (typeof(n) !== "string") { return; }
|
|
|
|
if (Cryptpad.isLoggedIn() && !Cryptpad.hasSigningKeys(proxy)) {
|
|
|
|
Cryptpad.changeDisplayName(n);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
proxy.on('change', [tokenKey], function () {
|
|
|
|
|
|
|
|
console.log('wut');
|
|
|
|
|
|
|
|
var localToken = tryParsing(localStorage.getItem(tokenKey));
|
|
|
|
|
|
|
|
if (localToken !== proxy[tokenKey]) {
|
|
|
|
|
|
|
|
return void requestLogin();
|
|
|
|
return void requestLogin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
proxy.on('change', [Cryptpad.displayNameKey], function (o, n) {
|
|
|
|
|
|
|
|
if (typeof(n) !== "string") { return; }
|
|
|
|
|
|
|
|
Cryptpad.changeDisplayName(n);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
proxy.on('change', [tokenKey], function () {
|
|
|
|
|
|
|
|
console.log('wut');
|
|
|
|
|
|
|
|
var localToken = tryParsing(localStorage.getItem(tokenKey));
|
|
|
|
|
|
|
|
if (localToken !== proxy[tokenKey]) {
|
|
|
|
|
|
|
|
return void requestLogin();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
fo.migrate(todo);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var initialized = false;
|
|
|
|
var initialized = false;
|
|
|
@ -260,6 +265,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var rt = window.rt = Listmap.create(listmapConfig);
|
|
|
|
var rt = window.rt = Listmap.create(listmapConfig);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exp.realtime = rt.realtime;
|
|
|
|
exp.proxy = rt.proxy;
|
|
|
|
exp.proxy = rt.proxy;
|
|
|
|
rt.proxy.on('create', function (info) {
|
|
|
|
rt.proxy.on('create', function (info) {
|
|
|
|
exp.info = info;
|
|
|
|
exp.info = info;
|
|
|
@ -291,10 +297,13 @@ define([
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.on('change', ['drive'], function () {
|
|
|
|
.on('change', [], function () {
|
|
|
|
var path = arguments[2];
|
|
|
|
var path = arguments[2];
|
|
|
|
var value = arguments[1];
|
|
|
|
var value = arguments[1];
|
|
|
|
if (path[1] === "migrate" && value === 1) {
|
|
|
|
console.log('abcd');
|
|
|
|
|
|
|
|
console.log(arguments);
|
|
|
|
|
|
|
|
if (path[0] === 'drive' && path[1] === "migrate" && value === 1) {
|
|
|
|
|
|
|
|
console.log('PEWPEWPEW');
|
|
|
|
rt.network.disconnect();
|
|
|
|
rt.network.disconnect();
|
|
|
|
rt.realtime.abort();
|
|
|
|
rt.realtime.abort();
|
|
|
|
Cryptpad.alert("Disconnected while migration");
|
|
|
|
Cryptpad.alert("Disconnected while migration");
|
|
|
|