filter:users.search filter:users.build hooks

v1.18.x
barisusakli 10 years ago
parent b48fdfadad
commit 73d65dd123

@ -43,7 +43,7 @@ usersController.getOnlineUsers = function(req, res, next) {
anonymousUserCount: websockets.getOnlineAnonCount()
};
res.render('users', userData);
render(req, res, userData, next);
});
};
@ -72,7 +72,7 @@ usersController.getUsers = function(set, count, req, res, next) {
pagination: pagination.create(1, pageCount)
};
userData['route_' + set] = true;
res.render('users', userData);
render(req, res, userData, next);
});
};
@ -113,10 +113,19 @@ usersController.getUsersForSearch = function(req, res, next) {
users: data.users
};
res.render('users', userData);
render(req, res, userData, next);
});
};
function render(req, res, data, next) {
plugins.fireHook('filter:users.build', {req: req, res: res, templateData: data}, function(err, data) {
if (err) {
return next(err);
}
res.render('users', data.templateData);
});
}
module.exports = usersController;

@ -87,72 +87,76 @@ module.exports = function(User) {
function(uid, next) {
userData.uid = uid;
db.setObject('user:' + uid, userData, next);
}
], function(err) {
if (err) {
return callback(err);
}
async.parallel([
function(next) {
db.incrObjectField('global', 'userCount', next);
},
function(next) {
db.setObjectField('username:uid', userData.username, userData.uid, next);
},
function(next) {
db.setObjectField('userslug:uid', userData.userslug, userData.uid, next);
},
function(next) {
db.sortedSetAdd('users:joindate', timestamp, userData.uid, next);
},
function(next) {
db.sortedSetsAdd(['users:postcount', 'users:reputation'], 0, userData.uid, next);
},
function(next) {
groups.join('registered-users', userData.uid, next);
},
function(next) {
if (userData.email) {
db.setObjectField('email:uid', userData.email.toLowerCase(), userData.uid, next);
if (parseInt(userData.uid, 10) !== 1 && parseInt(meta.config.requireEmailConfirmation, 10) === 1) {
User.email.sendValidationEmail(userData.uid, userData.email);
},
function(next) {
async.parallel([
function(next) {
db.setObjectField('username:uid', userData.username, userData.uid, next);
},
function(next) {
db.setObjectField('userslug:uid', userData.userslug, userData.uid, next);
},
function(next) {
db.sortedSetAdd('users:joindate', timestamp, userData.uid, next);
},
function(next) {
db.sortedSetsAdd(['users:postcount', 'users:reputation'], 0, userData.uid, next);
},
function(next) {
groups.join('registered-users', userData.uid, next);
},
function(next) {
if (userData.email) {
db.setObjectField('email:uid', userData.email.toLowerCase(), userData.uid, next);
if (parseInt(userData.uid, 10) !== 1 && parseInt(meta.config.requireEmailConfirmation, 10) === 1) {
User.email.sendValidationEmail(userData.uid, userData.email);
}
} else {
next();
}
} else {
next();
}
},
function(next) {
if (!data.password) {
return next();
}
User.hashPassword(data.password, function(err, hash) {
if (err) {
return next(err);
},
function(next) {
if (!data.password) {
return next();
}
async.parallel([
async.apply(User.setUserField, userData.uid, 'password', hash),
async.apply(User.reset.updateExpiry, userData.uid)
], next);
});
}
], function(err) {
if (err) {
return callback(err);
}
User.hashPassword(data.password, function(err, hash) {
if (err) {
return next(err);
}
async.parallel([
async.apply(User.setUserField, userData.uid, 'password', hash),
async.apply(User.reset.updateExpiry, userData.uid)
], next);
});
}
], next);
},
function(results, next) {
User.updateUserCount(next);
},
function(next) {
if (userNameChanged) {
User.notifications.sendNameChangeNotification(userData.uid, userData.username);
}
plugins.fireHook('action:user.create', userData);
callback(null, userData.uid);
});
});
next(null, userData.uid);
}
], callback);
});
});
};
User.updateUserCount = function(callback) {
db.sortedSetCard('users:joindate', function(err, count) {
if (err) {
return callback(err);
}
db.setObjectField('global', 'userCount', count, callback);
});
};
function isDataValid(userData, callback) {
async.parallel({
emailValid: function(next) {

@ -106,7 +106,7 @@ module.exports = function(User) {
db.deleteAll(['followers:' + uid, 'following:' + uid, 'user:' + uid], next);
},
function(next) {
db.decrObjectField('global', 'userCount', next);
User.updateUserCount(next);
}
], callback);
});

@ -5,6 +5,7 @@ var async = require('async'),
meta = require('../meta'),
user = require('../user'),
pagination = require('../pagination'),
plugins = require('../plugins'),
db = require('../database');
module.exports = function(User) {
@ -52,7 +53,10 @@ module.exports = function(User) {
searchResult.timing = (process.elapsedTimeSince(startTime) / 1000).toFixed(2);
searchResult.users = userData;
next(null, searchResult);
plugins.fireHook('filter:users.search', {result: searchResult, uid: uid}, next);
},
function(data, next) {
next(null, data.result);
}
], callback);
};

Loading…
Cancel
Save