mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
daf5a41af0
no issue - Added new API to delete members - Added methods to handle e2e member deletion - Deleting member via Admin leads to - Removal of member from payment processor and cancelling all active subscriptions immediately - Removal of member information from DB
76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
module.exports = function ({
|
|
subscriptions,
|
|
createMember,
|
|
updateMember,
|
|
getMember,
|
|
listMembers,
|
|
deleteMember,
|
|
validateMember,
|
|
sendEmail,
|
|
encodeToken,
|
|
decodeToken
|
|
}) {
|
|
function requestPasswordReset({email}) {
|
|
return getMember({email}, {require: true}).then((member) => {
|
|
return encodeToken({
|
|
sub: member.id
|
|
}).then((token) => {
|
|
return sendEmail(member, {token});
|
|
});
|
|
}, (/*err*/) => {
|
|
// Ignore user not found err;
|
|
});
|
|
}
|
|
|
|
function resetPassword({token, password}) {
|
|
return decodeToken(token).then(({sub}) => {
|
|
return updateMember({id: sub}, {password});
|
|
});
|
|
}
|
|
|
|
function get(...args) {
|
|
return getMember(...args).then((member) => {
|
|
return subscriptions.getAdapters().then((adapters) => {
|
|
return Promise.all(adapters.map((adapter) => {
|
|
return subscriptions.getSubscription(member, {
|
|
adapter
|
|
}).then((subscription) => {
|
|
return Object.assign(subscription, {adapter});
|
|
});
|
|
}));
|
|
}).then((subscriptions) => {
|
|
return Object.assign({}, member, {
|
|
subscriptions: subscriptions.filter(sub => sub.status === 'active')
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function destroy(...args) {
|
|
return getMember(...args).then((member) => {
|
|
if (!member) {
|
|
return null;
|
|
}
|
|
return subscriptions.getAdapters().then((adapters) => {
|
|
return Promise.all(adapters.map((adapter) => {
|
|
return subscriptions.removeCustomer(member, {
|
|
adapter
|
|
});
|
|
}));
|
|
}).then(() => {
|
|
return deleteMember(...args);
|
|
});
|
|
});
|
|
}
|
|
|
|
return {
|
|
requestPasswordReset,
|
|
resetPassword,
|
|
create: createMember,
|
|
validate: validateMember,
|
|
list: listMembers,
|
|
destroy,
|
|
get
|
|
};
|
|
};
|