# HG changeset patch # User Kim Alvefur # Date 1677172206 -3600 # Node ID e96c3ea64996ede150bf74493b6a5f8cbcd29e0d # Parent d2333b468d07504c874d713a3a4378f0b936dbfe mod_admin_shell: Add commands to disable and enable accounts First proper UI to enable/disable, allowing it to be tested. diff -r d2333b468d07 -r e96c3ea64996 plugins/mod_admin_shell.lua --- a/plugins/mod_admin_shell.lua Thu Feb 23 16:28:57 2023 +0100 +++ b/plugins/mod_admin_shell.lua Thu Feb 23 18:10:06 2023 +0100 @@ -275,6 +275,8 @@ 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 @@ 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