mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
filter:users.search filter:users.build hooks
This commit is contained in:
@@ -43,7 +43,7 @@ usersController.getOnlineUsers = function(req, res, next) {
|
|||||||
anonymousUserCount: websockets.getOnlineAnonCount()
|
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)
|
pagination: pagination.create(1, pageCount)
|
||||||
};
|
};
|
||||||
userData['route_' + set] = true;
|
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
|
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;
|
module.exports = usersController;
|
||||||
|
|||||||
@@ -87,72 +87,76 @@ module.exports = function(User) {
|
|||||||
function(uid, next) {
|
function(uid, next) {
|
||||||
userData.uid = uid;
|
userData.uid = uid;
|
||||||
db.setObject('user:' + uid, userData, next);
|
db.setObject('user:' + uid, userData, next);
|
||||||
}
|
},
|
||||||
], function(err) {
|
function(next) {
|
||||||
if (err) {
|
async.parallel([
|
||||||
return callback(err);
|
function(next) {
|
||||||
}
|
db.setObjectField('username:uid', userData.username, userData.uid, next);
|
||||||
|
},
|
||||||
async.parallel([
|
function(next) {
|
||||||
function(next) {
|
db.setObjectField('userslug:uid', userData.userslug, userData.uid, next);
|
||||||
db.incrObjectField('global', 'userCount', next);
|
},
|
||||||
},
|
function(next) {
|
||||||
function(next) {
|
db.sortedSetAdd('users:joindate', timestamp, userData.uid, next);
|
||||||
db.setObjectField('username:uid', userData.username, userData.uid, next);
|
},
|
||||||
},
|
function(next) {
|
||||||
function(next) {
|
db.sortedSetsAdd(['users:postcount', 'users:reputation'], 0, userData.uid, next);
|
||||||
db.setObjectField('userslug:uid', userData.userslug, userData.uid, next);
|
},
|
||||||
},
|
function(next) {
|
||||||
function(next) {
|
groups.join('registered-users', userData.uid, next);
|
||||||
db.sortedSetAdd('users:joindate', timestamp, userData.uid, next);
|
},
|
||||||
},
|
function(next) {
|
||||||
function(next) {
|
if (userData.email) {
|
||||||
db.sortedSetsAdd(['users:postcount', 'users:reputation'], 0, userData.uid, next);
|
db.setObjectField('email:uid', userData.email.toLowerCase(), userData.uid, next);
|
||||||
},
|
if (parseInt(userData.uid, 10) !== 1 && parseInt(meta.config.requireEmailConfirmation, 10) === 1) {
|
||||||
function(next) {
|
User.email.sendValidationEmail(userData.uid, userData.email);
|
||||||
groups.join('registered-users', userData.uid, next);
|
}
|
||||||
},
|
} else {
|
||||||
function(next) {
|
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();
|
function(next) {
|
||||||
}
|
if (!data.password) {
|
||||||
},
|
return next();
|
||||||
function(next) {
|
|
||||||
if (!data.password) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
User.hashPassword(data.password, function(err, hash) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async.parallel([
|
User.hashPassword(data.password, function(err, hash) {
|
||||||
async.apply(User.setUserField, userData.uid, 'password', hash),
|
if (err) {
|
||||||
async.apply(User.reset.updateExpiry, userData.uid)
|
return next(err);
|
||||||
], next);
|
}
|
||||||
});
|
|
||||||
}
|
async.parallel([
|
||||||
], function(err) {
|
async.apply(User.setUserField, userData.uid, 'password', hash),
|
||||||
if (err) {
|
async.apply(User.reset.updateExpiry, userData.uid)
|
||||||
return callback(err);
|
], next);
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
], next);
|
||||||
|
},
|
||||||
|
function(results, next) {
|
||||||
|
User.updateUserCount(next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
if (userNameChanged) {
|
if (userNameChanged) {
|
||||||
User.notifications.sendNameChangeNotification(userData.uid, userData.username);
|
User.notifications.sendNameChangeNotification(userData.uid, userData.username);
|
||||||
}
|
}
|
||||||
plugins.fireHook('action:user.create', userData);
|
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) {
|
function isDataValid(userData, callback) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
emailValid: function(next) {
|
emailValid: function(next) {
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ module.exports = function(User) {
|
|||||||
db.deleteAll(['followers:' + uid, 'following:' + uid, 'user:' + uid], next);
|
db.deleteAll(['followers:' + uid, 'following:' + uid, 'user:' + uid], next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
db.decrObjectField('global', 'userCount', next);
|
User.updateUserCount(next);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ var async = require('async'),
|
|||||||
meta = require('../meta'),
|
meta = require('../meta'),
|
||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
pagination = require('../pagination'),
|
pagination = require('../pagination'),
|
||||||
|
plugins = require('../plugins'),
|
||||||
db = require('../database');
|
db = require('../database');
|
||||||
|
|
||||||
module.exports = function(User) {
|
module.exports = function(User) {
|
||||||
@@ -52,7 +53,10 @@ module.exports = function(User) {
|
|||||||
searchResult.timing = (process.elapsedTimeSince(startTime) / 1000).toFixed(2);
|
searchResult.timing = (process.elapsedTimeSince(startTime) / 1000).toFixed(2);
|
||||||
searchResult.users = userData;
|
searchResult.users = userData;
|
||||||
|
|
||||||
next(null, searchResult);
|
plugins.fireHook('filter:users.search', {result: searchResult, uid: uid}, next);
|
||||||
|
},
|
||||||
|
function(data, next) {
|
||||||
|
next(null, data.result);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user