comparison mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 32:00d5e133c84d

mod_adhoc_cmd_admin: switch to utils.dataforms. Thanks MattJ for making this possible ;)
author Florian Zeitz <florob@babelmonkeys.de>
date Sat, 10 Oct 2009 03:24:41 +0200
parents b384999b047f
children f3225c55288f
comparison
equal deleted inserted replaced
30:fc4806a98fc4 32:00d5e133c84d
3 -- This file is MIT/X11 licensed. Please see the 3 -- This file is MIT/X11 licensed. Please see the
4 -- COPYING file in the source package for more information. 4 -- COPYING file in the source package for more information.
5 -- 5 --
6 6
7 local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid"; 7 local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid";
8 local dataforms_new = require "util.dataforms".new;
8 local usermanager_user_exists = require "core.usermanager".user_exists; 9 local usermanager_user_exists = require "core.usermanager".user_exists;
9 local usermanager_create_user = require "core.usermanager".create_user; 10 local usermanager_create_user = require "core.usermanager".create_user;
10 11
11 local is_admin = require "core.usermanager".is_admin; 12 local is_admin = require "core.usermanager".is_admin;
12 local admins = set.new(config.get(module:get_host(), "core", "admins")); 13 local admins = set.new(config.get(module:get_host(), "core", "admins"));
34 if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then 35 if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then
35 form = tag; 36 form = tag;
36 break; 37 break;
37 end 38 end
38 end 39 end
39 local fields = {}; 40 local layout = {
40 for _, field in ipairs(form.tags) do 41 { name = "accountjid", type = "jid-single" };
41 if field.name == "field" and field.attr.var then 42 { name = "password", type = "text-private" };
42 for i, tag in ipairs(field.tags) do 43 { name = "password-verify", type = "text-private" };
43 if tag.name == "value" and #tag.tags == 0 then 44 };
44 fields[field.attr.var] = tag[1] or ""; 45 dataforms_new(layout);
45 end 46 local fields = layout:data(form);
46 end
47 end
48 end
49 local username, host, resource = jid.split(fields.accountjid); 47 local username, host, resource = jid.split(fields.accountjid);
50 if (fields.password == fields["password-verify"]) and username and host and host == stanza.attr.to then 48 if (fields.password == fields["password-verify"]) and username and host and host == stanza.attr.to then
51 if usermanager_user_exists(username, host) then 49 if usermanager_user_exists(username, host) then
52 origin.send(st.error_reply(stanza, "cancel", "conflict", "Account already exists"):up() 50 origin.send(st.error_reply(stanza, "cancel", "conflict", "Account already exists"):up()
53 :tag("command", {xmlns="http://jabber.org/protocol/commands", 51 :tag("command", {xmlns="http://jabber.org/protocol/commands",