Display the prefilled password page when receiving a password-protected pad

pull/1/head
yflory 5 years ago
parent 62504e0e32
commit 3bdca60c76

@ -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);
}
});
};

@ -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);
}

@ -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 () {

Loading…
Cancel
Save