Comparison

prosodyctl @ 13595:6fafe51df188

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.
author Matthew Wild <mwild1@gmail.com>
date Tue, 07 Jan 2025 18:47:24 +0000
parent 13167:6226f75f55a7
child 13599:54803fb5b4d4
comparison
equal deleted inserted replaced
13594:abbdcef552fb 13595:6fafe51df188
144 local opts = parse_args(arg, only_help); 144 local opts = parse_args(arg, only_help);
145 if opts.help or not arg[1] then 145 if opts.help or not arg[1] then
146 show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); 146 show_usage([[adduser JID]], [[Create the specified user account in Prosody]]);
147 return opts.help and 0 or 1; 147 return opts.help and 0 or 1;
148 end 148 end
149 local user, host = jid_split(arg[1]); 149
150 if not user and host then 150 local shell = require "prosody.util.prosodyctl.shell";
151 show_message [[Failed to understand JID, please supply the JID you want to create]] 151 return shell.shell({ ("user:create(%q, nil, %q)"):format(arg[1], "prosody:member") });
152 show_usage [[adduser user@host]]
153 return 1;
154 end
155
156 if not host then
157 show_message [[Please specify a JID, including a host. e.g. alice@example.com]];
158 return 1;
159 end
160
161 if not prosody.hosts[host] then
162 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host)
163 show_warning("The user will not be able to log in until this is changed.");
164 prosody.hosts[host] = startup.make_host(host); --luacheck: ignore 122
165 end
166
167 if prosodyctl.user_exists{ user = user, host = host } then
168 show_message [[That user already exists]];
169 return 1;
170 end
171
172 local password = read_password();
173 if not password then return 1; end
174
175 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password };
176
177 if ok then return 0; end
178
179 show_message(error_messages[msg])
180 return 1;
181 end 152 end
182 153
183 function commands.passwd(arg) 154 function commands.passwd(arg)
184 local opts = parse_args(arg, only_help); 155 local opts = parse_args(arg, only_help);
185 if opts.help or not arg[1] then 156 if opts.help or not arg[1] then