Forcing UID value



  • I've just try to put this function in the plugin and call that directly without hooks,

    plugin.getUidByAUid = function(auid, callback) {
    	if (!auid) {
    		return callback(null, 0);
    	}
        console.log('auid param log:' + auid);
        db.sortedSetScore('auid:uid', auid, callback);
    };
    
    plugin.getUserDataByField = function (callerUid, field, fieldValue, callback) {
    	async.waterfall([
    		function (next) {
    			if (field === 'uid') {
    				next(null, fieldValue);
    			} else if (field === 'auid') {
    				plugin.getUidByAUid(fieldValue, next);
    			} else if (field === 'username') {
    				user.getUidByUsername(fieldValue, next);
    			} else if (field === 'email') {
    				user.getUidByEmail(fieldValue, next);
    			} else {
    				next(null, null);
    			}
    		},
    		function (uid, next) {
    			if (!uid) {
    				return next(null, null);
    			}
    			userController.getUserDataByUID(callerUid, uid, next);
    		},
    	], callback);
    };
    
    

    than i've try each field using plugin.getUserDataByField and not userController.getUserDataByField (hook doesn't exist so was ignored) :

            function (userObj, callback) {
                //user.getUidByEmail(String(userObj.email), callback)
                //user.getUserDataByUID('1','4', callback);
                //plugin.getUidByAUid(String(userObj.uid), callback);
                console.log(userObj.uid);
                plugin.getUserDataByField('1', 'auid', userObj.uid, function(err, userData) {
                    console.log(userData.auid);
                	//return callback(userData.auid, null);
                });
    

    Using all field work except that auid , db.sortedSetScore('auid:uid', auid, callback) return always null 😕



  • I need pheraps to import some other module ?


  • Admin

    Hi there, I do not see where you are trying to call db.sortedSetScore... though keep in mind it believe it is also getSortedSetScore 😄



  • @julian if you take a look to plugin.getUserDataByField function i call plugin.getUidByAUid wich call db.sortedSetScore.



  • @julian said in Forcing UID value:

    getSortedSetScore

    getSortedSetScore doesn't exist it's sortedSetScore
    https://github.com/NodeBB/NodeBB/blob/master/src/user/index.js#L129



  • plugin.getUidByAUid = function(auid, callback) {
    	if (!auid) {
    		return callback(null, 0);
    	}
        db.sortedSetScore('auid:uid', auid, callback);
    };
    

    return always null , so i've checked if the function was working and i've try to change db.sortedSetScore('auid:uid', auid, callback) to db.sortedSetScore('email:uid', 'myemail@gmail.com' , callback) and it work .

    At this point i've also checked using redis-cli for 'auid' field, it exist and has the right value.

    I really don't understand what's wrong, it look db.sortedSetScore can't find 'auid' for some reason 😕



  • I'm still blocked here 😞 any suggestion ?


  • Admin

    What is the type of auid:uid ? Is it a sorted set or hash? Run this in mongo shell db.objects.find({_key: "auid:uid"});



  • @baris i'm using Redis not mongoDB

    127.0.0.1:6379> HGET user:1 auid
    "3074"


  • Global Moderator

    @Simos the equivalent code would be

    ZSCORE auid:uid 1


  • @PitaJ @baris

    127.0.0.1:6379> HGET user:1 auid
    "3074"
    127.0.0.1:6379> ZSCORE auid:uid 1
    (nil)
    127.0.0.1:6379>

    it say nil


  • Admin

    run this type auid:uid



  • @baris said in Forcing UID value:

    type auid:uid

    127.0.0.1:6379> type auid:uid
    none
    127.0.0.1:6379>


  • Admin

    That means auid:uid doesn't exist so your code doesn't actually write anything into it.



  • @baris so why i can get it in the hash ? auid exist ...

    127.0.0.1:6379> HGETALL user:1

    1. "username"
    2. "Simos"
    3. "userslug"
    4. "simos"
    5. "email"
    6. "admin@simosnap.org"
    7. "joindate"
    8. "1542893552374"
    9. "lastonline"
    10. "1543850453258"
    11. "picture"
    12. ""
    13. "fullname"
    14. ""
    15. "location"
    16. ""
    17. "birthday"
    18. ""
    19. "website"
    20. ""
    21. "signature"
    22. ""
    23. "uploadedpicture"
    24. ""
    25. "profileviews"
    26. "2"
    27. "reputation"
    28. "0"
    29. "postcount"
    30. "1"
    31. "topiccount"
    32. "1"
    33. "lastposttime"
    34. "1542893552974"
    35. "banned"
    36. "0"
    37. "status"
    38. "online"
    39. "gdpr_consent"
    40. "0"
    41. "acceptTos"
    42. "0"
    43. "uid"
    44. "1"
    45. "password"
    46. "XXXXXXXXXXXXXXXXXXXXXXXXXX"
    47. "passwordExpiry"
    48. "0"
    49. "groupTitle"
    50. "["administrators"]"
    51. "auid"
    52. "3074"

  • Admin

    @Simos said in Forcing UID value:

    "auid"
    "3074"

    It exists as part of the user hash, but if you don't save it into auid:uid then sortedSetScore will always return null. You need to set it into auid:uid as well with db.sortedSetAdd('auid:uid', uid, auid, callback);



  • @baris i'm losing my self again ... i've already added that value to user hash on user create, in wich part of plugin now i've to save it into auid:uid with the function you have mentioned ?
    I'm new to redis ... pheraps i'm confused because i usually use mysql , but i 've understand that is completly different.


  • Admin

    Gotto do it when you create the user, so same place as you set it in user hash.



  • @baris
    I suppose after user creation ... as i don't understand how i should pass uid before having it ...


  • Admin

    Yes, you should be able to do it in action:user.create


Log in to reply
 

Suggested Topics

| |