2019-01-22 17:29:44 +03:00
|
|
|
module.exports = function ({
|
|
|
|
createMember,
|
|
|
|
updateMember,
|
|
|
|
getMember,
|
2019-01-30 14:36:09 +03:00
|
|
|
listMembers,
|
2019-01-22 17:29:44 +03:00
|
|
|
validateMember,
|
|
|
|
sendEmail,
|
|
|
|
encodeToken,
|
|
|
|
decodeToken
|
|
|
|
}) {
|
|
|
|
function requestPasswordReset({email}) {
|
2019-01-30 14:36:09 +03:00
|
|
|
return getMember({email}, {require: true}).then((member) => {
|
2019-01-22 17:29:44 +03:00
|
|
|
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});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
requestPasswordReset,
|
|
|
|
resetPassword,
|
|
|
|
create: createMember,
|
|
|
|
validate: validateMember,
|
2019-01-30 14:36:09 +03:00
|
|
|
get: getMember,
|
|
|
|
list: listMembers
|
2019-01-22 17:29:44 +03:00
|
|
|
};
|
|
|
|
};
|