Merge pull request #154 from strongloop/feature/debug-login-error
Add debug information for user.login
This commit is contained in:
commit
c711b99b8a
|
@ -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('An error is reported from User.findOne: %j', err);
|
||||
fn(defaultError);
|
||||
} else if(user) {
|
||||
user.hasPassword(credentials.password, function(err, isMatch) {
|
||||
if(err) {
|
||||
debug('An error is 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('The password is invalid for user %s', query.email || query.username);
|
||||
fn(defaultError);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
debug('No matching record is found for user %s', query.email || query.username);
|
||||
fn(defaultError);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue