User: custom email headers in verify

This commit is contained in:
Juan Pizarro 2014-10-24 02:46:23 -03:00
parent 03b3c3cda4
commit 4098bec2c6
2 changed files with 36 additions and 3 deletions

View File

@ -283,9 +283,10 @@ User.prototype.verify = function(options, fn) {
from: options.from,
subject: options.subject || 'Thanks for Registering',
text: options.text,
html: template(options)
}, function(err, email) {
if (err) {
html: template(options),
headers: options.headers || {}
}, function (err, email) {
if(err) {
fn(err);
} else {
fn(null, {email: email, token: user.verificationToken, uid: user.id});

View File

@ -487,6 +487,38 @@ describe('User', function(){
if(err) return done(err);
});
});
it('Verify a user\'s email address with custom header', function(done) {
User.afterRemote('create', function(ctx, user, next) {
assert(user, 'afterRemote should include result');
var options = {
type: 'email',
to: user.email,
from: 'noreply@myapp.org',
redirect: '/',
protocol: ctx.req.protocol,
host: ctx.req.get('host'),
headers: {'message-id':'custom-header-value'}
};
user.verify(options, function (err, result) {
assert(result.email);
assert.equal(result.email.messageId, 'custom-header-value');
done();
});
});
request(app)
.post('/users')
.expect('Content-Type', /json/)
.expect(200)
.send({email: 'bar@bat.com', password: 'bar'})
.end(function(err, res){
if(err) return done(err);
});
});
});
describe('User.confirm(options, fn)', function () {