Fix password change issues with read-only pads or from the drive

pull/1/head
yflory 5 years ago
parent 086e500b8e
commit 12a45377e7

@ -547,21 +547,27 @@ define([
if (!data.noPassword) { if (!data.noPassword) {
var hasPassword = data.password; var hasPassword = data.password;
if (hasPassword) { var $pwLabel = $('<label>', {'for': 'cp-app-prop-password'}).text(Messages.creation_passwordValue)
$('<label>', {'for': 'cp-app-prop-password'}).text(Messages.creation_passwordValue) .hide().appendTo($d);
.appendTo($d);
var password = UI.passwordInput({ var password = UI.passwordInput({
id: 'cp-app-prop-password', id: 'cp-app-prop-password',
readonly: 'readonly' readonly: 'readonly'
}); });
var $pwInput = $(password).find('.cp-password-input'); var $password = $(password).hide();
var $pwInput = $password.find('.cp-password-input');
$pwInput.val(data.password).click(function () { $pwInput.val(data.password).click(function () {
$pwInput[0].select(); $pwInput[0].select();
}); });
$d.append(password); $d.append(password);
if (hasPassword) {
$pwLabel.show();
$password.css('display', 'flex');
} }
if (!data.noEditPassword && owned) { // FIXME SHEET fix password change for sheets // In the properties, we should have the edit href if we know it.
// We should know it because the pad is stored, but it's better to check...
if (!data.noEditPassword && owned && data.href) { // FIXME SHEET fix password change for sheets
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
var isOO = parsed.type === 'sheet'; var isOO = parsed.type === 'sheet';
@ -621,7 +627,7 @@ define([
sframeChan.query(q, { sframeChan.query(q, {
teamId: typeof(owned) !== "boolean" ? owned : undefined, teamId: typeof(owned) !== "boolean" ? owned : undefined,
href: data.href || data.roHref, href: data.href,
password: newPass password: newPass
}, function (err, data) { }, function (err, data) {
$(passwordOk).text(Messages.properties_changePasswordButton); $(passwordOk).text(Messages.properties_changePasswordButton);
@ -631,8 +637,16 @@ define([
return void UI.alert(Messages.properties_passwordError); return void UI.alert(Messages.properties_passwordError);
} }
UI.findOKButton().click(); UI.findOKButton().click();
if (isFile) {
onProgress.stop(); $pwLabel.show();
$password.css('display', 'flex');
$pwInput.val(newPass);
// If the current document is a file or if we're changing the password from a drive,
// we don't have to reload the page at the end.
// Tell the user the password change was successful and abort
if (isFile || priv.app !== parsed.type) {
if (onProgress && onProgress.stop) { onProgress.stop(); }
$(passwordOk).text(Messages.properties_changePasswordButton); $(passwordOk).text(Messages.properties_changePasswordButton);
var alertMsg = data.warning ? Messages.properties_passwordWarningFile var alertMsg = data.warning ? Messages.properties_passwordWarningFile
: Messages.properties_passwordSuccessFile; : Messages.properties_passwordSuccessFile;
@ -642,7 +656,7 @@ define([
// Pad password changed: update the href // Pad password changed: update the href
// Use hidden hash if needed (we're an owner of this pad so we know it is stored) // Use hidden hash if needed (we're an owner of this pad so we know it is stored)
var useUnsafe = Util.find(priv, ['settings', 'security', 'unsafeLinks']); var useUnsafe = Util.find(priv, ['settings', 'security', 'unsafeLinks']);
var href = data.href || data.roHref; var href = (priv.readOnly && data.roHref) ? data.roHref : data.href;
if (!useUnsafe) { if (!useUnsafe) {
var newParsed = Hash.parsePadUrl(href); var newParsed = Hash.parsePadUrl(href);
var newSecret = Hash.getSecrets(newParsed.type, newParsed.hash, newPass); var newSecret = Hash.getSecrets(newParsed.type, newParsed.hash, newPass);

@ -1037,6 +1037,7 @@ define([
}, waitFor()); }, waitFor());
} }
}).nThen(function () { }).nThen(function () {
common.drive.onChange.fire({path: ['drive', Constants.storageKey]});
cb({ cb({
warning: warning, warning: warning,
hash: newHash, hash: newHash,
@ -1170,6 +1171,7 @@ define([
channel: newSecret.channel channel: newSecret.channel
}, waitFor()); }, waitFor());
}).nThen(function () { }).nThen(function () {
common.drive.onChange.fire({path: ['drive', Constants.storageKey]});
cb({ cb({
warning: warning, warning: warning,
hash: newHash, hash: newHash,
@ -1404,6 +1406,7 @@ define([
}, waitFor()); }, waitFor());
})); }));
}).nThen(function () { }).nThen(function () {
common.drive.onChange.fire({path: ['drive', Constants.storageKey]});
cb({ cb({
warning: warning, warning: warning,
hash: newHash, hash: newHash,

@ -1125,12 +1125,12 @@ define([
}); });
sframeChan.on('Q_OO_PASSWORD_CHANGE', function (data, cb) { sframeChan.on('Q_OO_PASSWORD_CHANGE', function (data, cb) {
data.href = data.href || currentPad.href; data.href = data.href;
Cryptpad.changeOOPassword(data, cb); Cryptpad.changeOOPassword(data, cb);
}); });
sframeChan.on('Q_PAD_PASSWORD_CHANGE', function (data, cb) { sframeChan.on('Q_PAD_PASSWORD_CHANGE', function (data, cb) {
data.href = data.href || currentPad.href; data.href = data.href;
Cryptpad.changePadPassword(Cryptget, Crypto, data, cb); Cryptpad.changePadPassword(Cryptget, Crypto, data, cb);
}); });

Loading…
Cancel
Save