From 701fb4fce01b2e7a99b14a83aecf3f95cd2ad955 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 23 Feb 2023 18:10:06 +0100 Subject: mod_admin_shell: Add commands to disable and enable accounts First proper UI to enable/disable, allowing it to be tested. --- plugins/mod_admin_shell.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua index c03a74b8..4a3a0641 100644 --- a/plugins/mod_admin_shell.lua +++ b/plugins/mod_admin_shell.lua @@ -275,6 +275,8 @@ function commands.help(session, data) print [[user:setrole(jid, host, role) - Set primary role of a user (see 'help roles')]] print [[user:addrole(jid, host, role) - Add a secondary role to a user]] print [[user:delrole(jid, host, role) - Remove a secondary role from a user]] + print [[user:disable(jid) - Disable the specified user account, preventing login]] + print [[user:enable(jid) - Enable the specified user account, restoring login access]] print [[user:delete(jid) - Permanently remove the specified user account]] print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] elseif section == "roles" then @@ -1521,6 +1523,36 @@ function def_env.user:create(jid, password, role) return true, "User created"; end +function def_env.user:disable(jid) + local username, host = jid_split(jid); + if not prosody.hosts[host] then + return nil, "No such host: "..host; + elseif not um.user_exists(username, host) then + return nil, "No such user"; + end + local ok, err = um.disable_user(username, host); + if ok then + return true, "User disabled"; + else + return nil, "Could not disable user: "..err; + end +end + +function def_env.user:enable(jid) + local username, host = jid_split(jid); + if not prosody.hosts[host] then + return nil, "No such host: "..host; + elseif not um.user_exists(username, host) then + return nil, "No such user"; + end + local ok, err = um.enable_user(username, host); + if ok then + return true, "User enabled"; + else + return nil, "Could not enable user: "..err; + end +end + function def_env.user:delete(jid) local username, host = jid_split(jid); if not prosody.hosts[host] then -- cgit v1.2.3