@@ -364,6 +364,10 @@ module.exports = function(User) {
364364 * @property {String } text Text of email.
365365 * @property {String } template Name of template that displays verification
366366 * page, for example, `'verify.ejs'.
367+ * @property {Function } templateFn A function generating the email HTML body
368+ * from `verify()` options object and generated attributes like `options.verifyHref`.
369+ * It must accept the option object and a callback function with `(err, html)`
370+ * as parameters
367371 * @property {String } redirect Page to which user will be redirected after
368372 * they verify their email, for example `'/'` for root URI.
369373 * @property {Function } generateVerificationToken A function to be used to
@@ -424,6 +428,8 @@ module.exports = function(User) {
424428 '&redirect=' +
425429 options . redirect ;
426430
431+ options . templateFn = options . templateFn || createVerificationEmailBody ;
432+
427433 // Email model
428434 var Email = options . mailer || this . constructor . email || registry . getModelByType ( loopback . Email ) ;
429435
@@ -458,20 +464,36 @@ module.exports = function(User) {
458464
459465 options . headers = options . headers || { } ;
460466
461- var template = loopback . template ( options . template ) ;
462- options . html = template ( options ) ;
463-
464- Email . send ( options , function ( err , email ) {
467+ options . templateFn ( options , function ( err , html ) {
465468 if ( err ) {
466469 fn ( err ) ;
467470 } else {
468- fn ( null , { email : email , token : user . verificationToken , uid : user . id } ) ;
471+ setHtmlContentAndSend ( html ) ;
469472 }
470473 } ) ;
474+
475+ function setHtmlContentAndSend ( html ) {
476+ options . html = html ;
477+
478+ Email . send ( options , function ( err , email ) {
479+ if ( err ) {
480+ fn ( err ) ;
481+ } else {
482+ fn ( null , { email : email , token : user . verificationToken , uid : user . id } ) ;
483+ }
484+ } ) ;
485+ }
471486 }
472487 return fn . promise ;
473488 } ;
474489
490+ function createVerificationEmailBody ( options , cb ) {
491+ var template = loopback . template ( options . template ) ;
492+ var body = template ( options ) ;
493+ cb ( null , body ) ;
494+ }
495+
496+
475497 /**
476498 * A default verification token generator which accepts the user the token is
477499 * being generated for and a callback function to indicate completion.
0 commit comments