Changeset

12991:6d7e3d5463d8

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.
author Kim Alvefur <zash@zash.se>
date Sun, 26 Mar 2023 16:45:23 +0200
parents 12990:939049732317
children 12992:651813914151
files plugins/mod_admin_shell.lua
diffstat 1 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_admin_shell.lua	Sun Mar 26 16:07:34 2023 +0200
+++ b/plugins/mod_admin_shell.lua	Sun Mar 26 16:45:23 2023 +0200
@@ -1516,21 +1516,29 @@
 	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";