diff options
author | Matthew Wild <mwild1@gmail.com> | 2025-01-07 18:47:24 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2025-01-07 18:47:24 +0000 |
commit | a1fda1fd1a592281ae6656bf12155a4210e3cc03 (patch) | |
tree | a1f3f8b794f92d06c1258f89ee454eb99bb2d370 | |
parent | 54718fffe02d14ffa22a615bd03fc00faba1f819 (diff) | |
download | prosody-a1fda1fd1a592281ae6656bf12155a4210e3cc03.tar.gz prosody-a1fda1fd1a592281ae6656bf12155a4210e3cc03.zip |
prosodyctl: adduser: use shell user:create() to provide the implementation
This allows user creation to happen inside the running Prosody process, which
improves a number of things - such as executing event handlers for user
creation, fixing issues and race conditions with some storage drivers, etc.
The intent is to do the same for the other prosodyctl commands, but this is
the first proof of concept for the approach.
-rwxr-xr-x | prosodyctl | 33 |
1 files changed, 2 insertions, 31 deletions
@@ -146,38 +146,9 @@ function commands.adduser(arg) show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); return opts.help and 0 or 1; end - local user, host = jid_split(arg[1]); - if not user and host then - show_message [[Failed to understand JID, please supply the JID you want to create]] - show_usage [[adduser user@host]] - return 1; - end - - if not host then - show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; - return 1; - end - if not prosody.hosts[host] then - show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) - show_warning("The user will not be able to log in until this is changed."); - prosody.hosts[host] = startup.make_host(host); --luacheck: ignore 122 - end - - if prosodyctl.user_exists{ user = user, host = host } then - show_message [[That user already exists]]; - return 1; - end - - local password = read_password(); - if not password then return 1; end - - local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; - - if ok then return 0; end - - show_message(error_messages[msg]) - return 1; + local shell = require "prosody.util.prosodyctl.shell"; + return shell.shell({ ("user:create(%q, nil, %q)"):format(arg[1], "prosody:member") }); end function commands.passwd(arg) |