JedWatson / sydjs-site

SydJS Meetup Website
MIT License
535 stars 225 forks source link

keystone.set('email locals',{}) not working #137

Open max8hine opened 6 years ago

max8hine commented 6 years ago

I found this code snippet in the keystone.js

keystone.set('email locals', {
    utils: keystone.utils,
    host: (function() {
        if (keystone.get('env') === 'staging') return 'http://sydjs-beta.herokuapp.com';
        if (keystone.get('env') === 'production') return 'http://www.sydjs.com';
        return (keystone.get('host') || 'http://localhost:') + (keystone.get('port') || '3000');
    })()
});

it seems did not pass anything into the email template, is the 'email locals' is valid key for keystone.set('')?

(below is the screenshot from the receiving email) image

the host url is missing in email.

Thank you in advance

max8hine commented 6 years ago

I think I know why, after checked the ./lib/email.js in Keystone.

need to use keystone.get('email locals') to grab the data

It would be good to hard code in the keystone/lib/email.js since keystone-email dropped the default locals.

temperary solution:

User.schema.methods.resetPassword = function(callback) {
    var user = this;
    user.resetPasswordKey = keystone.utils.randomString([16,24]);
    /** Get the emailLcals */
    const emailLocals = keystone.get('email locals')
    console.log(emailLocals)

    user.save(function(err) {
        if (err) return callback(err);
        new keystone.Email('forgotten-password').send({
            /** insert to the option object */
            ...emailLocals,
            user: user,
            link: '/reset-password/' + user.resetPasswordKey,
            subject: 'Reset your SydJS Password',
            to: user.email,
            from: {
                name: 'SydJS',
                email: 'contact@sydjs.com'
            }
        }, callback);
    });
}