Merge pull request #3249 from islamixo/feature-verificationToken

Pass options.verificationToken to templateFn
This commit is contained in:
Miroslav Bajtoš 2017-03-06 18:05:44 +01:00 committed by GitHub
commit b5a8564956
3 changed files with 25 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
.idea .idea
.project .project
.DS_Store .DS_Store
.vscode/
*.sublime* *.sublime*
*.seed *.seed
*.log *.log

View File

@ -450,6 +450,7 @@ module.exports = function(User) {
// Set a default token generation function if one is not provided // Set a default token generation function if one is not provided
var tokenGenerator = options.generateVerificationToken || User.generateVerificationToken; var tokenGenerator = options.generateVerificationToken || User.generateVerificationToken;
assert(typeof tokenGenerator === 'function', 'generateVerificationToken must be a function');
tokenGenerator(user, function(err, token) { tokenGenerator(user, function(err, token) {
if (err) { return fn(err); } if (err) { return fn(err); }
@ -468,6 +469,8 @@ module.exports = function(User) {
function sendEmail(user) { function sendEmail(user) {
options.verifyHref += '&token=' + user.verificationToken; options.verifyHref += '&token=' + user.verificationToken;
options.verificationToken = user.verificationToken;
options.text = options.text || g.f('Please verify your email by opening ' + options.text = options.text || g.f('Please verify your email by opening ' +
'this link in a web browser:\n\t%s', options.verifyHref); 'this link in a web browser:\n\t%s', options.verifyHref);

View File

@ -1714,6 +1714,27 @@ describe('User', function() {
.to.equal('#/some-path?a=1&b=2'); .to.equal('#/some-path?a=1&b=2');
}); });
}); });
it('verify that options.templateFn receives options.verificationToken', function() {
return User.create({email: 'test1@example.com', password: 'pass'})
.then(user => {
let actualVerificationToken;
return user.verify({
type: 'email',
to: user.email,
from: 'noreply@myapp.org',
redirect: '#/some-path?a=1&b=2',
templateFn: (options, cb) => {
actualVerificationToken = options.verificationToken;
cb(null, 'dummy body');
},
})
.then(() => actualVerificationToken);
})
.then(token => {
expect(token).to.exist();
});
});
}); });
describe('User.confirm(options, fn)', function() { describe('User.confirm(options, fn)', function() {