diff options
author | Kim Alvefur <zash@zash.se> | 2023-02-23 18:10:06 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2023-02-23 18:10:06 +0100 |
commit | 701fb4fce01b2e7a99b14a83aecf3f95cd2ad955 (patch) | |
tree | 4d8fe03ad4c0a6efb54918d24e7f561f016517d1 | |
parent | 893dce647b177d05b18f01ec8e31854ed15ebb7c (diff) | |
download | prosody-701fb4fce01b2e7a99b14a83aecf3f95cd2ad955.tar.gz prosody-701fb4fce01b2e7a99b14a83aecf3f95cd2ad955.zip |
mod_admin_shell: Add commands to disable and enable accounts
First proper UI to enable/disable, allowing it to be tested.
-rw-r--r-- | plugins/mod_admin_shell.lua | 32 |
1 files changed, 32 insertions, 0 deletions
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 |