Adding User Programatically



  • I am making a NodeBB integration via a JAVA application, and so far have been able to:

    1. Check if user already exists...
    2. Compare Provided Password to that of hash in collection...

    Now, my question is, what are the minimum requirements for adding a user to the collection?

    I have the nodebb-plugin-write-api configured, and can use that for creation, however would rather use the native MongoDB insert.


  • Global Moderator

    There are a lot of things involved with user creation, you should probably just use the write API.



  • Is there tho? Can't I just check for the next available UID and add uid, user, pass and email? If even that? Won't the rest of the values needed just be added by the main controller within NodeDB when the user logs into the actual forum?


  • Global Moderator

    This is a probably incomplete list of what needs to be done on user creation:

    • get nextUid
    • create userslug
    • make sure userslug is unique
    • increment uid
    • save all of this data:
    {
    	username,
    	userslug,
    	email,
    	joindate,
    	lastonline: joindate,
    	picture,
    	fullname,
    	location,
    	birthday,
    	website: '',
    	signature: '',
    	uploadedpicture: '',
    	profileviews: 0,
    	reputation: 0,
    	postcount: 0,
    	topiccount: 0,
    	lastposttime: 0,
    	banned: 0,
    	status: 'online',
    }
    
    • increment usercount
    • add username:uid map
    • add userslug:uid map
    • add sorted username
    • add to user joindates
    • add to users not validated
    • add to postcount and reputation sets
    • add to registered users group
    • send email validation maybe
    • hash the password, save the hash

    And that doesn't even consider the processing that certain plugins may do to new users. You don't want to do this yourself.



  • Thank you. This was very descriptive. Sorry, I am ultra new to collection vs relational data structures and JAVA, and Node... so.

    This really isn't much mapping to be done considering my experience and carelessness about time consuming processes coming from MySQL and PHP as a main production stack.

    THANK YOU. I will use the write-api, I just didn't want to rely on a third party plugin for my system in JAVA (Minecraft Plugin) of communicating with NodeBB etc.

    Once I create the initial user with the API I can then manipulate the data from JAVA with no issues.

    Again, thanks for the clarification.


  • Admin

    @kipperedsnack As @pitaj suggests, write API is your best bet. I maintain it, and so don't really think of it like a separate piece of software, but something tailor-made to work well with NodeBB 😃

    We split things into plugins because not everybody needs every feature, so you pick and choose the features you need, the write API being one of those.



  • I had a new dev, who was using our Write API to add users, and had an issue where he creates too many. I removed these users from the DB instead of NodeBB back end (in hindsight I see my mistake).

    It works, but obviously left some documents behind...

    0_1520212854692_da3e438c-6fe5-479e-b5d4-9d280699cc31-image.png

    The "steve images" are Guest users that were username_0 etc.

    Where can I find the groups in the DB to inspect for these ghosted IDs?


  • Admin

    Hm... depends, how did you remove those users from the db? If it was removing their user:# keys, then you ought to just add them back and then delete them the normal way...



  • @julian whats the normal way of deleting user/s?


  • Global Moderator

    @developer from the admin control panel. Manage -> Users I think


 

Suggested Topics

| |