Cleanup user.js for style guide compliance

v1.18.x
Damian Bushong 12 years ago
parent 0a09156a5e
commit 78ef54baf2

@ -12,26 +12,25 @@ var utils = require('./../public/src/utils.js'),
(function(User) {
User.getUserField = function(uid, field, callback) {
RDB.hget('user:' + uid, field, function(err, data) {
if(err === null)
if(err === null) {
callback(data);
else
} else {
console.log(err);
}
});
}
User.getUserFields = function(uid, fields, callback) {
RDB.hmget('user:' + uid, fields, function(err, data) {
if(err === null) {
var returnData = {};
for(var i=0, ii=fields.length; i<ii; ++i) {
for(var i = 0, returnData = {}, ii=fields.length; i<ii; ++i) {
returnData[fields[i]] = data[i];
}
callback(returnData);
}
else
} else {
console.log(err);
}
});
}
@ -41,12 +40,11 @@ var utils = require('./../public/src/utils.js'),
return;
}
var uuids = uids.filter(function(value, index, self) {
return self.indexOf(value) === index;
});
var data = {},
loaded = 0;
uuids = uids.filter(function(value, index, self) {
return self.indexOf(value) === index;
});
for (var i=0, ii=uuids.length; i<ii; i++) {
(function(user_id) {
@ -60,7 +58,6 @@ var utils = require('./../public/src/utils.js'),
}
User.getUserData = function(uid, callback) {
RDB.hgetall('user:' + uid, function(err, data) {
if(err === null) {
if(data) {
@ -68,33 +65,29 @@ var utils = require('./../public/src/utils.js'),
delete data['password'];
}
callback(data);
}
else
} else {
console.log(err);
}
});
}
User.updateProfile = function(uid, data, callback) {
var fields = ['email', 'fullname', 'website', 'location', 'birthday', 'signature'];
var key = '';
if(data['signature'] !== undefined && data['signature'].length > 150) {
callback({error:'Signature can\'t be longer than 150 characters!'});
return;
}
for(var i=0,ii=fields.length; i<ii; ++i) {
for(var i = 0, key, ii = fields.length; i < ii; ++i) {
key = fields[i];
if(data[key] !== undefined) {
if(key === 'email') {
User.setUserField(uid, 'gravatarpicture', User.createGravatarURLFromEmail(data[key]));
RDB.set('email:' + data['email'] +':uid', uid);
}
else if(key === 'signature') {
} else if(key === 'signature') {
data[key] = utils.strip_tags(data[key]);
}
@ -141,7 +134,6 @@ var utils = require('./../public/src/utils.js'),
console.log('deleting uid ' + uid);
User.getUserData(uid, function(data) {
RDB.del('username:' + data['username'] + ':uid');
RDB.del('email:' + data['email'] +':uid');
RDB.del('userslug:'+ data['userslug'] +':uid');
@ -154,17 +146,16 @@ var utils = require('./../public/src/utils.js'),
callback(true);
});
}
else
} else {
callback(false);
}
});
}
User.create = function(username, password, email, callback) {
username = username.trim(), email = email.trim();
username = username.trim();
email = email.trim();
// @todo return a proper error? use node-validator?
if(!utils.isEmailValid(email) || !utils.isUserNameValid(username) || !utils.isPasswordValid(password)) {
console.log('Invalid email/username/password!');
callback(null, 0);
@ -174,7 +165,6 @@ var utils = require('./../public/src/utils.js'),
var userslug = utils.slugify(username);
User.exists(userslug, function(exists) {
if(exists) {
callback(null, 0);
return;
@ -202,15 +192,16 @@ var utils = require('./../public/src/utils.js'),
'reputation': 0,
'postcount': 0,
'lastposttime': 0,
'administrator': (uid==1)?1:0
'administrator': (uid == 1) ? 1 : 0
});
RDB.set('username:' + username + ':uid', uid);
RDB.set('email:' + email +':uid', uid);
RDB.set('userslug:'+ userslug +':uid', uid);
if(email)
if(email) {
User.sendConfirmationEmail(email);
}
RDB.incr('usercount', function(err, count) {
RDB.handle(err);
@ -233,8 +224,9 @@ var utils = require('./../public/src/utils.js'),
};
User.createGravatarURLFromEmail = function(email) {
if (!email)
if (!email) {
email = utils.generateUUID();
}
var md5sum = crypto.createHash('md5');
md5sum.update(email.toLowerCase().trim());
var gravatarURL = 'http://www.gravatar.com/avatar/' + md5sum.digest('hex') + '?default=identicon&s=128';
@ -268,12 +260,12 @@ var utils = require('./../public/src/utils.js'),
callback(userdata);
});
});
}
else
} else {
callback([]);
}
else
}
} else {
console.log(err);
}
});
}

Loading…
Cancel
Save