Hidden hash for shared folders and team invitation

pull/1/head
yflory 5 years ago
parent 0ad96e0966
commit a8e6250576

@ -144,7 +144,7 @@ define([
}); });
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
if (!Utils.Hash.isValidHref(currentPad.href)) { if (!Utils.Hash.isValidHref(window.location.href)) {
waitFor.abort(); waitFor.abort();
return void sframeChan.event('EV_LOADING_ERROR', 'INVALID_HASH'); return void sframeChan.event('EV_LOADING_ERROR', 'INVALID_HASH');
} }

@ -9,6 +9,7 @@ define([
var requireConfig = RequireConfig(); var requireConfig = RequireConfig();
// Loaded in load #2 // Loaded in load #2
var hash, href;
nThen(function (waitFor) { nThen(function (waitFor) {
DomReady.onReady(waitFor()); DomReady.onReady(waitFor());
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
@ -19,6 +20,14 @@ define([
}; };
window.rc = requireConfig; window.rc = requireConfig;
window.apiconf = ApiConfig; window.apiconf = ApiConfig;
// Hidden hash
hash = window.location.hash;
href = window.location.href;
if (window.history && window.history.replaceState) {
window.history.replaceState({}, window.document.title, '#');
}
document.getElementById('sbox-iframe').setAttribute('src', document.getElementById('sbox-iframe').setAttribute('src',
ApiConfig.httpSafeOrigin + '/drive/inner.html?' + requireConfig.urlArgs + ApiConfig.httpSafeOrigin + '/drive/inner.html?' + requireConfig.urlArgs +
'#' + encodeURIComponent(JSON.stringify(req))); '#' + encodeURIComponent(JSON.stringify(req)));
@ -37,19 +46,19 @@ define([
window.addEventListener('message', onMsg); window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
var afterSecrets = function (Cryptpad, Utils, secret, cb) { var afterSecrets = function (Cryptpad, Utils, secret, cb) {
var hash = window.location.hash.slice(1); var _hash = hash.slice(1);
if (hash && Utils.LocalStore.isLoggedIn()) { if (_hash && Utils.LocalStore.isLoggedIn()) {
// Add a shared folder! // Add a shared folder!
Cryptpad.addSharedFolder(null, secret, function (id) { Cryptpad.addSharedFolder(null, secret, function (id) {
window.CryptPad_newSharedFolder = id; window.CryptPad_newSharedFolder = id;
cb(); cb();
}); });
return; return;
} else if (hash) { } else if (_hash) {
var id = Utils.Util.createRandomInteger(); var id = Utils.Util.createRandomInteger();
window.CryptPad_newSharedFolder = id; window.CryptPad_newSharedFolder = id;
var data = { var data = {
href: Utils.Hash.getRelativeHref(window.location.href), href: Utils.Hash.getRelativeHref(href),
password: secret.password password: secret.password
}; };
return void Cryptpad.loadSharedFolder(id, data, cb); return void Cryptpad.loadSharedFolder(id, data, cb);
@ -84,12 +93,15 @@ define([
}); });
sframeChan.on('EV_DRIVE_SET_HASH', function (hash) { sframeChan.on('EV_DRIVE_SET_HASH', function (hash) {
// Update the hash in the address bar // Update the hash in the address bar
// XXX Hidden hash: don't put the shared folder href in the address bar
/*
if (!Utils.LocalStore.isLoggedIn()) { return; } if (!Utils.LocalStore.isLoggedIn()) { return; }
var ohc = window.onhashchange; var ohc = window.onhashchange;
window.onhashchange = function () {}; window.onhashchange = function () {};
window.location.hash = hash || ''; window.location.hash = hash || '';
window.onhashchange = ohc; window.onhashchange = ohc;
ohc({reset:true}); ohc({reset:true});
*/
}); });
Cryptpad.onNetworkDisconnect.reg(function () { Cryptpad.onNetworkDisconnect.reg(function () {
sframeChan.event('EV_NETWORK_DISCONNECT'); sframeChan.event('EV_NETWORK_DISCONNECT');
@ -109,9 +121,11 @@ define([
}; };
var addData = function (meta) { var addData = function (meta) {
if (!window.CryptPad_newSharedFolder) { return; } if (!window.CryptPad_newSharedFolder) { return; }
meta.anonSFHref = window.location.href; meta.anonSFHref = href;
}; };
SFCommonO.start({ SFCommonO.start({
hash: hash,
href: href,
afterSecrets: afterSecrets, afterSecrets: afterSecrets,
noHash: true, noHash: true,
noRealtime: true, noRealtime: true,

@ -9,6 +9,7 @@ define([
var requireConfig = RequireConfig(); var requireConfig = RequireConfig();
// Loaded in load #2 // Loaded in load #2
var hash, href;
nThen(function (waitFor) { nThen(function (waitFor) {
DomReady.onReady(waitFor()); DomReady.onReady(waitFor());
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
@ -19,6 +20,14 @@ define([
}; };
window.rc = requireConfig; window.rc = requireConfig;
window.apiconf = ApiConfig; window.apiconf = ApiConfig;
// Hidden hash
hash = window.location.hash;
href = window.location.href;
if (window.history && window.history.replaceState) {
window.history.replaceState({}, window.document.title, '#');
}
document.getElementById('sbox-iframe').setAttribute('src', document.getElementById('sbox-iframe').setAttribute('src',
ApiConfig.httpSafeOrigin + '/teams/inner.html?' + requireConfig.urlArgs + ApiConfig.httpSafeOrigin + '/teams/inner.html?' + requireConfig.urlArgs +
'#' + encodeURIComponent(JSON.stringify(req))); '#' + encodeURIComponent(JSON.stringify(req)));
@ -37,7 +46,6 @@ define([
window.addEventListener('message', onMsg); window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
var teamId; var teamId;
var hash = window.location.hash.slice(1);
var addRpc = function (sframeChan, Cryptpad) { var addRpc = function (sframeChan, Cryptpad) {
sframeChan.on('Q_SET_TEAM', function (data, cb) { sframeChan.on('Q_SET_TEAM', function (data, cb) {
teamId = data; teamId = data;
@ -95,7 +103,7 @@ define([
}; };
var addData = function (meta) { var addData = function (meta) {
if (!hash) { return; } if (!hash) { return; }
meta.teamInviteHash = hash; meta.teamInviteHash = hash.slice(1);
}; };
SFCommonO.start({ SFCommonO.start({
getSecrets: getSecrets, getSecrets: getSecrets,

Loading…
Cancel
Save