31 lines
771 B
JavaScript
31 lines
771 B
JavaScript
module.exports = Self => {
|
|
Self.remoteMethod('recoverPassword', {
|
|
description: 'Send email to the user',
|
|
accepts: [
|
|
{
|
|
arg: 'email',
|
|
type: 'string',
|
|
description: 'The email of user',
|
|
required: true
|
|
}
|
|
],
|
|
http: {
|
|
path: `/recoverPassword`,
|
|
verb: 'POST'
|
|
}
|
|
});
|
|
|
|
Self.recoverPassword = async function(email) {
|
|
const models = Self.app.models;
|
|
|
|
try {
|
|
await models.user.resetPassword({email, emailTemplate: 'recover-password'});
|
|
} catch (err) {
|
|
if (err.code === 'EMAIL_NOT_FOUND')
|
|
return;
|
|
else
|
|
throw err;
|
|
}
|
|
};
|
|
};
|