From 589d32c0629c6a98cc5e3efaee6398468808e657 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 30 Oct 2020 15:00:12 +0100 Subject: [PATCH] Stop using sessionStorage for login redirect and new pad options --- customize.dist/login.js | 31 +++++++-- customize.dist/pages/features.js | 8 --- customize.dist/pages/index.js | 8 ++- www/common/common-hash.js | 97 +++++++++++++++++++++++----- www/common/common-ui-elements.js | 46 +++---------- www/common/cryptpad-common.js | 20 ++---- www/common/drive-ui.js | 19 ++---- www/common/notifications.js | 13 ++-- www/common/onlyoffice/inner.js | 8 +-- www/common/outer/mailbox-handlers.js | 5 ++ www/common/sframe-common-outer.js | 65 +++++++++++-------- www/common/sframe-common.js | 9 +-- www/common/toolbar.js | 8 +-- www/debug/main.js | 7 +- www/drive/main.js | 27 ++++---- www/file/inner.js | 4 +- www/profile/inner.js | 8 +-- www/secureiframe/main.js | 6 -- www/teams/inner.js | 12 +--- 19 files changed, 207 insertions(+), 194 deletions(-) diff --git a/customize.dist/login.js b/customize.dist/login.js index 35121f113..d07d4c4c3 100644 --- a/customize.dist/login.js +++ b/customize.dist/login.js @@ -28,6 +28,19 @@ define([ }; 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 dispense = Cred.dispenser(bytes); @@ -118,11 +131,11 @@ define([ }; var setMergeAnonDrive = function () { - sessionStorage.migrateAnonDrive = 1; + Exports.mergeAnonDrive = 1; }; var setCreateReadme = function () { - sessionStorage.createReadme = 1; + Exports.createReadme = 1; }; Exports.loginOrRegister = function (uname, passwd, isRegister, shouldImport, cb) { @@ -416,12 +429,20 @@ define([ }); }; Exports.redirect = function () { - if (sessionStorage.redirectTo) { - var h = sessionStorage.redirectTo; + if (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'); parser.href = h; if (parser.origin === window.location.origin) { - delete sessionStorage.redirectTo; window.location.href = h; return; } diff --git a/customize.dist/pages/features.js b/customize.dist/pages/features.js index 6403ec36a..56bb29664 100644 --- a/customize.dist/pages/features.js +++ b/customize.dist/pages/features.js @@ -22,14 +22,6 @@ define([ target: '_blank', rel: 'noopener noreferrer' }, 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 = h('div.col-12.col-sm-4.cp-anon-user',[ diff --git a/customize.dist/pages/index.js b/customize.dist/pages/index.js index 300637748..c718b363f 100644 --- a/customize.dist/pages/index.js +++ b/customize.dist/pages/index.js @@ -4,12 +4,13 @@ define([ '/common/hyperscript.js', '/common/common-feedback.js', '/common/common-interface.js', + '/common/common-hash.js', '/common/textFit.min.js', '/customize/messages.js', '/customize/application_config.js', '/common/outer/local-store.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 isAvailableType = function (x) { @@ -46,8 +47,9 @@ define([ var href = '/'+ x[0] +'/'; var attr = isEnabled ? { href: href } : { onclick: function () { - sessionStorage.redirectTo = href; - window.location.href = '/login/'; + var href = Hash.hashToHref('', 'login'); + var url = Hash.getNewPadURL(href, { href: href }); + window.location.href = url; } }; if (!isEnabled) { diff --git a/www/common/common-hash.js b/www/common/common-hash.js index ff8764da4..06a1d7fef 100644 --- a/www/common/common-hash.js +++ b/www/common/common-hash.js @@ -169,6 +169,17 @@ Version 1 /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 k; // Check if we have a ownerKey for this pad @@ -214,28 +225,51 @@ Version 1 parsed.embed = options.indexOf('embed') !== -1; parsed.versionHash = getVersionHash(options); parsed.newPadOpts = getNewPadOpts(options); + parsed.loginOpts = getLoginOpts(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) { parsed.type = 'pad'; - parsed.getHash = function () { return hash; }; + parsed.getHash = function () { + return hash; + }; parsed.getOptions = function () { return { embed: parsed.embed, present: parsed.present, ownerKey: parsed.ownerKey, versionHash: parsed.versionHash, + newPadOpts: parsed.newPadOpts, + loginOpts: parsed.loginOpts, password: parsed.password }; }; - if (/^\/newpad=/.test(hash)) { - return { - newPadOpts: hash.slice(8, -1) - }; - } - if (hash.slice(0,1) !== '/' && hash.length >= 56) { // Version 0 // Old hash parsed.channel = hash.slice(0, 32); @@ -256,9 +290,8 @@ Version 1 if (versionHash) { hash += 'hash=' + Crypto.b64RemoveSlashes(versionHash) + '/'; } - if (opts.newPadOpts) { - hash += 'newpad=' + opts.newPadOpts + '/'; - } + if (opts.newPadOpts) { hash += 'newpad=' + opts.newPadOpts + '/'; } + if (opts.loginOpts) { hash += 'login=' + opts.loginOpts + '/'; } return hash; }; @@ -306,6 +339,8 @@ Version 1 embed: parsed.embed, present: parsed.present, ownerKey: parsed.ownerKey, + newPadOpts: parsed.newPadOpts, + loginOpts: parsed.loginOpts, password: parsed.password }; }; @@ -317,6 +352,8 @@ Version 1 if (parsed.password || opts.password) { hash += 'p/'; } if (opts.embed) { hash += 'embed/'; } if (opts.present) { hash += 'present/'; } + if (opts.newPadOpts) { hash += 'newpad=' + opts.newPadOpts + '/'; } + if (opts.loginOpts) { hash += 'login=' + opts.loginOpts + '/'; } return hash; }; @@ -389,18 +426,26 @@ Version 1 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) { options = options || {}; var url = '/'; if (!ret.type) { return url; } url += ret.type + '/'; // New pad with options: append the options to the hash - if (!ret.hashData && options.newPadOpts) { - return url + '#/newpad=' + options.newPadOpts + '/'; + if (!ret.hashData && options && Object.keys(options).length) { + return url + '#' + getHash(options); } 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); url += '#' + hash; return url; @@ -549,7 +594,6 @@ Version 1 secret = JSON.parse(JSON.stringify(secret)); if (!secret.keys && !secret.key) { - console.error('e'); return hashes; } else if (!secret.keys) { secret.keys = {}; @@ -615,6 +659,29 @@ Version 1 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; }; diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 2d0e02b14..e977f1f49 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -254,20 +254,15 @@ define([ className: 'secondary', name: Messages.login_register, onClick: function () { - common.setLoginRedirect(function () { - common.gotoURL('/register/'); - }); + common.setLoginRedirect('register'); } }, { className: 'secondary', name: Messages.login_login, onClick: function () { - common.setLoginRedirect(function () { - common.gotoURL('/login/'); - }); + common.setLoginRedirect('login'); } - } - ] + }] }; } }; @@ -1788,9 +1783,7 @@ define([ attributes: {'class': 'cp-toolbar-menu-login fa fa-sign-in'}, content: h('span', Messages.login_login), action: function () { - Common.setLoginRedirect(function () { - window.parent.location = origin+'/login/'; - }); + Common.setLoginRedirect('login'); }, }); options.push({ @@ -1798,9 +1791,7 @@ define([ attributes: {'class': 'cp-toolbar-menu-register fa fa-user-plus'}, content: h('span', Messages.login_register), action: function () { - Common.setLoginRedirect(function () { - window.parent.location = origin+'/register/'; - }); + Common.setLoginRedirect('register'); }, }); } @@ -1925,8 +1916,6 @@ define([ $modal.find('.cp-modal').append($title); $modal.find('.cp-modal').append($description); - var $advanced; - var $container = $('
'); var i = 0; var types = AppConfig.availablePadTypes.filter(function (p) { @@ -1950,15 +1939,7 @@ define([ $element.attr('data-type', p); $element.click(function () { $modal.hide(); - if ($advanced && Util.isChecked($advanced)) { - common.sessionStorage.put(Constants.displayPadCreationScreen, true, function (){ - common.openURL('/' + p + '/'); - }); - return; - } - common.sessionStorage.put(Constants.displayPadCreationScreen, "", function () { - common.openURL('/' + p + '/'); - }); + common.openURL('/' + p + '/'); }); }); @@ -1983,12 +1964,6 @@ define([ } return; } - if (e.which === 32 && $advanced) { - $advanced.prop('checked', !$advanced.prop('checked')); - $modal.focus(); - e.stopPropagation(); - e.preventDefault(); - } }); @@ -2753,13 +2728,8 @@ define([ $(link).click(function (e) { e.preventDefault(); e.stopPropagation(); - if (msg.content.password) { - common.sessionStorage.put('newPadPassword', msg.content.password, function () { - common.openURL(msg.content.href); - }); - return; - } - common.openURL(msg.content.href); + var obj = { pw: msg.content.password || '' }; + common.openURL(Hash.getNewPadURL(msg.content.href, obj)); }); var div = h('div', [ diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 70ebe5bcc..36413d89d 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1880,8 +1880,9 @@ define([ LocalStore.logout(); // redirect them to log in, and come back when they're done. - sessionStorage.redirectTo = currentPad.href; - window.location.href = '/login/'; + var href = Hash.hashToHref('', 'login'); + var url = Hash.getNewPadURL(href, { href: currentPad.href }); + window.location.href = url; }; common.startAccountDeletion = function (data, cb) { @@ -2277,12 +2278,6 @@ define([ 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) { var localToken = tryParsing(localStorage.getItem(Constants.tokenKey)); if (localToken === null) { @@ -2337,21 +2332,18 @@ define([ postMessage("DISCONNECT"); }); }).nThen(function (waitFor) { - if (sessionStorage.createReadme) { + if (common.createReadme) { var data = { driveReadme: Messages.driveReadme, driveReadmeTitle: Messages.driveReadmeTitle, }; postMessage("CREATE_README", data, waitFor(function (e) { if (e && e.error) { return void console.error(e.error); } - delete sessionStorage.createReadme; })); } }).nThen(function (waitFor) { - if (sessionStorage.migrateAnonDrive) { - common.mergeAnonDrive(waitFor(function() { - delete sessionStorage.migrateAnonDrive; - })); + if (common.migrateAnonDrive) { + common.mergeAnonDrive(waitFor()); } }).nThen(function (waitFor) { if (AppConfig.afterLogin) { diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 08a3f1279..53e496ef4 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -1126,16 +1126,13 @@ define([ window.open(APP.origin + hiddenHref); }; var openIn = function (type, path, team, fData) { - var obj = JSON.stringify({ + var obj = { p: path, t: team, d: fData - }); - var str = encodeURIComponent(obj); - var parsed = Hash.parsePadUrl(Hash.hashToHref('', type)); - var opts = parsed.getOptions(); - opts.newPadOpts = str; - common.openURL(parsed.getUrl(opts)); + }; + var href = Hash.hashToHref('', type); + common.openURL(Hash.getNewPadURL(href, obj)); }; var refresh = APP.refresh = function () { @@ -4252,13 +4249,6 @@ define([ if (paths.length !== 1) { return; } var p = paths[0]; 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 () { var path = currentPath; if (path[0] !== ROOT) { path = [ROOT]; } @@ -4269,7 +4259,6 @@ define([ password: _metadata.password, channel: _metadata.channel, }; - var parsed = Hash.parsePadUrl(_metadata.href || _metadata.roHref); openIn('code', path, APP.team, _simpleData); })(); } diff --git a/www/common/notifications.js b/www/common/notifications.js index 1686b87f9..caf5bfe00 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -7,8 +7,7 @@ define([ '/common/common-util.js', '/common/common-constants.js', '/customize/messages.js', - '/bower_components/nthen/index.js' -], function($, h, Hash, UI, UIElements, Util, Constants, Messages, nThen) { +], function($, h, Hash, UI, UIElements, Util, Constants, Messages) { var handlers = {}; @@ -108,16 +107,12 @@ define([ return Messages._getKey(key, [name, title, teamName]); }; content.handler = function() { - var obj = JSON.stringify({ + var obj = { p: msg.content.isTemplate ? ['template'] : undefined, t: teamNotification || undefined, pw: msg.content.password || '' - }); - var str = encodeURIComponent(obj); - var parsed = Hash.parsePadUrl(msg.content.href); - var opts = parsed.getOptions(); - opts.newPadOpts = str; - common.openURL(parsed.getUrl(opts)); + }; + common.openURL(Hash.getNewPadURL(msg.content.href, obj)); defaultDismiss(common, data)(); }; if (!content.archived) { diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index c265d2d2b..ce0dbcc3f 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -460,15 +460,11 @@ define([ var actions = h('div', [cancel, register, login]); var modal = UI.cornerPopup(Messages.oo_login, actions, '', {alt: true}); $(register).click(function () { - common.setLoginRedirect(function () { - common.gotoURL('/register/'); - }); + common.setLoginRedirect('register'); modal.delete(); }); $(login).click(function () { - common.setLoginRedirect(function () { - common.gotoURL('/login/'); - }); + common.setLoginRedirect('login'); modal.delete(); }); $(cancel).click(function () { diff --git a/www/common/outer/mailbox-handlers.js b/www/common/outer/mailbox-handlers.js index e5080b8e5..326b4afc7 100644 --- a/www/common/outer/mailbox-handlers.js +++ b/www/common/outer/mailbox-handlers.js @@ -321,6 +321,11 @@ define([ 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); } addOwners[channel] = { type: box.type, diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 0e51b1794..01a5ceaf8 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -131,12 +131,28 @@ define([ 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(), { driveEvents: cfg.driveEvents, 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; if (!/^#/.test(nHash)) { nHash = '#' + nHash; } window.history.replaceState({}, window.document.title, nHash); @@ -202,9 +218,10 @@ define([ }; // New pad options - if (parsed.hashData && parsed.hashData.newPadOpts) { + var options = parsed.getOptions(); + if (options.newPadOpts) { try { - var newPad = JSON.parse(decodeURIComponent(parsed.hashData.newPadOpts)); + var newPad = Utils.Hash.decodeDataOptions(options.newPadOpts); Cryptpad.initialTeam = newPad.t; Cryptpad.initialPath = newPad.p; if (newPad.pw) { @@ -225,22 +242,20 @@ define([ } catch (e) { 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 (!Object.keys(parsed.hashData).length) { - delete parsed.hashData; - parsed.hash = ''; - currentPad.hash = ''; - Cryptpad.setTabHash(''); + if (version === 4) { return void todo(); } - // Otherwise, existing pad (new for us) - var opts = parsed.getOptions(); - delete opts.newPadOpts; - parsed = Utils.Hash.parsePadUrl(parsed.getUrl(opts)); - currentPad.hash = parsed.hash; - Cryptpad.setTabHash(parsed.hash); + // Otherwise, continue } @@ -460,9 +475,6 @@ define([ var defaultTitle = Utils.UserObject.getDefaultName(parsed); var edPublic, curvePublic, notifications, isTemplate; 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 updateMeta = function () { //console.log('EV_METADATA_UPDATE'); @@ -507,7 +519,6 @@ define([ }, isNewFile: isNewFile, isDeleted: isNewFile && currentPad.hash.length > 0, - forceCreationScreen: forceCreationScreen, password: password, channel: secret.channel, enableSF: localStorage.CryptPad_SF === "1", // TODO to remove when enabled by default @@ -635,9 +646,10 @@ define([ Cryptpad.mailbox.execCommand(data, cb); }); - sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) { - sessionStorage.redirectTo = currentPad.href; - cb(); + sframeChan.on('EV_SET_LOGIN_REDIRECT', function (page) { + var href = Utils.Hash.hashToHref('', page); + var url = Utils.Hash.getNewPadURL(href, { href: currentPad.href }); + window.location.href = url; }); sframeChan.on('Q_STORE_IN_TEAM', function (data, cb) { @@ -1065,11 +1077,10 @@ define([ password: password, title: currentTitle }; - sessionStorage[Utils.Constants.newPadFileData] = JSON.stringify(data); - window.open(window.location.pathname); - setTimeout(function () { - delete sessionStorage[Utils.Constants.newPadFileData]; - }, 100); + var obj = { d: data }; + var href = window.location.pathname; + var url = Utils.Hash.getNewPadURL(href, obj); + window.open(url); }); // Messaging diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index f7a2c41c3..ffff122b5 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -307,9 +307,8 @@ define([ ctx.sframeChan.event('EV_SET_HASH', hash); }; - funcs.setLoginRedirect = function (cb) { - cb = cb || $.noop; - ctx.sframeChan.query('Q_SET_LOGIN_REDIRECT', null, cb); + funcs.setLoginRedirect = function (page) { + ctx.sframeChan.query('EV_SET_LOGIN_REDIRECT', page); }; funcs.isPresentUrl = function (cb) { @@ -758,9 +757,7 @@ define([ var mustLogin = privateData.registeredOnly; if (mustLogin) { UI.alert(Messages.mustLogin, function () { - funcs.setLoginRedirect(function () { - funcs.gotoURL('/login/'); - }); + funcs.setLoginRedirect('login'); }, {forefront: true}); return; } diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 9a96039f6..78e4e91f3 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -773,15 +773,11 @@ MessengerUI, Messages) { ]); $msg.find('a.cp-pnp-login').click(function (ev) { ev.preventDefault(); - Common.setLoginRedirect(function () { - window.parent.location = o + '/login/'; - }); + Common.setLoginRedirect('login'); }); $msg.find('a.cp-pnp-register').click(function (ev) { ev.preventDefault(); - Common.setLoginRedirect(function () { - window.parent.location = o + '/register/'; - }); + Common.setLoginRedirect('register'); }); $('.cp-toolbar-top').append($msg); //UI.addTooltips(); diff --git a/www/debug/main.js b/www/debug/main.js index 68055b1d4..b901beec0 100644 --- a/www/debug/main.js +++ b/www/debug/main.js @@ -53,14 +53,9 @@ define([ }; window.addEventListener('message', onMsg); }).nThen(function (/*waitFor*/) { - var hash = localStorage[Constants.userHashKey]; + var hash = localStorage[Constants.userHashKey] || localStorage[Constants.fileHashKey]; var drive = hash && ('#'+hash === window.location.hash); if (!window.location.hash) { - if (!hash) { - sessionStorage.redirectTo = '/debug/'; - window.location.href = '/login/'; - return; - } drive = true; window.location.hash = hash; } else { diff --git a/www/drive/main.js b/www/drive/main.js index 8db013c0f..5eb9dbc67 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -46,9 +46,12 @@ define([ window.addEventListener('message', onMsg); }).nThen(function (/*waitFor*/) { var afterSecrets = function (Cryptpad, Utils, secret, cb, sframeChan) { - var _hash = hash.slice(1); - if (_hash && Utils.LocalStore.isLoggedIn()) { - // Add a shared folder! + var parsed = Utils.Hash.parsePadUrl(href); + var isSf = parsed.hashData && parsed.hashData.type === 'pad'; + if (!isSf) { return void cb(); } + + // SF and logged in: add shared folder + if (Utils.LocalStore.isLoggedIn()) { Cryptpad.addSharedFolder(null, secret, function (id) { if (id && typeof(id) === "object" && id.error) { sframeChan.event("EV_RESTRICTED_ERROR"); @@ -65,16 +68,16 @@ define([ cb(); }); 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) { sframeChan.on('EV_BURN_ANON_DRIVE', function () { diff --git a/www/file/inner.js b/www/file/inner.js index 81019d0be..b2aef53ed 100644 --- a/www/file/inner.js +++ b/www/file/inner.js @@ -231,9 +231,7 @@ define([ if (!common.isLoggedIn()) { UI.removeLoadingScreen(); return UI.alert(Messages.upload_mustLogin, function () { - common.setLoginRedirect(function () { - common.gotoURL('/login/'); - }); + common.setLoginRedirect('login'); }); } diff --git a/www/profile/inner.js b/www/profile/inner.js index cddae4611..7a872fdd0 100644 --- a/www/profile/inner.js +++ b/www/profile/inner.js @@ -611,15 +611,11 @@ define([ var actions = h('div', [cancel, register, login]); var modal = UI.cornerPopup(Messages.profile_login, actions, '', {alt: true}); $(register).click(function () { - common.setLoginRedirect(function () { - common.gotoURL('/register/'); - }); + common.setLoginRedirect('register'); modal.delete(); }); $(login).click(function () { - common.setLoginRedirect(function () { - common.gotoURL('/login/'); - }); + common.setLoginRedirect('login'); modal.delete(); }); $(cancel).click(function () { diff --git a/www/secureiframe/main.js b/www/secureiframe/main.js index 060248097..49e94a252 100644 --- a/www/secureiframe/main.js +++ b/www/secureiframe/main.js @@ -86,12 +86,6 @@ define([ } metaObj = n; })); - if (typeof(isTemplate) === "undefined") { - Cryptpad.isTemplate(currentPad.href, waitFor(function (err, t) { - if (err) { console.log(err); } - isTemplate = t; - })); - } }).nThen(function (/*waitFor*/) { metaObj.doc = {}; var additionalPriv = { diff --git a/www/teams/inner.js b/www/teams/inner.js index 2eb234b12..a75ed94db 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -1267,14 +1267,10 @@ define([ anonRegister = h('button.btn.btn-secondary', Messages.login_register), ])); $(anonLogin).click(function () { - common.setLoginRedirect(function () { - common.gotoURL('/login/'); - }); + common.setLoginRedirect('login'); }); $(anonRegister).click(function () { - common.setLoginRedirect(function () { - common.gotoURL('/register/'); - }); + common.setLoginRedirect('register'); }); waitFor.abort(); }).nThen(function () { @@ -1402,9 +1398,7 @@ define([ var hash = privateData.teamInviteHash; if (!hash && !driveAPP.loggedIn) { UI.alert(Messages.mustLogin, function () { - common.setLoginRedirect(function () { - common.gotoURL('/login/'); - }); + common.setLoginRedirect('login'); }, {forefront: true}); return; }