• GNU/Linux Admin

    In the fork of your login plugin, you should be able to save the remoteId into the user hash on the user.create call.


  • @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 } ]

  • Global Moderator Plugin & Theme Dev

    @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 ?

  • NodeBB

    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);
    };
    

  • Thanks ! Why i can get it with user.getUserFields but not with user.getUser ?


  • Is there any existent function to get uid having a field value ? (in my case external uid)

  • GNU/Linux Admin

    .getUserField() should work, though you will need to implement the whitelist as @baris has mentioned.


  • @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);
    };

  • Global Moderator Plugin & Theme Dev

    Yeah you'll have to save a map of auids to uids in the database.


  • @PitaJ is there any example of code for this ?

  • GNU/Linux Admin

    @Simos what have you tried so far?


  • @julian I've try only user.getUserDataByField function 😄 than i've discovered is limited.

  • GNU/Linux Admin

    Yes, you can use that method. You just need to create a plugin hook listener to the whitelist hook @baris mentioned, so you can add the remoteId to the whitelisted fields.


  • @julian so i need to make an hook on getUserDataByField ?


  • @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 😕


  • I'm getting confused , i would need to have a function like getUidByEmail but for my added field AUID :

    User.getUidByEmail = function (email, callback) {
    db.sortedSetScore('email:uid', email.toLowerCase(), callback);
    };

    i need :

    User.getUidByAUID = function (auid, callback) {
    db.sortedSetScore('auid:uid', auid, callback);
    };

    What i've to do to make that function with a plugin ? I've been able to make it work modifing nodebb source user/index.js , but i don't understad how i can do with a plugin without modifing nodebb core.

  • NodeBB

    @Simos said in Forcing UID value:

    auid:uid

    Just put it in your plugin.

    plugin.getUserDataByField = function (callerUid, field, fieldValue, callback) {
        if (field === 'auid') {
            user.getUidByAUid(fieldValue, next);
        }
    ...
    };
    
    plugin.getUidByAUid= funtion(auid, callback) {
       db.sortedSetScore('auid:uid', auid, callback);
    };
    

  • @baris thanks ! i've do add also:

    var db = module.parent.require('../database');
    

    right ?

  • Global Moderator Plugin & Theme Dev

    @Simos require.main.require is preferred:

    require.main.require('./src/database')
    

Suggested Topics

| |