Merge pull request #3249 from islamixo/feature-verificationToken
Pass options.verificationToken to templateFn
This commit is contained in:
commit
b5a8564956
|
@ -1,6 +1,7 @@
|
|||
.idea
|
||||
.project
|
||||
.DS_Store
|
||||
.vscode/
|
||||
*.sublime*
|
||||
*.seed
|
||||
*.log
|
||||
|
|
|
@ -450,6 +450,7 @@ module.exports = function(User) {
|
|||
|
||||
// Set a default token generation function if one is not provided
|
||||
var tokenGenerator = options.generateVerificationToken || User.generateVerificationToken;
|
||||
assert(typeof tokenGenerator === 'function', 'generateVerificationToken must be a function');
|
||||
|
||||
tokenGenerator(user, function(err, token) {
|
||||
if (err) { return fn(err); }
|
||||
|
@ -468,6 +469,8 @@ module.exports = function(User) {
|
|||
function sendEmail(user) {
|
||||
options.verifyHref += '&token=' + user.verificationToken;
|
||||
|
||||
options.verificationToken = user.verificationToken;
|
||||
|
||||
options.text = options.text || g.f('Please verify your email by opening ' +
|
||||
'this link in a web browser:\n\t%s', options.verifyHref);
|
||||
|
||||
|
|
|
@ -1714,6 +1714,27 @@ describe('User', function() {
|
|||
.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() {
|
||||
|
|
Loading…
Reference in New Issue