Auto generate password for account created through API?

(Rémi Auguste) #1

I’m developing a little script that creates user account through discourse API. The create API doesn’t allow user creation without passing a password.

It would be nice if the API creates the user even if no password is specified and when activating the user is asked for his password.

Is it the kind of feature that could be added or is there already a better way to do that ? (or did I missed an option in the admin panel ?)

(Vinoth Kannan) #2

So you are going to send email to activate the user? If yes then it’s better to send invites instead of creating accounts via API. Because invitations will activate the user instantly when they accept it and the password reset email will be sent.

(Rémi Auguste) #3

Oh, I didn’t know invites worked this way. I’m going to look into it, thanks :wink:

(Rémi Auguste) #4

The API about invitation is not well presented in the documentation… I guess I’ll have to read the code to find out how it works.

Is there a way to accept the invitation for the user and just send him the “reset password” mail ? The goal here is to easily add a willing user without asking him to set his password directly. In our case, we have a contact form on our website (with name, email and message) bearing a checkbox “register me on the forum”.

So I’d like the server handling the form to add the user to discourse though API.

(Vinoth Kannan) #5

Can’t you ask for password and confirm password when a user click the “register me on the forum” checkbox?

So you can even bypass password resetting email.

(Rémi Auguste) #6

We could do that, but the form handler isn’t yet behind a SSL layer so I’d rather have Discourse handling the password.
So I thought that if there was a way to do that more or less easily directly in Discourse it would be better. If not, I’ll fall back to your proposal :wink:

(Vinoth Kannan) #7

Okay I understand. What is the problem you are facing with Invites API?

(Rémi Auguste) #8

I hardly find any documentation about it, I did some try and retry on some guessed usage but I always ends up with “502 Bad Gateway”.

I tried:

  • POST /invites
  • POST /admin/invites
  • POST /invite

I don’t get what’s the expected path and params for invitation.

I looked into discourse_api/routes.txt at master · discourse/discourse_api · GitHub but I don’t understand how to read it…

(Vinoth Kannan) #9

as per official Ruby API client code POST /invites is correct I guess.

(Rémi Auguste) #10

Ok, with a “email” field in the params it doesn’t do the gateway error. I manage to create an invite that way.

I’ll try to create a user with a random password and trigger the password reset action to see if I can achieve my goal this way :rolling_eyes: