Improve password change workflow

pull/1/head
yflory 5 years ago
parent c894351a30
commit 427cf836b1

@ -1857,6 +1857,12 @@ define([
$span.addClass('cp-app-drive-element-sharedf'); $span.addClass('cp-app-drive-element-sharedf');
_addOwnership($span, $state, data); _addOwnership($span, $state, data);
var hrefData = Hash.parsePadUrl(data.href || data.roHref);
if (hrefData.hashData && hrefData.hashData.password) {
var $password = $passwordIcon.clone().appendTo($state);
$password.attr('title', Messages.fm_passwordProtected || '');
}
var $shared = $sharedIcon.clone().appendTo($state); var $shared = $sharedIcon.clone().appendTo($state);
$shared.attr('title', Messages.fm_canBeShared); $shared.attr('title', Messages.fm_canBeShared);
} }

@ -1919,7 +1919,7 @@ define([
store.manager.user.userObject.getHref(data) : data.href; store.manager.user.userObject.getHref(data) : data.href;
var parsed = Hash.parsePadUrl(href); var parsed = Hash.parsePadUrl(href);
var secret = Hash.getSecrets(parsed.type, parsed.hash, o); var secret = Hash.getSecrets(parsed.type, parsed.hash, o);
SF.updatePassword({ SF.updatePassword(Store, {
oldChannel: secret.channel, oldChannel: secret.channel,
password: n, password: n,
href: href href: href
@ -2063,6 +2063,15 @@ define([
/////////////////////// Init ///////////////////////////////////// /////////////////////// Init /////////////////////////////////////
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
Store.refreshDriveUI = function () {
getAllStores().forEach(function (_s) {
var send = _s.id ? _s.sendEvent : sendDriveEvent;
send('DRIVE_CHANGE', {
path: ['drive', UserObject.FILES_DATA]
});
});
};
var onReady = function (clientId, returned, cb) { var onReady = function (clientId, returned, cb) {
var proxy = store.proxy; var proxy = store.proxy;
var unpin = function (data, cb) { var unpin = function (data, cb) {

@ -49,6 +49,9 @@ define([
var deprecateProxy = function (Env, id, channel) { var deprecateProxy = function (Env, id, channel) {
Env.unpinPads([channel], function () {}); Env.unpinPads([channel], function () {});
Env.user.userObject.deprecateSharedFolder(id); Env.user.userObject.deprecateSharedFolder(id);
if (Env.Store && Env.Store.refreshDriveUI) {
Env.Store.refreshDriveUI();
}
}; };
/* /*

@ -215,8 +215,15 @@ define([
if (wrongPasswordStored) { if (wrongPasswordStored) {
// Store the correct password // Store the correct password
nThen(function (w) { nThen(function (w) {
// XXX noPasswordStored: return; ?
Cryptpad.setPadAttribute('password', password, w(), parsed.getUrl()); Cryptpad.setPadAttribute('password', password, w(), parsed.getUrl());
Cryptpad.setPadAttribute('channel', secret.channel, w(), parsed.getUrl()); Cryptpad.setPadAttribute('channel', secret.channel, w(), parsed.getUrl());
if (parsed.hashData.mode === 'edit') {
var href = window.location.pathname + '#' + Utils.Hash.getEditHashFromKeys(secret);
Cryptpad.setPadAttribute('href', href, w(), parsed.getUrl());
var roHref = window.location.pathname + '#' + Utils.Hash.getViewHashFromKeys(secret);
Cryptpad.setPadAttribute('roHref', roHref, w(), parsed.getUrl());
}
}).nThen(correctPassword); }).nThen(correctPassword);
} else { } else {
correctPassword(); correctPassword();
@ -244,10 +251,19 @@ define([
} }
password = val; password = val;
Cryptpad.getFileSize(window.location.href, password, waitFor(function (e, size) { if (parsed.type === "file") {
if (size !== 0) { // `isNewChannel` doesn't work for files (not a channel)
return void todo(); // `getFileSize` is not adapted to channels because of metadata
} Cryptpad.getFileSize(window.location.href, password, waitFor(function (e, size) {
if (size !== 0) { return void todo(); }
// Wrong password or deleted file?
askPassword(true);
}));
return;
}
// Not a file, so we can use `isNewChannel`
Cryptpad.isNewChannel(window.location.href, password, waitFor(function(e, isNew) {
if (!isNew) { return void todo(); }
if (parsed.hashData.mode === 'view' && (val || !parsed.hashData.password)) { if (parsed.hashData.mode === 'view' && (val || !parsed.hashData.password)) {
// Error, wrong password stored, the view seed has changed with the password // Error, wrong password stored, the view seed has changed with the password
// password will never work // password will never work

@ -385,8 +385,8 @@ define([
var result; var result;
var noPassword = function (str) { var noPassword = function (str) {
if (!str) { return; } if (!str) { return; }
var value = str.replace(/\/p\/?/, '/'); var parsed = Hash.parsePadUrl(str);
return Hash.getRelativeHref(value); return parsed.getUrl().replace(/\/p\/?/, '/');
}; };
var href = noPassword(_href); var href = noPassword(_href);
getFiles([FILES_DATA]).some(function (id) { getFiles([FILES_DATA]).some(function (id) {
@ -403,8 +403,8 @@ define([
var result; var result;
var noPassword = function (str) { var noPassword = function (str) {
if (!str) { return; } if (!str) { return; }
var value = str.replace(/\/p\/?/, '/'); var parsed = Hash.parsePadUrl(str);
return Hash.getRelativeHref(value); return parsed.getUrl().replace(/\/p\/?/, '/');
}; };
var href = noPassword(_href); var href = noPassword(_href);
getFiles([SHARED_FOLDERS]).some(function (id) { getFiles([SHARED_FOLDERS]).some(function (id) {

Loading…
Cancel
Save