aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-03-26 16:45:23 +0200
committerKim Alvefur <zash@zash.se>2023-03-26 16:45:23 +0200
commit1d6989afb1a42f23b3dc1b1d39162d8fa3163996 (patch)
tree39e62bfeb9ddf9927b4da10f799d84b84a7cd662
parent50058a1e46d8c14f06d961eaa574065396ae0cef (diff)
downloadprosody-1d6989afb1a42f23b3dc1b1d39162d8fa3163996.tar.gz
prosody-1d6989afb1a42f23b3dc1b1d39162d8fa3163996.zip
mod_admin_shell: Simplify user creation when no role given
Idea here is to prevent a user from being created with the default role if a different role was given, but that dance wouldn't be needed if no role is provided.
-rw-r--r--plugins/mod_admin_shell.lua24
1 files changed, 16 insertions, 8 deletions
diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua
index d135197c..8c6bab9d 100644
--- a/plugins/mod_admin_shell.lua
+++ b/plugins/mod_admin_shell.lua
@@ -1516,21 +1516,29 @@ function def_env.user:create(jid, password, role)
elseif um.user_exists(username, host) then
return nil, "User exists";
end
- local ok, err = um.create_user(username, nil, host);
- if not ok then
- return nil, "Could not create user: "..err;
- end
if role then
+ local ok, err = um.create_user(username, nil, host);
+ if not ok then
+ return nil, "Could not create user: "..err;
+ end
+
local role_ok, rerr = um.set_user_role(jid, host, role);
if not role_ok then
return nil, "Could not set role: " .. tostring(rerr);
end
- end
- local ok, err = um.set_password(username, password, host, nil);
- if not ok then
- return nil, "Could not set password for user: "..err;
+ if password then
+ local ok, err = um.set_password(username, password, host, nil);
+ if not ok then
+ return nil, "Could not set password for user: "..err;
+ end
+ end
+ else
+ local ok, err = um.create_user(username, password, host);
+ if not ok then
+ return nil, "Could not create user: "..err;
+ end
end
return true, "User created";