diff mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 35:3c49411d4aa3

mod_adhoc_cmd_admin: Fixed style, some typos, and got down to <100LOC. Perhaps we need util.adhoc?
author Matthew Wild <mwild1@gmail.com>
date Sat, 10 Oct 2009 09:33:44 +0100
parents fc374b724270
children 58d326d86a9a
line wrap: on
line diff
--- a/mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua	Sat Oct 10 04:16:11 2009 +0200
+++ b/mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua	Sat Oct 10 09:33:44 2009 +0100
@@ -14,7 +14,7 @@
 
 local sessions = {};
 
-local add_user_layout = {
+local add_user_layout = dataforms_new{
 	title= "Adding a User";
 	instructions = "Fill out this form to add a user.";
 
@@ -23,7 +23,6 @@
 	{ 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
@@ -42,12 +41,7 @@
 			sessions[stanza.tags[1].attr.sessionid] = nil;
 			return true;
 		end
-		for _, tag in ipairs(stanza.tags[1].tags) do
-			if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then
-				form = tag;
-				break;
-			end
-		end
+		form = stanza.tags[1]:find_child_with_ns("jabber:x:data");
 		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
@@ -80,10 +74,10 @@
 		else
 			module:log("debug", fields.accountjid .. " " .. fields.password .. " " .. fields["password-verify"]);
 			origin.send(st.error_reply(stanza, "cancel", "conflict",
-				"Invalid data.\nPasswords missmatch, or empy username"):up()
+				"Invalid data.\nPassword mismatch, or empty username"):up()
 				:tag("command", {xmlns="http://jabber.org/protocol/commands",
 					node="http://jabber.org/protocol/admin#add-user", status="canceled"})
-				:tag("note", {type="error"}):text("Invalid data.\nPasswords missmatch, or empy username"));
+				:tag("note", {type="error"}):text("Invalid data.\nPassword mismatch, or empty username"));
 			sessions[stanza.tags[1].attr.sessionid] = nil;
 			return true;
 		end