@@ -365,6 +365,10 @@ module.exports = function(User) {
365365 * @property {String } text Text of email.
366366 * @property {String } template Name of template that displays verification
367367 * page, for example, `'verify.ejs'.
368+ * @property {Function } templateFn A function generating the email HTML body
369+ * from `verify()` options object and generated attributes like `options.verifyHref`.
370+ * It must accept the option object and a callback function with `(err, html)`
371+ * as parameters
368372 * @property {String } redirect Page to which user will be redirected after
369373 * they verify their email, for example `'/'` for root URI.
370374 * @property {Function } generateVerificationToken A function to be used to
@@ -418,6 +422,8 @@ module.exports = function(User) {
418422 '&redirect=' +
419423 options . redirect ;
420424
425+ options . templateFn = options . templateFn || createVerificationEmailBody ;
426+
421427 // Email model
422428 var Email = options . mailer || this . constructor . email || registry . getModelByType ( loopback . Email ) ;
423429
@@ -452,20 +458,35 @@ module.exports = function(User) {
452458
453459 options . headers = options . headers || { } ;
454460
455- var template = loopback . template ( options . template ) ;
456- options . html = template ( options ) ;
457-
458- Email . send ( options , function ( err , email ) {
461+ options . templateFn ( options , function ( err , html ) {
459462 if ( err ) {
460463 fn ( err ) ;
461464 } else {
462- fn ( null , { email : email , token : user . verificationToken , uid : user . id } ) ;
465+ setHtmlContentAndSend ( html ) ;
463466 }
464467 } ) ;
468+
469+ function setHtmlContentAndSend ( html ) {
470+ options . html = html ;
471+
472+ Email . send ( options , function ( err , email ) {
473+ if ( err ) {
474+ fn ( err ) ;
475+ } else {
476+ fn ( null , { email : email , token : user . verificationToken , uid : user . id } ) ;
477+ }
478+ } ) ;
479+ }
465480 }
466481 return fn . promise ;
467482 } ;
468483
484+ function createVerificationEmailBody ( options , cb ) {
485+ var template = loopback . template ( options . template ) ;
486+ var body = template ( options ) ;
487+ cb ( null , body ) ;
488+ }
489+
469490 /**
470491 * A default verification token generator which accepts the user the token is
471492 * being generated for and a callback function to indicate completion.
0 commit comments