Forcing UID value
-
i've made a fork of nodebb-plugin-login-mysite ( https://github.com/SimosNap/nodebb-plugin-login-anope ) to login to the forum using IRC anope account. On IRC users can change both username and email so UID is the only things i can refer for account updates
-
@julian Pheraps i miss something , i don't see an user hash field in user table :
[ { uid: 4,
username: 'antani',
userslug: 'antani',
picture: '',
status: 'online',
postcount: 0,
reputation: 0,
'email:confirmed': 0,
lastonline: 1542925209728,
flags: null,
banned: 0,
'banned:expire': 0,
joindate: 1542925209728,
uploadedpicture: undefined,
'icon:text': 'A',
'icon:bgColor': '#2196f3',
joindateISO: '2018-11-22T22:20:09.728Z',
lastonlineISO: '2018-11-22T22:20:09.728Z',
banned_until: 0,
banned_until_readable: 'Not Banned',
administrator: false } ] -
@Simos what you just posted is what Julian referred to by "user hash". He was saying "hash table" otherwise called an object or a dictionary.
-
@PitaJ i've try to add the remoteid on user.create :
console.log(_uid); if (!_uid) { user.create({ remoteid: userObj.uid, username: userObj.display, email: userObj.email }, callback); } else { callback(null, _uid) }
I suppose it don't add the remoteid value because remoteid field doesn't exist right ?
-
You will need a plugin to save the
remoteid
into the user hash, so in your plugin listen for'filter:user.create'
here is how it should look.myPlugin.filterUserCreate = function (hookData, callback) { hookData.user.remoteid = hookData.data.remoteid; callback(null, hookData); };
-
@julian it look getUserField() need nodebb uid i've to get userdata having the remoteid (the customfield i've added)
plugin.filterUserCreate = function (data, callback) {
data.user.auid = data.data.auid;
callback(null, data);
};plugin.whitelistFields = function(data, callback) {
data.whitelist.push('auid');
callback(null, data);
}; -
Yeah you'll have to save a map of auids to uids in the database.
-
@julian I'm trying to understand how make an hook for getUserDataByField, but pheraps i'm too noob, i write what i've done :
i've added the user create hook in plugin.json :
{ "hook": "filter:user.create", "method": "filterUserCreate" },
than i've added the function to the library lo listen for 'filter:user.create' :
plugin.filterUserCreate = function (data, callback) { data.user.auid = data.data.auid; callback(null, data); };
I've added the whitelist hook :
{ "hook": "filter:user.whitelistFields", "method": "whitelistFields" },
than i've added the function to the library to listen for 'filter:user.whitelistFields' :
plugin.whitelistFields = function(data, callback) { data.whitelist.push('auid'); callback(null, data); };
At this point i've checked and everythings work, on user create i've also the 'auid' fields with relative value, now i need a function to get user data knowing the remote id field 'auid', i've checked in controllers/user.js and i've found 'getUserDataByField' function wich should help me for my pourpose, but it's limited to uid, username and email.
I've begin adding the hook for getUserDataByField function in plugin.json :{ "hook": "filter:user.getUserDataByField", "method": "getUserDataByField" }
than i've begin to adding the filter listener in the library :
plugin.getUserDataByField = function (callerUid, field, fieldValue, callback) { if (field === 'auid') { user.getUidByAUid(fieldValue, next); }
Than i've loose my self