Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
max8hine opened this issue Apr 12, 2018 · 1 comment
Open

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

max8hine opened this issue Apr 12, 2018 · 1 comment

Comments

@max8hine
Copy link

max8hine commented Apr 12, 2018

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
Copy link
Author

max8hine commented Apr 12, 2018

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: '[email protected]'
			}
		}, callback);
	});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant