mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
46bf5270df
These changes introduce a new "service" to the members api, which handles getting and creating subscriptions. This is wired up to get subscription information when creating tokens, and attaching information to the token, so that the Content API can allow/deny access. Behind the subscription service we have a Stripe "payment processor", this holds the logic for creating subscriptions etc... in Stripe. The logic for getting items out of stripe uses a hash of the relevant data as the id to search for, this allows us to forgo keeping stripe data in a db, so that this feature can get out quicker.
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
module.exports = function ({
|
|
subscriptions,
|
|
createMember,
|
|
updateMember,
|
|
getMember,
|
|
listMembers,
|
|
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')
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
return {
|
|
requestPasswordReset,
|
|
resetPassword,
|
|
create: createMember,
|
|
validate: validateMember,
|
|
list: listMembers,
|
|
get
|
|
};
|
|
};
|