Sorry, I'm still trying to do this and since I saw many topics on the subject, I thought I'd share my process, even if I think I'm not qualified to do this - maybe it'll help someone some day.
I found in src\user\data.js
:
User.setUserField = async function (uid, field, value) {
await User.setUserFields(uid, { [field]: value });
};
User.setUserFields = async function (uid, data) {
await db.setObject(`user:${uid}`, data);
for (const [field, value] of Object.entries(data)) {
plugins.hooks.fire('action:user.set', { uid, field, value, type: 'set' });
}
};
src\user\profile.js
:
User.updateProfile = async function (uid, data, extraFields) {
let fields = [
'username', 'email', 'fullname', 'website', 'location',
'groupTitle', 'birthday', 'signature', 'aboutme',
];
if (Array.isArray(extraFields)) {
fields = _.uniq(fields.concat(extraFields));
}
if (!data.uid) {
throw new Error('[[error:invalid-update-uid]]');
}
const updateUid = data.uid;
const result = await plugins.hooks.fire('filter:user.updateProfile', {
uid: uid,
data: data,
fields: fields,
});
fields = result.fields;
data = result.data;
await validateData(uid, data);
const oldData = await User.getUserFields(updateUid, fields);
const updateData = {};
await Promise.all(fields.map(async (field) => {
if (!(data[field] !== undefined && typeof data[field] === 'string')) {
return;
}
data[field] = data[field].trim();
if (field === 'email') {
return await updateEmail(updateUid, data.email);
} else if (field === 'username') {
return await updateUsername(updateUid, data.username);
} else if (field === 'fullname') {
return await updateFullname(updateUid, data.fullname);
}
updateData[field] = data[field];
}));
if (Object.keys(updateData).length) {
await User.setUserFields(updateUid, updateData);
}
plugins.hooks.fire('action:user.updateProfile', {
uid: uid,
data: data,
fields: fields,
oldData: oldData,
});
return await User.getUserFields(updateUid, [
'email', 'username', 'userslug',
'picture', 'icon:text', 'icon:bgColor',
]);
};
I've also tried to read three plugins that were interesting to me, see how they did it : Cash mod, OpenFantasy & Custom Fields. But eventhough I tried a lot I haven't been able to reproduce anything they did in the quickstart plugin. Even my console.log("hello world")
wasn't working, hahah. They're not working either anyway...
I know it's not good to edit core files, but I'm really getting frustrated. If I can't add custom fields, I can't use NodeBB and I'll be back on Forumotion, which is a pain in the ass.
I thought of creating another table which would have all the custom fields and a column that would get the UID of the user those fields are related to. But I was having such a hard time finding how to show tables in MongoDB, especially user tables and switched to PostgreSQL, only to find out there isn't any user table, just data stored in a row...
So yeah, is there anyone to give me like hints on how I could do that ? I know I have to do a plugin, but I just don't know where to start and I can't seem to replicate what others did before.
Thanks