From 3bdca60c7697fdc67dac834cfbaec2f27fe073d4 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 19 Nov 2019 10:40:55 +0100 Subject: [PATCH] Display the prefilled password page when receiving a password-protected pad --- www/common/common-ui-elements.js | 9 +++++++-- www/common/sframe-common-outer.js | 13 ++++++++----- www/common/sframe-common.js | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 8943f67b5..126450f0f 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -3463,19 +3463,24 @@ define([ (cb || function () {})(); }; - UIElements.displayPasswordPrompt = function (common, isError) { + UIElements.displayPasswordPrompt = function (common, cfg, isError) { var error; if (isError) { error = setHTML(h('p.cp-password-error'), Messages.password_error); } var info = h('p.cp-password-info', Messages.password_info); var password = UI.passwordInput({placeholder: Messages.password_placeholder}); var button = h('button', Messages.password_submit); + cfg = cfg || {}; + + if (cfg.value && !isError) { + $(password).find('.cp-password-input').val(cfg.value); + } var submit = function () { var value = $(password).find('.cp-password-input').val(); UI.addLoadingScreen(); common.getSframeChannel().query('Q_PAD_PASSWORD_VALUE', value, function (err, data) { if (!data) { - UIElements.displayPasswordPrompt(common, true); + UIElements.displayPasswordPrompt(common, cfg, true); } }); }; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 224a9f73c..a2c50ca6b 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -206,7 +206,7 @@ define([ // 2c: 'view' pad and '/p/' and a wrong password stored --> the seed is incorrect // 2d: 'view' pad and '/p/' and password never stored (security feature) --> password-prompt - var askPassword = function (wrongPasswordStored) { + var askPassword = function (wrongPasswordStored, cfg) { // Ask for the password and check if the pad exists // If the pad doesn't exist, it means the password isn't correct // or the pad has been deleted @@ -250,11 +250,14 @@ define([ // Not a file, so we can use `isNewChannel` Cryptpad.isNewChannel(window.location.href, password, next); }); - sframeChan.event("EV_PAD_PASSWORD"); + sframeChan.event("EV_PAD_PASSWORD", cfg); }; var done = waitFor(); var stored = false; + var passwordCfg = { + value: '' + }; nThen(function (w) { Cryptpad.getPadAttribute('title', w(function (err, data) { stored = (!err && typeof (data) === "string"); @@ -264,7 +267,7 @@ define([ }), parsed.getUrl()); }).nThen(function (w) { if (!password && !stored && sessionStorage.newPadPassword) { - password = sessionStorage.newPadPassword; + passwordCfg.value = sessionStorage.newPadPassword; delete sessionStorage.newPadPassword; } @@ -274,7 +277,7 @@ define([ Cryptpad.getFileSize(window.location.href, password, w(function (e, size) { if (size !== 0) { return void todo(); } // Wrong password or deleted file? - askPassword(true); + askPassword(true, passwordCfg); })); return; } @@ -293,7 +296,7 @@ define([ return void todo(); } // Wrong password or deleted file? - askPassword(true); + askPassword(true, passwordCfg); })); }).nThen(done); } diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index c73e43996..f8bbb205b 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -595,8 +595,8 @@ define([ UI.addTooltips(); - ctx.sframeChan.on("EV_PAD_PASSWORD", function () { - UIElements.displayPasswordPrompt(funcs); + ctx.sframeChan.on("EV_PAD_PASSWORD", function (cfg) { + UIElements.displayPasswordPrompt(funcs, cfg); }); ctx.sframeChan.on("EV_PAD_PASSWORD_ERROR", function () {