Add debug information for user.login

This commit is contained in:
Raymond Feng 2014-01-27 14:31:38 -08:00
parent 0779d07fe2
commit c35f762d4e
1 changed files with 5 additions and 0 deletions

View File

@ -18,6 +18,7 @@ var Model = require('../loopback').Model
, ACL = require('./acl').ACL
, assert = require('assert');
var debug = require('debug')('loopback:user');
/**
* Default User properties.
*/
@ -143,20 +144,24 @@ User.login = function (credentials, fn) {
var defaultError = new Error('login failed');
if(err) {
debug('User: error reported from User.findOne: %j', err);
fn(defaultError);
} else if(user) {
user.hasPassword(credentials.password, function(err, isMatch) {
if(err) {
debug('User: error reported from User.hasPassword: %j', err);
fn(defaultError);
} else if(isMatch) {
user.accessTokens.create({
ttl: Math.min(credentials.ttl || User.settings.ttl, User.settings.maxTTL)
}, fn);
} else {
debug('User: invalid password for user %s', query.email || query.username);
fn(defaultError);
}
});
} else {
debug('User: no matching record found for user %s', query.email || query.username);
fn(defaultError);
}
});