Add a warning when a premium user is deleting their account

pull/1/head
yflory 4 years ago
parent 8afb71cf90
commit 7731cb603f

@ -469,6 +469,10 @@ define([
}); });
}, true); }, true);
Messages.settings_deleteWarning = "Warning: it seems you're subscribed to a premium plan (paid or given by another user). Please cancel paid subscriptions before deleting your account as you won't be able to do it yourself once the account is deleted."; // XXX
Messages.settings_deleteContinue = "Delete my account"; // XXX
Messages.settings_deleteSubscription = "Manage my subscription"; // XXX
makeBlock('delete', function(cb) { // Msg.settings_deleteHint, .settings_deleteTitle makeBlock('delete', function(cb) { // Msg.settings_deleteHint, .settings_deleteTitle
if (!common.isLoggedIn()) { return cb(false); } if (!common.isLoggedIn()) { return cb(false); }
@ -488,41 +492,69 @@ define([
classes: 'btn-danger', classes: 'btn-danger',
multiple: true multiple: true
}, function() { }, function() {
$button.prop('disabled', 'disabled'); nThen(function (waitFor) {
var password = $form.find('#cp-settings-delete-account').val(); $button.prop('disabled', 'disabled');
if (!password) { var priv = metadataMgr.getPrivateData();
return void UI.warn(Messages.error); // Check if subscriptions are enabled and you have a premium plan
} if (priv.plan && priv.plan !== "custom" && ApiConfig.allowSubscriptions) {
spinner.spin(); // Also make sure upgradeURL is defined
sframeChan.query("Q_SETTINGS_DELETE_ACCOUNT", { var url = priv.accounts && priv.accounts.upgradeURL;
password: password if (!url) { return; }
}, function(err, data) { url += '#mysubs';
if (data && data.error) { var a = h('a', { href:url }, Messages.settings_deleteSubscription);
spinner.hide(); $(a).click(function (e) {
$button.prop('disabled', ''); e.preventDefault();
if (data.error === 'INVALID_PASSWORD') { common.openUnsafeURL(url);
return void UI.warn(Messages.drive_sfPasswordError); });
} UI.confirm(h('div', [
console.error(data.error); Messages.settings_deleteWarning, h('p', a)
return void UI.warn(Messages.error); ]), waitFor(function (yes) {
} if (!yes) {
// Owned drive $button.prop('disabled', '');
if (data.state === true) { waitFor.abort();
sframeChan.query('Q_SETTINGS_LOGOUT', null, function() {}); }
UI.alert(Messages.settings_deleted, function() { }), {
common.gotoURL('/'); ok: Messages.settings_deleteContinue,
okClass: 'btn.btn-danger',
cancelClass: 'btn.btn-primary'
}); });
spinner.done();
return;
} }
// Not owned drive }).nThen(function () {
var msg = h('div.cp-app-settings-delete-alert', [ var password = $form.find('#cp-settings-delete-account').val();
h('p', Messages.settings_deleteModal), if (!password) {
h('pre', JSON.stringify(data, 0, 2)) return void UI.warn(Messages.error);
]); }
UI.alert(msg); spinner.spin();
spinner.hide(); sframeChan.query("Q_SETTINGS_DELETE_ACCOUNT", {
$button.prop('disabled', ''); password: password
}, function(err, data) {
if (data && data.error) {
spinner.hide();
$button.prop('disabled', '');
if (data.error === 'INVALID_PASSWORD') {
return void UI.warn(Messages.drive_sfPasswordError);
}
console.error(data.error);
return void UI.warn(Messages.error);
}
// Owned drive
if (data.state === true) {
sframeChan.query('Q_SETTINGS_LOGOUT', null, function() {});
UI.alert(Messages.settings_deleted, function() {
common.gotoURL('/');
});
spinner.done();
return;
}
// Not owned drive
var msg = h('div.cp-app-settings-delete-alert', [
h('p', Messages.settings_deleteModal),
h('pre', JSON.stringify(data, 0, 2))
]);
UI.alert(msg);
spinner.hide();
$button.prop('disabled', '');
});
}); });
}); });

Loading…
Cancel
Save