changeset 34:fc374b724270

mod_adhoc_cmd_admin: Define form layout only once.
author Florian Zeitz <florob@babelmonkeys.de>
date Sat, 10 Oct 2009 04:16:11 +0200
parents f3225c55288f
children 3c49411d4aa3
files mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua
diffstat 1 files changed, 13 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua	Sat Oct 10 04:01:45 2009 +0200
+++ b/mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua	Sat Oct 10 04:16:11 2009 +0200
@@ -14,6 +14,17 @@
 
 local sessions = {};
 
+local add_user_layout = {
+	title= "Adding a User";
+	instructions = "Fill out this form to add a user.";
+
+	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
+	{ name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" };
+	{ name = "password", type = "text-private", label = "The password for this account" };
+	{ name = "password-verify", type = "text-private", label = "Retype password" };
+};
+dataforms_new(add_user_layout)
+
 function add_user_command_handler(item, origin, stanza)
 	if not is_admin(stanza.attr.from) then
 		module:log("warn", "Non-admin %s tried to add a user", tostring(jid.bare(stanza.attr.from)));
@@ -37,13 +48,7 @@
 				break;
 			end
 		end
-		local layout = {
-			{ name = "accountjid", type = "jid-single" };
-			{ name = "password", type = "text-private" };
-			{ name = "password-verify", type = "text-private" };
-		};
-		dataforms_new(layout);
-		local fields = layout:data(form);
+		local fields = add_user_layout:data(form);
 		local username, host, resource = jid.split(fields.accountjid);
 		if (fields.password == fields["password-verify"]) and username and host and host == stanza.attr.to then
 			if usermanager_user_exists(username, host) then
@@ -85,19 +90,9 @@
 	else
 		local sessionid=uuid.generate();
 		sessions[sessionid] = "executing";
-		local form = {
-			title= "Adding a User";
-			instructions = "Fill out this form to add a user.";
-
-			{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
-			{ name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" };
-			{ name = "password", type = "text-private", label = "The password for this account" };
-			{ name = "password-verify", type = "text-private", label = "Retype password" };
-		};
-		dataforms_new(form);
 		origin.send(st.reply(stanza):tag("command", {xmlns="http://jabber.org/protocol/commands",
 			node="http://jabber.org/protocol/admin#add-user", sessionid=sessionid,
-			status="executing"}):add_child(form:form()));
+			status="executing"}):add_child(add_user_layout:form()));
 	end
 	return true;
 end