Is it possible to set user reputation via the write API?
Alternatively, it is possible to bypass posting restrictions when posting via the write API?
I'm using the custom SSO plugin found here: https://github.com/julianlam/nodebb-plugin-sso-oauth (with a few alterations). Inside the parseUserReturn
function, I'm trying to set their default picture so:
var profile = {};
/* Required. */
profile.id = data.id;
profile.displayName = data.name;
profile.emails = [{ value: data.email }];
/* Optional. */
profile.picture = data.avatar;
callback(null, profile);
However, it seems to be ignored. What am I doing wrong?
I'm using NodeBB v0.7.3
edit: I'd also like to set defaults on user:*:settings
to have followTopicsOnReply
and followTopicsOnCreate
to 1
after a successful sign up via SSO. Is this something I can do?
Sure, so -- setting profile
will only instruct the plugin to use the values as they are provided. After the user is created (that is, once you have a uid), you can reference the user library to do your own modifications:
var user = module.parent.require('user');
user.setUserField('picture', urlToPicture, function(err) {
// ...
});
Thanks @julian.
I was able to set the picture by extending the OAuth.login
method (https://github.com/julianlam/nodebb-plugin-sso-oauth/blob/master/library.js#L160-L213).
function _getAvatar(data) {
...
}
...
var success = function (uid) {
// Save provider-specific information to the user
User.setUserField(uid, constants.name + 'Id', payload.oAuthid);
db.setObjectField(constants.name + 'Id:uid', payload.oAuthid, uid);
var avatar = _getAvatar(payload.data);
if (avatar) {
User.setUserField(uid, 'picture', avatar);
User.setUserField(uid, 'uploadedpicture', avatar);
}
...
I'm not sure why but just updating the picture
didn't seem to work. I had to update uploadedpicture
as well.
The other thing I needed to do was change the settings. Turns out that user:*:settings
isn't fully populated until I visit the settings page and click on "save settings". So what I ended up having to do was:
var mySettings = {}; // Custom settings.
User.saveSettings(uid, mySettings, function (err) {});
and that seemed to work.
Thanks for checking back in!