fix email password reset

This commit is contained in:
Berkeley Martinez
2015-08-16 09:54:34 -07:00
parent 63be84f47f
commit de7eb3d440
4 changed files with 72 additions and 192 deletions

View File

@ -83,6 +83,39 @@ module.exports = function(User) {
next();
});
User.on('resetPasswordRequest', function(info) {
const host = User.app.get('host');
// TODO(berks) get protocol as well
const url = `http://${host}/reset-password?access_token=` +
info.accessToken.id;
// the email of the requested user
debug(info.email);
// the temp access token to allow password reset
debug(info.accessToken.id);
// requires AccessToken.belongsTo(User)
var mailOptions = {
to: info.email,
from: 'Team@freecodecamp.com',
subject: 'Password Reset Request',
text: `
Hello,\n\n
This email is confirming that you requested to
reset your password for your Free Code Camp account.
This is your email: ${ info.email }.
Go to ${ url } to reset your password.
\n
Happy Coding!
\n
`
};
User.app.models.Email.send(mailOptions, function(err) {
if (err) { console.error(err); }
debug('email reset sent');
});
});
User.afterRemote('login', function(ctx, user, next) {
var res = ctx.res;
var req = ctx.req;