mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-20 19:29:57 +02:00
Merge branch 'master' of github.com:designcreateplay/NodeBB
This commit is contained in:
@@ -10,6 +10,7 @@ var db = require('./database'),
|
||||
plugins = require('./plugins'),
|
||||
CategoryTools = require('./categoryTools'),
|
||||
meta = require('./meta'),
|
||||
emitter = require('./emitter'),
|
||||
|
||||
async = require('async'),
|
||||
winston = require('winston'),
|
||||
@@ -299,19 +300,24 @@ var db = require('./database'),
|
||||
});
|
||||
};
|
||||
|
||||
Categories.onNewPostMade = function(uid, tid, pid, timestamp) {
|
||||
topics.getTopicFields(tid, ['cid', 'pinned'], function(err, topicData) {
|
||||
Categories.onNewPostMade = function(postData) {
|
||||
topics.getTopicFields(postData.tid, ['cid', 'pinned'], function(err, topicData) {
|
||||
if (err) {
|
||||
winston.error(err.message);
|
||||
}
|
||||
|
||||
var cid = topicData.cid;
|
||||
|
||||
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid);
|
||||
db.sortedSetAdd('categories:recent_posts:cid:' + cid, postData.timestamp, postData.pid);
|
||||
|
||||
if(parseInt(topicData.pinned, 10) === 0) {
|
||||
db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid);
|
||||
db.sortedSetAdd('categories:' + cid + ':tid', postData.timestamp, postData.tid);
|
||||
}
|
||||
|
||||
Categories.addActiveUser(cid, uid, timestamp);
|
||||
Categories.addActiveUser(cid, postData.uid, postData.timestamp);
|
||||
});
|
||||
};
|
||||
|
||||
emitter.on('event:newpost', Categories.onNewPostMade);
|
||||
|
||||
}(exports));
|
||||
@@ -9,6 +9,7 @@ var db = require('./database'),
|
||||
categories = require('./categories'),
|
||||
plugins = require('./plugins'),
|
||||
meta = require('./meta'),
|
||||
emitter = require('./emitter'),
|
||||
|
||||
async = require('async'),
|
||||
path = require('path'),
|
||||
@@ -68,9 +69,7 @@ var db = require('./database'),
|
||||
|
||||
db.incrObjectField('global', 'postCount');
|
||||
|
||||
topics.onNewPostMade(tid, postData.pid, timestamp);
|
||||
categories.onNewPostMade(uid, tid, postData.pid, timestamp);
|
||||
user.onNewPostMade(uid, tid, postData.pid, timestamp);
|
||||
emitter.emit('event:newpost', postData);
|
||||
|
||||
plugins.fireHook('filter:post.get', postData, next);
|
||||
},
|
||||
|
||||
@@ -21,7 +21,8 @@ var async = require('async'),
|
||||
notifications = require('./notifications'),
|
||||
favourites = require('./favourites'),
|
||||
meta = require('./meta'),
|
||||
Plugins = require('./plugins');
|
||||
Plugins = require('./plugins'),
|
||||
emitter = require('./emitter');
|
||||
|
||||
(function(Topics) {
|
||||
|
||||
@@ -1015,12 +1016,14 @@ var async = require('async'),
|
||||
Topics.setTopicField(tid, 'lastposttime', timestamp);
|
||||
};
|
||||
|
||||
Topics.onNewPostMade = function(tid, pid, timestamp, callback) {
|
||||
Topics.increasePostCount(tid);
|
||||
Topics.updateTimestamp(tid, timestamp);
|
||||
Topics.addPostToTopic(tid, pid, timestamp, callback);
|
||||
Topics.onNewPostMade = function(postData) {
|
||||
Topics.increasePostCount(postData.tid);
|
||||
Topics.updateTimestamp(postData.tid, postData.timestamp);
|
||||
Topics.addPostToTopic(postData.tid, postData.pid, postData.timestamp);
|
||||
};
|
||||
|
||||
emitter.on('event:newpost', Topics.onNewPostMade);
|
||||
|
||||
Topics.addPostToTopic = function(tid, pid, timestamp, callback) {
|
||||
db.sortedSetAdd('tid:' + tid + ':posts', timestamp, pid, callback);
|
||||
};
|
||||
|
||||
146
src/user.js
146
src/user.js
@@ -15,6 +15,7 @@ var bcrypt = require('bcryptjs'),
|
||||
groups = require('./groups'),
|
||||
topics = require('./topics'),
|
||||
events = require('./events'),
|
||||
emitter = require('./emitter'),
|
||||
Emailer = require('./emailer');
|
||||
|
||||
(function(User) {
|
||||
@@ -23,6 +24,7 @@ var bcrypt = require('bcryptjs'),
|
||||
User.notifications = require('./user/notifications');
|
||||
User.reset = require('./user/reset');
|
||||
|
||||
require('./user/create')(User);
|
||||
require('./user/follow')(User);
|
||||
require('./user/profile')(User);
|
||||
require('./user/admin')(User);
|
||||
@@ -30,136 +32,6 @@ var bcrypt = require('bcryptjs'),
|
||||
require('./user/settings')(User);
|
||||
require('./user/search')(User);
|
||||
|
||||
User.create = function(userData, callback) {
|
||||
userData = userData || {};
|
||||
userData.userslug = utils.slugify(userData.username);
|
||||
|
||||
userData.username = userData.username.trim();
|
||||
if (userData.email !== undefined) {
|
||||
userData.email = userData.email.trim();
|
||||
userData.email = validator.escape(userData.email);
|
||||
}
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
if (userData.email) {
|
||||
next(!utils.isEmailValid(userData.email) ? new Error('Invalid Email!') : null);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
next((!utils.isUserNameValid(userData.username) || !userData.userslug) ? new Error('Invalid Username!') : null);
|
||||
},
|
||||
function(next) {
|
||||
if (userData.password) {
|
||||
next(!utils.isPasswordValid(userData.password) ? new Error('Invalid Password!') : null);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
User.exists(userData.userslug, function(err, exists) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(exists ? new Error('Username taken!') : null);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
if (userData.email) {
|
||||
User.email.available(userData.email, function(err, available) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(!available ? new Error('Email taken!') : null);
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
plugins.fireHook('filter:user.create', userData, function(err, filteredUserData){
|
||||
next(err, utils.merge(userData, filteredUserData));
|
||||
});
|
||||
}
|
||||
], function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
userData = results[results.length - 1];
|
||||
|
||||
db.incrObjectField('global', 'nextUid', function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var gravatar = User.createGravatarURLFromEmail(userData.email);
|
||||
var timestamp = Date.now();
|
||||
var password = userData.password;
|
||||
|
||||
userData = {
|
||||
'uid': uid,
|
||||
'username': userData.username,
|
||||
'userslug': userData.userslug,
|
||||
'fullname': '',
|
||||
'location': '',
|
||||
'birthday': '',
|
||||
'website': '',
|
||||
'email': userData.email || '',
|
||||
'signature': '',
|
||||
'joindate': timestamp,
|
||||
'picture': gravatar,
|
||||
'gravatarpicture': gravatar,
|
||||
'uploadedpicture': '',
|
||||
'profileviews': 0,
|
||||
'reputation': 0,
|
||||
'postcount': 0,
|
||||
'lastposttime': 0,
|
||||
'banned': 0,
|
||||
'status': 'online'
|
||||
};
|
||||
|
||||
db.setObject('user:' + uid, userData, function(err) {
|
||||
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
db.setObjectField('username:uid', userData.username, uid);
|
||||
db.setObjectField('userslug:uid', userData.userslug, uid);
|
||||
|
||||
if (userData.email !== undefined) {
|
||||
db.setObjectField('email:uid', userData.email, uid);
|
||||
if (parseInt(uid, 10) !== 1) {
|
||||
User.email.verify(uid, userData.email);
|
||||
}
|
||||
}
|
||||
|
||||
plugins.fireHook('action:user.create', userData);
|
||||
db.incrObjectField('global', 'userCount');
|
||||
|
||||
db.sortedSetAdd('users:joindate', timestamp, uid);
|
||||
db.sortedSetAdd('users:postcount', 0, uid);
|
||||
db.sortedSetAdd('users:reputation', 0, uid);
|
||||
|
||||
groups.joinByGroupName('registered-users', uid);
|
||||
|
||||
if (password) {
|
||||
User.hashPassword(password, function(err, hash) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
User.setUserField(uid, 'password', hash);
|
||||
callback(null, uid);
|
||||
});
|
||||
} else {
|
||||
callback(null, uid);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
User.getUserField = function(uid, field, callback) {
|
||||
db.getObjectField('user:' + uid, field, callback);
|
||||
@@ -328,7 +200,7 @@ var bcrypt = require('bcryptjs'),
|
||||
|
||||
User.hashPassword = function(password, callback) {
|
||||
if (!password) {
|
||||
return callback(password);
|
||||
return callback(null, password);
|
||||
}
|
||||
|
||||
bcrypt.genSalt(nconf.get('bcrypt_rounds'), function(err, salt) {
|
||||
@@ -339,16 +211,18 @@ var bcrypt = require('bcryptjs'),
|
||||
});
|
||||
};
|
||||
|
||||
User.onNewPostMade = function(uid, tid, pid, timestamp) {
|
||||
User.addPostIdToUser(uid, pid, timestamp);
|
||||
User.onNewPostMade = function(postData) {
|
||||
User.addPostIdToUser(postData.uid, postData.pid, postData.timestamp);
|
||||
|
||||
User.incrementUserFieldBy(uid, 'postcount', 1, function(err, newpostcount) {
|
||||
db.sortedSetAdd('users:postcount', newpostcount, uid);
|
||||
User.incrementUserFieldBy(postData.uid, 'postcount', 1, function(err, newpostcount) {
|
||||
db.sortedSetAdd('users:postcount', newpostcount, postData.uid);
|
||||
});
|
||||
|
||||
User.setUserField(uid, 'lastposttime', timestamp);
|
||||
User.setUserField(postData.uid, 'lastposttime', postData.timestamp);
|
||||
};
|
||||
|
||||
emitter.on('event:newpost', User.onNewPostMade);
|
||||
|
||||
User.addPostIdToUser = function(uid, pid, timestamp) {
|
||||
db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid);
|
||||
};
|
||||
|
||||
134
src/user/create.js
Normal file
134
src/user/create.js
Normal file
@@ -0,0 +1,134 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
db = require('./../database'),
|
||||
utils = require('./../../public/src/utils'),
|
||||
validator = require('validator'),
|
||||
plugins = require('./../plugins'),
|
||||
groups = require('./../groups');
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
User.create = function(userData, callback) {
|
||||
userData = userData || {};
|
||||
userData.userslug = utils.slugify(userData.username);
|
||||
|
||||
userData.username = userData.username.trim();
|
||||
if (userData.email !== undefined) {
|
||||
userData.email = userData.email.trim();
|
||||
userData.email = validator.escape(userData.email);
|
||||
}
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
next(!utils.isEmailValid(userData.email) ? new Error('Invalid Email!') : null);
|
||||
},
|
||||
function(next) {
|
||||
next((!utils.isUserNameValid(userData.username) || !userData.userslug) ? new Error('Invalid Username!') : null);
|
||||
},
|
||||
function(next) {
|
||||
next(!utils.isPasswordValid(userData.password) ? new Error('Invalid Password!') : null);
|
||||
},
|
||||
function(next) {
|
||||
User.exists(userData.userslug, function(err, exists) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(exists ? new Error('Username taken!') : null);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
if (userData.email) {
|
||||
User.email.available(userData.email, function(err, available) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(!available ? new Error('Email taken!') : null);
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
plugins.fireHook('filter:user.create', userData, function(err, filteredUserData){
|
||||
next(err, utils.merge(userData, filteredUserData));
|
||||
});
|
||||
}
|
||||
], function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
userData = results[results.length - 1];
|
||||
|
||||
db.incrObjectField('global', 'nextUid', function(err, uid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var gravatar = User.createGravatarURLFromEmail(userData.email);
|
||||
var timestamp = Date.now();
|
||||
var password = userData.password;
|
||||
|
||||
userData = {
|
||||
'uid': uid,
|
||||
'username': userData.username,
|
||||
'userslug': userData.userslug,
|
||||
'fullname': '',
|
||||
'location': '',
|
||||
'birthday': '',
|
||||
'website': '',
|
||||
'email': userData.email || '',
|
||||
'signature': '',
|
||||
'joindate': timestamp,
|
||||
'picture': gravatar,
|
||||
'gravatarpicture': gravatar,
|
||||
'uploadedpicture': '',
|
||||
'profileviews': 0,
|
||||
'reputation': 0,
|
||||
'postcount': 0,
|
||||
'lastposttime': 0,
|
||||
'banned': 0,
|
||||
'status': 'online'
|
||||
};
|
||||
|
||||
db.setObject('user:' + uid, userData, function(err) {
|
||||
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
db.setObjectField('username:uid', userData.username, uid);
|
||||
db.setObjectField('userslug:uid', userData.userslug, uid);
|
||||
|
||||
if (userData.email !== undefined) {
|
||||
db.setObjectField('email:uid', userData.email, uid);
|
||||
if (parseInt(uid, 10) !== 1) {
|
||||
User.email.verify(uid, userData.email);
|
||||
}
|
||||
}
|
||||
|
||||
plugins.fireHook('action:user.create', userData);
|
||||
db.incrObjectField('global', 'userCount');
|
||||
|
||||
db.sortedSetAdd('users:joindate', timestamp, uid);
|
||||
db.sortedSetAdd('users:postcount', 0, uid);
|
||||
db.sortedSetAdd('users:reputation', 0, uid);
|
||||
|
||||
groups.joinByGroupName('registered-users', uid);
|
||||
|
||||
if (password) {
|
||||
User.hashPassword(password, function(err, hash) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
User.setUserField(uid, 'password', hash);
|
||||
callback(null, uid);
|
||||
});
|
||||
} else {
|
||||
callback(null, uid);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user