requesting user reputation
-
i am able to get user image or usermail with app.user
<script>
var imgName = app.user.picture;
var email = app.user.email;how can i get user reputation with similar approach?
-
@baris said in requesting user reputation:
Added in https://github.com/NodeBB/NodeBB/commit/bdc23b4a8d42b19126858d6d6256e54b1711ba73
thanks for the quick adition
could you add postcount too?on other side..
whats is the approach to make it server side on a custom template? -
anyone? thank you
-
Up again om this
Questions.
1- can you add app.user.postcount? @baris
2- whats is the approach to make it server side on a custom template? I mean read logged in info from user and show his avatar email etc. Mot sure which filter could work
3- and another how can i read app.user.icon:text again on client side, it gives me errorThank you if anyone helps
-
For icon text use
app.user['icon:text']
For adding the data from the currently logged in user to custom template, the
req
in your route controller function will havereq.uid
which is the current user's uid. Use that to lookup the user data and add it to the template variables object. -
@yariplus said in requesting user reputation:
For icon text use
app.user['icon:text']
For adding the data from the currently logged in user to custom template, the req in your template controller function will have
req.uid
which is the current user's uid. Use that to lookup the user data and add it to the template variables object.Thank you
That new template is in standalone plugin so not sure how to get that req.uid. Is that always accesible? Cam you me give a code example ? -
Sure.
Here's the custom-pages render function as an example.
https://github.com/psychobunny/nodebb-plugin-custom-pages/blob/master/library.js#L18-L23You can modify it to add getUserUsers to the render vaiables, using the req.uid
var User = module.parent.require('./user'); function renderCustomPage(req, res) { var path = req.path.replace(/\/(api\/)?/, '').replace(/\/$/, ''); User.getUserFields(req.uid, ['username', 'topiccount', 'reputation'], function (err, user) { if (err || !user) user = null; res.render(path, { title: plugin.pagesHash[path].name, user: user }); }); }
Now on all the custom pages templates, the variable
{user.reputation}
will be available. (and undefined for guests) -
@yariplus said in requesting user reputation:
Sure.
Here's the custom-pages render function as an example.
https://github.com/psychobunny/nodebb-plugin-custom-pages/blob/master/library.js#L18-L23You can modify it to add getUserUsers to the render vaiables, using the req.uid
var User = module.parent.require('./user'); function renderCustomPage(req, res) { var path = req.path.replace(/\/(api\/)?/, '').replace(/\/$/, ''); User.getUserFields(req.uid, ['username', 'topiccount', 'reputation'], function (err, user) { if (err || !user) user = null; res.render(path, { title: plugin.pagesHash[path].name, user: user }); }); }
Now on all the custom pages templates, the variable
{user.reputation}
will be available. (and undefined for guests)works perfect
@yariplus 4 president