diff --git a/lib/models/user.js b/lib/models/user.js index a6e413fd..09e3281a 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -277,6 +277,7 @@ User.prototype.hasPassword = function (plain, fn) { User.prototype.verify = function (options, fn) { var user = this; + var userModel = this.constructor; assert(typeof options === 'object', 'options required when calling user.verify()'); assert(options.type, 'You must supply a verification type (options.type)'); assert(options.type === 'email', 'Unsupported verification type'); @@ -287,13 +288,20 @@ User.prototype.verify = function (options, fn) { options.template = path.resolve(options.template || path.join(__dirname, '..', '..', 'templates', 'verify.ejs')); options.user = this; options.protocol = options.protocol || 'http'; - options.host = options.host || 'localhost'; + + var app = this.app; + options.host = options.host || (app && app.get('host')) || 'localhost'; + options.port = options.port || (app && app.get('port')) || 3000; + options.restApiRoot = options.restApiRoot || (app && app.get('restApiRoot')) || '/api'; options.verifyHref = options.verifyHref || options.protocol + '://' + options.host - + User.http.path - + User.confirm.http.path + + ':' + + options.port + + options.restApiRoot + + userModel.http.path + + userModel.confirm.http.path + '?uid=' + options.user.id + '&redirect=' diff --git a/test/user.test.js b/test/user.test.js index b7588779..0bfc9240 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -454,7 +454,9 @@ describe('User', function(){ assert(result.email); assert(result.email.response); assert(result.token); - assert(~result.email.response.toString('utf-8').indexOf('To: bar@bat.com')); + var msg = result.email.response.toString('utf-8'); + assert(~msg.indexOf('/api/users/confirm')); + assert(~msg.indexOf('To: bar@bat.com')); done(); }); });