Comparison

prosodyctl @ 13599:54803fb5b4d4

prosodyctl: passwd: Use user:password() shell command for implementation
author Matthew Wild <mwild1@gmail.com>
date Tue, 07 Jan 2025 19:25:35 +0000
parent 13595:6fafe51df188
child 13600:854df134274f
comparison
equal deleted inserted replaced
13598:2cd43975a15c 13599:54803fb5b4d4
155 local opts = parse_args(arg, only_help); 155 local opts = parse_args(arg, only_help);
156 if opts.help or not arg[1] then 156 if opts.help or not arg[1] then
157 show_usage([[passwd JID]], [[Set the password for the specified user account in Prosody]]); 157 show_usage([[passwd JID]], [[Set the password for the specified user account in Prosody]]);
158 return opts.help and 0 or 1; 158 return opts.help and 0 or 1;
159 end 159 end
160 local user, host = jid_split(arg[1]); 160
161 if not user and host then 161 local shell = require "prosody.util.prosodyctl.shell";
162 show_message [[Failed to understand JID, please supply the JID you want to set the password for]] 162 return shell.shell({ ("user:password(%q, nil)"):format(arg[1]) });
163 show_usage [[passwd user@host]]
164 return 1;
165 end
166
167 if not host then
168 show_message [[Please specify a JID, including a host. e.g. alice@example.com]];
169 return 1;
170 end
171
172 if not prosody.hosts[host] then
173 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host)
174 show_warning("The user will not be able to log in until this is changed.");
175 prosody.hosts[host] = startup.make_host(host); --luacheck: ignore 122
176 end
177
178 if not prosodyctl.user_exists { user = user, host = host } then
179 show_message [[That user does not exist, use prosodyctl adduser to create a new user]]
180 return 1;
181 end
182
183 local password = read_password();
184 if not password then return 1; end
185
186 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password };
187
188 if ok then return 0; end
189
190 show_message(error_messages[msg])
191 return 1;
192 end 163 end
193 164
194 function commands.deluser(arg) 165 function commands.deluser(arg)
195 local opts = parse_args(arg, only_help); 166 local opts = parse_args(arg, only_help);
196 if opts.help or not arg[1] then 167 if opts.help or not arg[1] then