Build the email verification url from app context

https://github.com/strongloop/loopback/issues/408
This commit is contained in:
Raymond Feng 2014-07-26 22:39:42 -07:00
parent 5bb4cde593
commit 567e2530d7
2 changed files with 14 additions and 4 deletions

View File

@ -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='

View File

@ -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();
});
});