Stop using sessionStorage for login redirect and new pad options

pull/1/head
yflory 4 years ago
parent 1016c05e64
commit f3d2fc6ad5

@ -28,6 +28,19 @@ define([
}; };
var Nacl = window.nacl; var Nacl = window.nacl;
var redirectTo = '/drive/';
var setRedirectTo = function () {
var parsed = Hash.parsePadUrl(window.location.href);
if (parsed.hashData && parsed.hashData.newPadOpts) {
var newPad = Hash.decodeDataOptions(parsed.hashData.newPadOpts);
redirectTo = newPad.href;
}
};
if (window.location.hash) {
setRedirectTo();
}
var allocateBytes = Exports.allocateBytes = function (bytes) { var allocateBytes = Exports.allocateBytes = function (bytes) {
var dispense = Cred.dispenser(bytes); var dispense = Cred.dispenser(bytes);
@ -118,11 +131,11 @@ define([
}; };
var setMergeAnonDrive = function () { var setMergeAnonDrive = function () {
sessionStorage.migrateAnonDrive = 1; Exports.mergeAnonDrive = 1;
}; };
var setCreateReadme = function () { var setCreateReadme = function () {
sessionStorage.createReadme = 1; Exports.createReadme = 1;
}; };
Exports.loginOrRegister = function (uname, passwd, isRegister, shouldImport, cb) { Exports.loginOrRegister = function (uname, passwd, isRegister, shouldImport, cb) {
@ -416,12 +429,20 @@ define([
}); });
}; };
Exports.redirect = function () { Exports.redirect = function () {
if (sessionStorage.redirectTo) { if (redirectTo) {
var h = sessionStorage.redirectTo; var h = redirectTo;
var loginOpts = {};
if (Exports.mergeAnonDrive) {
loginOpts.mergeAnonDrive = 1;
}
if (Exports.createReadme) {
loginOpts.createReadme = 1;
}
h = Hash.getLoginURL(h, loginOpts);
var parser = document.createElement('a'); var parser = document.createElement('a');
parser.href = h; parser.href = h;
if (parser.origin === window.location.origin) { if (parser.origin === window.location.origin) {
delete sessionStorage.redirectTo;
window.location.href = h; window.location.href = h;
return; return;
} }

@ -22,14 +22,6 @@ define([
target: '_blank', target: '_blank',
rel: 'noopener noreferrer' rel: 'noopener noreferrer'
}, h('button.cp-features-register-button', Msg.features_f_subscribe)); }, h('button.cp-features-register-button', Msg.features_f_subscribe));
/*$(premiumButton).click(function (e) {
if (LocalStore.isLoggedIn()) { return; }
// Not logged in: go to /login with a redirect to this page
e.preventDefault();
e.stopPropagation();
sessionStorage.redirectTo = '/features.html';
window.location.href = '/login/';
});*/
var anonymousFeatures = var anonymousFeatures =
h('div.col-12.col-sm-4.cp-anon-user',[ h('div.col-12.col-sm-4.cp-anon-user',[

@ -4,12 +4,13 @@ define([
'/common/hyperscript.js', '/common/hyperscript.js',
'/common/common-feedback.js', '/common/common-feedback.js',
'/common/common-interface.js', '/common/common-interface.js',
'/common/common-hash.js',
'/common/textFit.min.js', '/common/textFit.min.js',
'/customize/messages.js', '/customize/messages.js',
'/customize/application_config.js', '/customize/application_config.js',
'/common/outer/local-store.js', '/common/outer/local-store.js',
'/customize/pages.js' '/customize/pages.js'
], function ($, Config, h, Feedback, UI, TextFit, Msg, AppConfig, LocalStore, Pages) { ], function ($, Config, h, Feedback, UI, Hash, TextFit, Msg, AppConfig, LocalStore, Pages) {
var urlArgs = Config.requireConf.urlArgs; var urlArgs = Config.requireConf.urlArgs;
var isAvailableType = function (x) { var isAvailableType = function (x) {
@ -46,8 +47,9 @@ define([
var href = '/'+ x[0] +'/'; var href = '/'+ x[0] +'/';
var attr = isEnabled ? { href: href } : { var attr = isEnabled ? { href: href } : {
onclick: function () { onclick: function () {
sessionStorage.redirectTo = href; var href = Hash.hashToHref('', 'login');
window.location.href = '/login/'; var url = Hash.getNewPadURL(href, { href: href });
window.location.href = url;
} }
}; };
if (!isEnabled) { if (!isEnabled) {

@ -169,6 +169,17 @@ Version 1
/code/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI /code/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI
*/ */
var getLoginOpts = function (hashArr) {
var k;
// Check if we have a ownerKey for this pad
hashArr.some(function (data) {
if (/^login=/.test(data)) {
k = data.slice(6);
return true;
}
});
return k || '';
};
var getNewPadOpts = function (hashArr) { var getNewPadOpts = function (hashArr) {
var k; var k;
// Check if we have a ownerKey for this pad // Check if we have a ownerKey for this pad
@ -214,28 +225,51 @@ Version 1
parsed.embed = options.indexOf('embed') !== -1; parsed.embed = options.indexOf('embed') !== -1;
parsed.versionHash = getVersionHash(options); parsed.versionHash = getVersionHash(options);
parsed.newPadOpts = getNewPadOpts(options); parsed.newPadOpts = getNewPadOpts(options);
parsed.loginOpts = getLoginOpts(options);
parsed.ownerKey = getOwnerKey(options); parsed.ownerKey = getOwnerKey(options);
}; };
// Version 4: only login or newpad options, smae for all the apps
if (hashArr[1] && hashArr[1] === '4') {
parsed.getHash = function (opts) {
if (!opts || !Object.keys(opts).length) { return ''; }
var hash = '/4/';
if (opts.newPadOpts) { hash += 'newpad=' + opts.newPadOpts + '/'; }
if (opts.loginOpts) { hash += 'login=' + opts.loginOpts + '/'; }
return hash;
};
parsed.getOptions = function () {
var options = {};
if (parsed.newPadOpts) { options.newPadOpts = parsed.newPadOpts; }
if (parsed.loginOpts) { options.loginOpts = parsed.loginOpts; }
return options;
};
parsed.version = 4;
options = hashArr.slice(2);
addOptions();
return parsed;
}
// The other versions depends on the type
if (['media', 'file', 'user', 'invite'].indexOf(type) === -1) { if (['media', 'file', 'user', 'invite'].indexOf(type) === -1) {
parsed.type = 'pad'; parsed.type = 'pad';
parsed.getHash = function () { return hash; }; parsed.getHash = function () {
return hash;
};
parsed.getOptions = function () { parsed.getOptions = function () {
return { return {
embed: parsed.embed, embed: parsed.embed,
present: parsed.present, present: parsed.present,
ownerKey: parsed.ownerKey, ownerKey: parsed.ownerKey,
versionHash: parsed.versionHash, versionHash: parsed.versionHash,
newPadOpts: parsed.newPadOpts,
loginOpts: parsed.loginOpts,
password: parsed.password password: parsed.password
}; };
}; };
if (/^\/newpad=/.test(hash)) {
return {
newPadOpts: hash.slice(8, -1)
};
}
if (hash.slice(0,1) !== '/' && hash.length >= 56) { // Version 0 if (hash.slice(0,1) !== '/' && hash.length >= 56) { // Version 0
// Old hash // Old hash
parsed.channel = hash.slice(0, 32); parsed.channel = hash.slice(0, 32);
@ -256,9 +290,8 @@ Version 1
if (versionHash) { if (versionHash) {
hash += 'hash=' + Crypto.b64RemoveSlashes(versionHash) + '/'; hash += 'hash=' + Crypto.b64RemoveSlashes(versionHash) + '/';
} }
if (opts.newPadOpts) { if (opts.newPadOpts) { hash += 'newpad=' + opts.newPadOpts + '/'; }
hash += 'newpad=' + opts.newPadOpts + '/'; if (opts.loginOpts) { hash += 'login=' + opts.loginOpts + '/'; }
}
return hash; return hash;
}; };
@ -306,6 +339,8 @@ Version 1
embed: parsed.embed, embed: parsed.embed,
present: parsed.present, present: parsed.present,
ownerKey: parsed.ownerKey, ownerKey: parsed.ownerKey,
newPadOpts: parsed.newPadOpts,
loginOpts: parsed.loginOpts,
password: parsed.password password: parsed.password
}; };
}; };
@ -317,6 +352,8 @@ Version 1
if (parsed.password || opts.password) { hash += 'p/'; } if (parsed.password || opts.password) { hash += 'p/'; }
if (opts.embed) { hash += 'embed/'; } if (opts.embed) { hash += 'embed/'; }
if (opts.present) { hash += 'present/'; } if (opts.present) { hash += 'present/'; }
if (opts.newPadOpts) { hash += 'newpad=' + opts.newPadOpts + '/'; }
if (opts.loginOpts) { hash += 'login=' + opts.loginOpts + '/'; }
return hash; return hash;
}; };
@ -389,18 +426,26 @@ Version 1
var idx; var idx;
// When we start without a hash, use version 4 links to add login or newpad options
var getHash = function (opts) {
if (!opts || !Object.keys(opts).length) { return ''; }
var hash = '/4/';
if (opts.newPadOpts) { hash += 'newpad=' + opts.newPadOpts + '/'; }
if (opts.loginOpts) { hash += 'login=' + opts.loginOpts + '/'; }
return hash;
};
ret.getUrl = function (options) { ret.getUrl = function (options) {
options = options || {}; options = options || {};
var url = '/'; var url = '/';
if (!ret.type) { return url; } if (!ret.type) { return url; }
url += ret.type + '/'; url += ret.type + '/';
// New pad with options: append the options to the hash // New pad with options: append the options to the hash
if (!ret.hashData && options.newPadOpts) { if (!ret.hashData && options && Object.keys(options).length) {
return url + '#/newpad=' + options.newPadOpts + '/'; return url + '#' + getHash(options);
} }
if (!ret.hashData) { return url; } if (!ret.hashData) { return url; }
if (ret.hashData.type !== 'pad') { return url + '#' + ret.hash; } //if (ret.hashData.version === 0) { return url + '#' + ret.hash; }
if (ret.hashData.version === 0) { return url + '#' + ret.hash; } //if (ret.hashData.type !== 'pad') { return url + '#' + ret.hash; }
var hash = ret.hashData.getHash(options); var hash = ret.hashData.getHash(options);
url += '#' + hash; url += '#' + hash;
return url; return url;
@ -549,7 +594,6 @@ Version 1
secret = JSON.parse(JSON.stringify(secret)); secret = JSON.parse(JSON.stringify(secret));
if (!secret.keys && !secret.key) { if (!secret.keys && !secret.key) {
console.error('e');
return hashes; return hashes;
} else if (!secret.keys) { } else if (!secret.keys) {
secret.keys = {}; secret.keys = {};
@ -615,6 +659,29 @@ Version 1
return true; return true;
}; };
Hash.decodeDataOptions = function (opts) {
var b64 = decodeURIComponent(opts);
var str = Nacl.util.encodeUTF8(Nacl.util.decodeBase64(b64));
return JSON.parse(str);
};
Hash.encodeDataOptions = function (opts) {
var str = JSON.stringify(opts);
var b64 = Nacl.util.encodeBase64(Nacl.util.decodeUTF8(str));
return encodeURIComponent(b64);
};
Hash.getNewPadURL = function (href, opts) {
var parsed = Hash.parsePadUrl(href);
var options = parsed.getOptions();
options.newPadOpts = Hash.encodeDataOptions(opts);
return parsed.getUrl(options);
};
Hash.getLoginURL = function (href, opts) {
var parsed = Hash.parsePadUrl(href);
var options = parsed.getOptions();
options.loginOpts = Hash.encodeDataOptions(opts);
return parsed.getUrl(options);
};
return Hash; return Hash;
}; };

@ -254,20 +254,15 @@ define([
className: 'secondary', className: 'secondary',
name: Messages.login_register, name: Messages.login_register,
onClick: function () { onClick: function () {
common.setLoginRedirect(function () { common.setLoginRedirect('register');
common.gotoURL('/register/');
});
} }
}, { }, {
className: 'secondary', className: 'secondary',
name: Messages.login_login, name: Messages.login_login,
onClick: function () { onClick: function () {
common.setLoginRedirect(function () { common.setLoginRedirect('login');
common.gotoURL('/login/');
});
} }
} }]
]
}; };
} }
}; };
@ -1787,9 +1782,7 @@ define([
attributes: {'class': 'cp-toolbar-menu-login fa fa-sign-in'}, attributes: {'class': 'cp-toolbar-menu-login fa fa-sign-in'},
content: h('span', Messages.login_login), content: h('span', Messages.login_login),
action: function () { action: function () {
Common.setLoginRedirect(function () { Common.setLoginRedirect('login');
window.parent.location = origin+'/login/';
});
}, },
}); });
options.push({ options.push({
@ -1797,9 +1790,7 @@ define([
attributes: {'class': 'cp-toolbar-menu-register fa fa-user-plus'}, attributes: {'class': 'cp-toolbar-menu-register fa fa-user-plus'},
content: h('span', Messages.login_register), content: h('span', Messages.login_register),
action: function () { action: function () {
Common.setLoginRedirect(function () { Common.setLoginRedirect('register');
window.parent.location = origin+'/register/';
});
}, },
}); });
} }
@ -1924,8 +1915,6 @@ define([
$modal.find('.cp-modal').append($title); $modal.find('.cp-modal').append($title);
$modal.find('.cp-modal').append($description); $modal.find('.cp-modal').append($description);
var $advanced;
var $container = $('<div>'); var $container = $('<div>');
var i = 0; var i = 0;
var types = AppConfig.availablePadTypes.filter(function (p) { var types = AppConfig.availablePadTypes.filter(function (p) {
@ -1949,15 +1938,7 @@ define([
$element.attr('data-type', p); $element.attr('data-type', p);
$element.click(function () { $element.click(function () {
$modal.hide(); $modal.hide();
if ($advanced && Util.isChecked($advanced)) { common.openURL('/' + p + '/');
common.sessionStorage.put(Constants.displayPadCreationScreen, true, function (){
common.openURL('/' + p + '/');
});
return;
}
common.sessionStorage.put(Constants.displayPadCreationScreen, "", function () {
common.openURL('/' + p + '/');
});
}); });
}); });
@ -1982,12 +1963,6 @@ define([
} }
return; return;
} }
if (e.which === 32 && $advanced) {
$advanced.prop('checked', !$advanced.prop('checked'));
$modal.focus();
e.stopPropagation();
e.preventDefault();
}
}); });
@ -2752,13 +2727,8 @@ define([
$(link).click(function (e) { $(link).click(function (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if (msg.content.password) { var obj = { pw: msg.content.password || '' };
common.sessionStorage.put('newPadPassword', msg.content.password, function () { common.openURL(Hash.getNewPadURL(msg.content.href, obj));
common.openURL(msg.content.href);
});
return;
}
common.openURL(msg.content.href);
}); });
var div = h('div', [ var div = h('div', [

@ -1879,8 +1879,9 @@ define([
LocalStore.logout(); LocalStore.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 = currentPad.href; var href = Hash.hashToHref('', 'login');
window.location.href = '/login/'; var url = Hash.getNewPadURL(href, { href: currentPad.href });
window.location.href = url;
}; };
common.startAccountDeletion = function (data, cb) { common.startAccountDeletion = function (data, cb) {
@ -2276,12 +2277,6 @@ define([
if (data.anonHash && !cfg.userHash) { LocalStore.setFSHash(data.anonHash); } if (data.anonHash && !cfg.userHash) { LocalStore.setFSHash(data.anonHash); }
/*if (cfg.userHash && sessionStorage) {
// copy User_hash into sessionStorage because cross-domain iframes
// on safari replaces localStorage with sessionStorage or something
sessionStorage.setItem(Constants.userHashKey, cfg.userHash);
}*/
if (cfg.userHash) { if (cfg.userHash) {
var localToken = tryParsing(localStorage.getItem(Constants.tokenKey)); var localToken = tryParsing(localStorage.getItem(Constants.tokenKey));
if (localToken === null) { if (localToken === null) {
@ -2336,21 +2331,18 @@ define([
postMessage("DISCONNECT"); postMessage("DISCONNECT");
}); });
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
if (sessionStorage.createReadme) { if (common.createReadme) {
var data = { var data = {
driveReadme: Messages.driveReadme, driveReadme: Messages.driveReadme,
driveReadmeTitle: Messages.driveReadmeTitle, driveReadmeTitle: Messages.driveReadmeTitle,
}; };
postMessage("CREATE_README", data, waitFor(function (e) { postMessage("CREATE_README", data, waitFor(function (e) {
if (e && e.error) { return void console.error(e.error); } if (e && e.error) { return void console.error(e.error); }
delete sessionStorage.createReadme;
})); }));
} }
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
if (sessionStorage.migrateAnonDrive) { if (common.migrateAnonDrive) {
common.mergeAnonDrive(waitFor(function() { common.mergeAnonDrive(waitFor());
delete sessionStorage.migrateAnonDrive;
}));
} }
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
if (AppConfig.afterLogin) { if (AppConfig.afterLogin) {

@ -1126,16 +1126,13 @@ define([
window.open(APP.origin + hiddenHref); window.open(APP.origin + hiddenHref);
}; };
var openIn = function (type, path, team, fData) { var openIn = function (type, path, team, fData) {
var obj = JSON.stringify({ var obj = {
p: path, p: path,
t: team, t: team,
d: fData d: fData
}); };
var str = encodeURIComponent(obj); var href = Hash.hashToHref('', type);
var parsed = Hash.parsePadUrl(Hash.hashToHref('', type)); common.openURL(Hash.getNewPadURL(href, obj));
var opts = parsed.getOptions();
opts.newPadOpts = str;
common.openURL(parsed.getUrl(opts));
}; };
var refresh = APP.refresh = function () { var refresh = APP.refresh = function () {
@ -4252,13 +4249,6 @@ define([
if (paths.length !== 1) { return; } if (paths.length !== 1) { return; }
var p = paths[0]; var p = paths[0];
el = manager.find(p.path); el = manager.find(p.path);
var metadata = manager.getFileData(el);
var simpleData = {
title: metadata.filename || metadata.title,
href: metadata.href,
password: metadata.password,
channel: metadata.channel,
};
(function () { (function () {
var path = currentPath; var path = currentPath;
if (path[0] !== ROOT) { path = [ROOT]; } if (path[0] !== ROOT) { path = [ROOT]; }
@ -4269,7 +4259,6 @@ define([
password: _metadata.password, password: _metadata.password,
channel: _metadata.channel, channel: _metadata.channel,
}; };
var parsed = Hash.parsePadUrl(_metadata.href || _metadata.roHref);
openIn('code', path, APP.team, _simpleData); openIn('code', path, APP.team, _simpleData);
})(); })();
} }

@ -7,8 +7,7 @@ define([
'/common/common-util.js', '/common/common-util.js',
'/common/common-constants.js', '/common/common-constants.js',
'/customize/messages.js', '/customize/messages.js',
'/bower_components/nthen/index.js' ], function($, h, Hash, UI, UIElements, Util, Constants, Messages) {
], function($, h, Hash, UI, UIElements, Util, Constants, Messages, nThen) {
var handlers = {}; var handlers = {};
@ -108,16 +107,12 @@ define([
return Messages._getKey(key, [name, title, teamName]); return Messages._getKey(key, [name, title, teamName]);
}; };
content.handler = function() { content.handler = function() {
var obj = JSON.stringify({ var obj = {
p: msg.content.isTemplate ? ['template'] : undefined, p: msg.content.isTemplate ? ['template'] : undefined,
t: teamNotification || undefined, t: teamNotification || undefined,
pw: msg.content.password || '' pw: msg.content.password || ''
}); };
var str = encodeURIComponent(obj); common.openURL(Hash.getNewPadURL(msg.content.href, obj));
var parsed = Hash.parsePadUrl(msg.content.href);
var opts = parsed.getOptions();
opts.newPadOpts = str;
common.openURL(parsed.getUrl(opts));
defaultDismiss(common, data)(); defaultDismiss(common, data)();
}; };
if (!content.archived) { if (!content.archived) {

@ -458,15 +458,11 @@ define([
var actions = h('div', [cancel, register, login]); var actions = h('div', [cancel, register, login]);
var modal = UI.cornerPopup(Messages.oo_login, actions, '', {alt: true}); var modal = UI.cornerPopup(Messages.oo_login, actions, '', {alt: true});
$(register).click(function () { $(register).click(function () {
common.setLoginRedirect(function () { common.setLoginRedirect('register');
common.gotoURL('/register/');
});
modal.delete(); modal.delete();
}); });
$(login).click(function () { $(login).click(function () {
common.setLoginRedirect(function () { common.setLoginRedirect('login');
common.gotoURL('/login/');
});
modal.delete(); modal.delete();
}); });
$(cancel).click(function () { $(cancel).click(function () {

@ -321,6 +321,11 @@ define([
var channel = content.channel || content.teamChannel; var channel = content.channel || content.teamChannel;
if (content.password) {
var key = ctx.store.driveSecret.keys.cryptKey;
content.password = Crypto.encrypt(content.password, key);
}
if (addOwners[channel]) { return void cb(true); } if (addOwners[channel]) { return void cb(true); }
addOwners[channel] = { addOwners[channel] = {
type: box.type, type: box.type,

@ -131,12 +131,28 @@ define([
if (sframeChan) { sframeChan.event('EV_LOADING_INFO', data); } if (sframeChan) { sframeChan.event('EV_LOADING_INFO', data); }
}); });
try {
var parsed = Utils.Hash.parsePadUrl(currentPad.href);
var options = parsed.getOptions();
if (options.loginOpts) {
var loginOpts = Utils.Hash.decodeDataOptions(options.loginOpts);
if (loginOpts.createReadme) { Cryptpad.createReadme = true; }
if (loginOpts.mergeAnonDrive) { Cryptpad.migrateAnonDrive = true; }
// Remove newPadOpts from the hash
delete options.loginOpts;
currentPad.href = parsed.getUrl(options);
currentPad.hash = parsed.hashData.getHash ? parsed.hashData.getHash(options)
: '';
}
} catch (e) { console.error(e); }
Cryptpad.ready(waitFor(), { Cryptpad.ready(waitFor(), {
driveEvents: cfg.driveEvents, driveEvents: cfg.driveEvents,
currentPad: currentPad currentPad: currentPad
}); });
if (window.history && window.history.replaceState && currentPad.hash) { // Remove the login hash if needed
if (window.history && window.history.replaceState && (currentPad.hash || window.location.hash)) {
var nHash = currentPad.hash; var nHash = currentPad.hash;
if (!/^#/.test(nHash)) { nHash = '#' + nHash; } if (!/^#/.test(nHash)) { nHash = '#' + nHash; }
window.history.replaceState({}, window.document.title, nHash); window.history.replaceState({}, window.document.title, nHash);
@ -202,9 +218,10 @@ define([
}; };
// New pad options // New pad options
if (parsed.hashData && parsed.hashData.newPadOpts) { var options = parsed.getOptions();
if (options.newPadOpts) {
try { try {
var newPad = JSON.parse(decodeURIComponent(parsed.hashData.newPadOpts)); var newPad = Utils.Hash.decodeDataOptions(options.newPadOpts);
Cryptpad.initialTeam = newPad.t; Cryptpad.initialTeam = newPad.t;
Cryptpad.initialPath = newPad.p; Cryptpad.initialPath = newPad.p;
if (newPad.pw) { if (newPad.pw) {
@ -225,22 +242,20 @@ define([
} catch (e) { } catch (e) {
console.error(e, parsed.hashData.newPadOpts); console.error(e, parsed.hashData.newPadOpts);
} }
delete parsed.hashData.newPadOpts; delete options.newPadOpts;
currentPad.href = parsed.getUrl(options);
currentPad.hash = parsed.hashData.getHash ? parsed.hashData.getHash(options)
: '';
var version = parsed.hashData.version;
parsed = Utils.Hash.parsePadUrl(currentPad.href);
Cryptpad.setTabHash(currentPad.hash);
// If it's a new pad, don't check password // If it's a new pad, don't check password
if (!Object.keys(parsed.hashData).length) { if (version === 4) {
delete parsed.hashData;
parsed.hash = '';
currentPad.hash = '';
Cryptpad.setTabHash('');
return void todo(); return void todo();
} }
// Otherwise, existing pad (new for us) // Otherwise, continue
var opts = parsed.getOptions();
delete opts.newPadOpts;
parsed = Utils.Hash.parsePadUrl(parsed.getUrl(opts));
currentPad.hash = parsed.hash;
Cryptpad.setTabHash(parsed.hash);
} }
@ -460,9 +475,6 @@ define([
var defaultTitle = Utils.UserObject.getDefaultName(parsed); var defaultTitle = Utils.UserObject.getDefaultName(parsed);
var edPublic, curvePublic, notifications, isTemplate; var edPublic, curvePublic, notifications, isTemplate;
var settings = {}; var settings = {};
var forceCreationScreen = cfg.useCreationScreen &&
sessionStorage[Utils.Constants.displayPadCreationScreen];
delete sessionStorage[Utils.Constants.displayPadCreationScreen];
var isSafe = ['debug', 'profile', 'drive', 'teams'].indexOf(currentPad.app) !== -1; var isSafe = ['debug', 'profile', 'drive', 'teams'].indexOf(currentPad.app) !== -1;
var updateMeta = function () { var updateMeta = function () {
//console.log('EV_METADATA_UPDATE'); //console.log('EV_METADATA_UPDATE');
@ -507,7 +519,6 @@ define([
}, },
isNewFile: isNewFile, isNewFile: isNewFile,
isDeleted: isNewFile && currentPad.hash.length > 0, isDeleted: isNewFile && currentPad.hash.length > 0,
forceCreationScreen: forceCreationScreen,
password: password, password: password,
channel: secret.channel, channel: secret.channel,
enableSF: localStorage.CryptPad_SF === "1", // TODO to remove when enabled by default enableSF: localStorage.CryptPad_SF === "1", // TODO to remove when enabled by default
@ -635,9 +646,10 @@ define([
Cryptpad.mailbox.execCommand(data, cb); Cryptpad.mailbox.execCommand(data, cb);
}); });
sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) { sframeChan.on('EV_SET_LOGIN_REDIRECT', function (page) {
sessionStorage.redirectTo = currentPad.href; var href = Utils.Hash.hashToHref('', page);
cb(); var url = Utils.Hash.getNewPadURL(href, { href: currentPad.href });
window.location.href = url;
}); });
sframeChan.on('Q_STORE_IN_TEAM', function (data, cb) { sframeChan.on('Q_STORE_IN_TEAM', function (data, cb) {
@ -1065,11 +1077,10 @@ define([
password: password, password: password,
title: currentTitle title: currentTitle
}; };
sessionStorage[Utils.Constants.newPadFileData] = JSON.stringify(data); var obj = { d: data };
window.open(window.location.pathname); var href = window.location.pathname;
setTimeout(function () { var url = Utils.Hash.getNewPadURL(href, obj);
delete sessionStorage[Utils.Constants.newPadFileData]; window.open(url);
}, 100);
}); });
// Messaging // Messaging

@ -307,9 +307,8 @@ define([
ctx.sframeChan.event('EV_SET_HASH', hash); ctx.sframeChan.event('EV_SET_HASH', hash);
}; };
funcs.setLoginRedirect = function (cb) { funcs.setLoginRedirect = function (page) {
cb = cb || $.noop; ctx.sframeChan.query('EV_SET_LOGIN_REDIRECT', page);
ctx.sframeChan.query('Q_SET_LOGIN_REDIRECT', null, cb);
}; };
funcs.isPresentUrl = function (cb) { funcs.isPresentUrl = function (cb) {
@ -758,9 +757,7 @@ define([
var mustLogin = privateData.registeredOnly; var mustLogin = privateData.registeredOnly;
if (mustLogin) { if (mustLogin) {
UI.alert(Messages.mustLogin, function () { UI.alert(Messages.mustLogin, function () {
funcs.setLoginRedirect(function () { funcs.setLoginRedirect('login');
funcs.gotoURL('/login/');
});
}, {forefront: true}); }, {forefront: true});
return; return;
} }

@ -773,15 +773,11 @@ MessengerUI, Messages) {
]); ]);
$msg.find('a.cp-pnp-login').click(function (ev) { $msg.find('a.cp-pnp-login').click(function (ev) {
ev.preventDefault(); ev.preventDefault();
Common.setLoginRedirect(function () { Common.setLoginRedirect('login');
window.parent.location = o + '/login/';
});
}); });
$msg.find('a.cp-pnp-register').click(function (ev) { $msg.find('a.cp-pnp-register').click(function (ev) {
ev.preventDefault(); ev.preventDefault();
Common.setLoginRedirect(function () { Common.setLoginRedirect('register');
window.parent.location = o + '/register/';
});
}); });
$('.cp-toolbar-top').append($msg); $('.cp-toolbar-top').append($msg);
//UI.addTooltips(); //UI.addTooltips();

@ -53,14 +53,9 @@ define([
}; };
window.addEventListener('message', onMsg); window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
var hash = localStorage[Constants.userHashKey]; var hash = localStorage[Constants.userHashKey] || localStorage[Constants.fileHashKey];
var drive = hash && ('#'+hash === window.location.hash); var drive = hash && ('#'+hash === window.location.hash);
if (!window.location.hash) { if (!window.location.hash) {
if (!hash) {
sessionStorage.redirectTo = '/debug/';
window.location.href = '/login/';
return;
}
drive = true; drive = true;
window.location.hash = hash; window.location.hash = hash;
} else { } else {

@ -46,9 +46,12 @@ define([
window.addEventListener('message', onMsg); window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
var afterSecrets = function (Cryptpad, Utils, secret, cb, sframeChan) { var afterSecrets = function (Cryptpad, Utils, secret, cb, sframeChan) {
var _hash = hash.slice(1); var parsed = Utils.Hash.parsePadUrl(href);
if (_hash && Utils.LocalStore.isLoggedIn()) { var isSf = parsed.hashData && parsed.hashData.type === 'pad';
// Add a shared folder! if (!isSf) { return void cb(); }
// SF and logged in: add shared folder
if (Utils.LocalStore.isLoggedIn()) {
Cryptpad.addSharedFolder(null, secret, function (id) { Cryptpad.addSharedFolder(null, secret, function (id) {
if (id && typeof(id) === "object" && id.error) { if (id && typeof(id) === "object" && id.error) {
sframeChan.event("EV_RESTRICTED_ERROR"); sframeChan.event("EV_RESTRICTED_ERROR");
@ -65,16 +68,16 @@ define([
cb(); cb();
}); });
return; return;
} else if (_hash) {
var id = Utils.Util.createRandomInteger();
window.CryptPad_newSharedFolder = id;
var data = {
href: Utils.Hash.getRelativeHref(Cryptpad.currentPad.href),
password: secret.password
};
return void Cryptpad.loadSharedFolder(id, data, cb);
} }
cb();
// Anon shared folder
var id = Utils.Util.createRandomInteger();
window.CryptPad_newSharedFolder = id;
var data = {
href: Utils.Hash.getRelativeHref(Cryptpad.currentPad.href),
password: secret.password
};
Cryptpad.loadSharedFolder(id, data, cb);
}; };
var addRpc = function (sframeChan, Cryptpad, Utils) { var addRpc = function (sframeChan, Cryptpad, Utils) {
sframeChan.on('EV_BURN_ANON_DRIVE', function () { sframeChan.on('EV_BURN_ANON_DRIVE', function () {

@ -231,9 +231,7 @@ define([
if (!common.isLoggedIn()) { if (!common.isLoggedIn()) {
UI.removeLoadingScreen(); UI.removeLoadingScreen();
return UI.alert(Messages.upload_mustLogin, function () { return UI.alert(Messages.upload_mustLogin, function () {
common.setLoginRedirect(function () { common.setLoginRedirect('login');
common.gotoURL('/login/');
});
}); });
} }

@ -611,15 +611,11 @@ define([
var actions = h('div', [cancel, register, login]); var actions = h('div', [cancel, register, login]);
var modal = UI.cornerPopup(Messages.profile_login, actions, '', {alt: true}); var modal = UI.cornerPopup(Messages.profile_login, actions, '', {alt: true});
$(register).click(function () { $(register).click(function () {
common.setLoginRedirect(function () { common.setLoginRedirect('register');
common.gotoURL('/register/');
});
modal.delete(); modal.delete();
}); });
$(login).click(function () { $(login).click(function () {
common.setLoginRedirect(function () { common.setLoginRedirect('login');
common.gotoURL('/login/');
});
modal.delete(); modal.delete();
}); });
$(cancel).click(function () { $(cancel).click(function () {

@ -86,12 +86,6 @@ define([
} }
metaObj = n; metaObj = n;
})); }));
if (typeof(isTemplate) === "undefined") {
Cryptpad.isTemplate(currentPad.href, waitFor(function (err, t) {
if (err) { console.log(err); }
isTemplate = t;
}));
}
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
metaObj.doc = {}; metaObj.doc = {};
var additionalPriv = { var additionalPriv = {

@ -1267,14 +1267,10 @@ define([
anonRegister = h('button.btn.btn-secondary', Messages.login_register), anonRegister = h('button.btn.btn-secondary', Messages.login_register),
])); ]));
$(anonLogin).click(function () { $(anonLogin).click(function () {
common.setLoginRedirect(function () { common.setLoginRedirect('login');
common.gotoURL('/login/');
});
}); });
$(anonRegister).click(function () { $(anonRegister).click(function () {
common.setLoginRedirect(function () { common.setLoginRedirect('register');
common.gotoURL('/register/');
});
}); });
waitFor.abort(); waitFor.abort();
}).nThen(function () { }).nThen(function () {
@ -1402,9 +1398,7 @@ define([
var hash = privateData.teamInviteHash; var hash = privateData.teamInviteHash;
if (!hash && !driveAPP.loggedIn) { if (!hash && !driveAPP.loggedIn) {
UI.alert(Messages.mustLogin, function () { UI.alert(Messages.mustLogin, function () {
common.setLoginRedirect(function () { common.setLoginRedirect('login');
common.gotoURL('/login/');
});
}, {forefront: true}); }, {forefront: true});
return; return;
} }

Loading…
Cancel
Save