Own drive migration

This commit is contained in:
yflory 2018-12-19 18:59:20 +01:00
parent bbc06f668f
commit f2f9b57505
4 changed files with 43 additions and 18 deletions

View file

@ -456,7 +456,8 @@ define([
edPublic: store.proxy.edPublic,
friends: store.proxy.friends || {},
settings: store.proxy.settings,
thumbnails: disableThumbnails === false
thumbnails: disableThumbnails === false,
isDriveOwned: Boolean(Util.find(store, ['driveMetadata', 'owners']))
}
};
cb(JSON.parse(JSON.stringify(metadata)));
@ -1523,8 +1524,9 @@ define([
if (!data.userHash) {
returned.anonHash = Hash.getEditHashFromKeys(secret);
}
}).on('ready', function () {
}).on('ready', function (info) {
if (store.userObject) { return; } // the store is already ready, it is a reconnection
store.driveMetadata = info.metadata;
if (!rt.proxy.drive || typeof(rt.proxy.drive) !== 'object') { rt.proxy.drive = {}; }
var drive = rt.proxy.drive;
// Creating a new anon drive: import anon pads from localStorage

View file

@ -667,6 +667,7 @@ define(function () {
out.settings_ownDriveHint = "Migrating your drive to the new version will give you access to new features..."; // XXX
out.settings_ownDriveButton = "Migrate"; // XXX
out.settings_ownDriveConfirm = "Are you sure?"; // XXX
out.settings_ownDrivePending = "Your account is being migrated. Please do not close or reload this page until the process has completed."; // XXX
out.settings_changePasswordTitle = "Change your password";
out.settings_changePasswordHint = "Change your account's password. Enter your current password, and confirm the new password by typing it twice.<br>" +

View file

@ -154,7 +154,7 @@
}
}
.cp-settings-change-password {
.cp-settings-change-password, .cp-settings-migrate {
[type="password"], [type="text"] {
width: @sidebar_button-width;
flex: unset;

View file

@ -52,6 +52,7 @@ define([
'cp-settings-autostore',
'cp-settings-userfeedback',
'cp-settings-change-password',
'cp-settings-migrate',
'cp-settings-backup',
'cp-settings-delete'
],
@ -473,10 +474,7 @@ define([
};
create['migrate'] = function () {
if (true) { return; } // STUBBED until we have a reason to deploy this
// TODO
// if (!loginBlock) { return; }
// if (alreadyMigrated) { return; }
if (privateData.isDriveOwned) { return; }
if (!common.isLoggedIn()) { return; }
var $div = $('<div>', { 'class': 'cp-settings-migrate cp-sidebarlayout-element'});
@ -489,25 +487,49 @@ define([
var $ok = $('<span>', {'class': 'fa fa-check', title: Messages.saved});
var $spinner = $('<span>', {'class': 'fa fa-spinner fa-pulse'});
var $button = $('<button>', {'id': 'cp-settings-delete', 'class': 'btn btn-primary'})
.text(Messages.settings_ownDriveButton).appendTo($div);
var form = h('div', [
UI.passwordInput({
id: 'cp-settings-migrate-password',
placeholder: Messages.settings_changePasswordCurrent
}, true),
h('button.btn.btn-primary', Messages.settings_ownDriveButton)
]);
$button.click(function () {
$(form).appendTo($div);
var todo = function () {
var password = $(form).find('#cp-settings-migrate-password').val();
if (!password) { return; }
$spinner.show();
UI.confirm(Messages.settings_ownDriveConfirm, function (yes) {
if (!yes) { return; }
sframeChan.query("Q_OWN_USER_DRIVE", null, function (err, data) {
if (err || data.error) {
console.error(err || data.error);
// TODO
$spinner.hide();
return;
}
// TODO: drive is migrated, autoamtic redirect from outer?
var data = {
password: password,
newPassword: password
};
UI.addLoadingScreen({
hideTips: true,
loadingText: Messages.settings_ownDrivePending,
});
sframeChan.query('Q_CHANGE_USER_PASSWORD', data, function (err, obj) {
UI.removeLoadingScreen();
if (err || obj.error) { return UI.alert(Messages.settings_changePasswordError); }
$ok.show();
$spinner.hide();
});
});
};
$(form).find('button').click(function () {
todo();
});
$(form).find('input').keydown(function (e) {
// Save on Enter
if (e.which === 13) {
e.preventDefault();
e.stopPropagation();
todo();
}
});
$spinner.hide().appendTo($div);