Misc & isRootUserId()

This commit is contained in:
Bryan Ashby 2016-08-29 21:03:48 -06:00
parent a54caed41e
commit 57309b433a
1 changed files with 12 additions and 8 deletions

View File

@ -18,6 +18,8 @@ exports.loadProperties = loadProperties;
exports.getUserIdsWithProperty = getUserIdsWithProperty; exports.getUserIdsWithProperty = getUserIdsWithProperty;
exports.getUserList = getUserList; exports.getUserList = getUserList;
exports.isRootUserId = function(id) { return 1 === id; };
function User() { function User() {
var self = this; var self = this;
@ -28,7 +30,7 @@ function User() {
this.isAuthenticated = function() { this.isAuthenticated = function() {
return true === self.authenticated; return true === self.authenticated;
} };
this.isValid = function() { this.isValid = function() {
if(self.userId <= 0 || self.username.length < Config.users.usernameMin) { if(self.userId <= 0 || self.username.length < Config.users.usernameMin) {
@ -58,13 +60,15 @@ function User() {
groupNames = [ groupNames ]; groupNames = [ groupNames ];
} }
// :TODO: _.some()
var isMember = false; var isMember = false;
_.forEach(groupNames, groupName => { _.forEach(groupNames, groupName => {
if(-1 !== self.groups.indexOf(groupName)) { if(-1 !== self.groups.indexOf(groupName)) {
isMember = true; isMember = true;
return false; // stop iteration return false; // stop iteration
} }
}); });
return isMember; return isMember;
@ -103,9 +107,9 @@ User.prototype.load = function(userId, cb) {
}; };
User.prototype.authenticate = function(username, password, cb) { User.prototype.authenticate = function(username, password, cb) {
var self = this; const self = this;
var cachedInfo = {}; const cachedInfo = {};
async.waterfall( async.waterfall(
[ [
@ -178,7 +182,7 @@ User.prototype.authenticate = function(username, password, cb) {
self.authenticated = true; self.authenticated = true;
} }
cb(err); return cb(err);
} }
); );
}; };