Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.43k stars 2.78k forks source link

REST API :: PUT /users/{id} :: command for regenerate/change password #30482

Open adriansev opened 3 months ago

adriansev commented 3 months ago

Feature Request

It would be really useful to have a programmatic way to regenerate and send user password.

Use case

For programmatic creation of users, an addition of regenerate and send password would complete the user addition procedure. Moreover, for security reasons, would be useful to have this functionality as part of REST API.

Suggested implementation

No response

Suggested steps

No response

JonBendtsen commented 2 months ago

Some notes for changing the password

https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/user/card.php#L679 https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/user/card.php#L686

Seems like the entire segment from line 673 to like 695 handles password changes and if needed sending it to the user.

JonBendtsen commented 2 months ago

The 2 functions called above are found here:

public function setPassword: https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/user/class/user.class.php#L2394

public function send_password https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/user/class/user.class.php#L2536

JonBendtsen commented 2 months ago

What kind of http method would be a good choice here?

GET, PUT, POST?

GET - no, because we are not getting any data PUT - no because we are not putting any data either, the password is generated and then sent, we do not supply the password POST - same reasons as PUT

JonBendtsen commented 2 months ago

basing my attempt on:

     * @url GET {id}/setGroup/{group}
     */
    public function setGroup($id, $group, $entity = 1)
JonBendtsen commented 2 months ago

I'll sprinkle in some code from public function put($id, $request_data = null) as well

JonBendtsen commented 2 months ago

It changes the password, but at the moment I can not get it to send, and I do not like some variables I had to set

image