这听起来很常见,我认为您不需要 ACL。您将需要有会话,然后您可以根据当前登录的用户更改视图的外观。一个不完整的例子是这样的:
// Assumes:
// - You set req.session.user when user logs in
// - The url route has a :name so you can do req.param() to get the name of the page being viewed
db.users.getCurrentUser(req.session.user, gotLoggedInUser)
db.users.getUserByName({name: req.param('name')}, gotUser)
然后将其传递给视图,当您执行以下操作时res.render()
:
var is_viewing_own_page = currentUser._id.toString() === loggedInUser._id.toString()
然后视图可以做这样的事情(假设是玉):
- if (is_viewing_own_page)
div You are looking at your own page
- else
div You are viewing someone else's page