aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2021-01-15 18:42:45 +0000
committerMatthew Wild <mwild1@gmail.com>2021-01-15 18:42:45 +0000
commit8696e7c401418784a0becec6c00430572de1a450 (patch)
treeddb40bf59acdd973ec57baee68ff1db149eb3ac8
parent77afc5ac351e92234e29cff80f55881a8e2b2f93 (diff)
downloadprosody-8696e7c401418784a0becec6c00430572de1a450.tar.gz
prosody-8696e7c401418784a0becec6c00430572de1a450.zip
MUC: Allow modules to add to the room registration form, and handle the result
-rw-r--r--plugins/muc/register.lib.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/plugins/muc/register.lib.lua b/plugins/muc/register.lib.lua
index d917b396..b6559410 100644
--- a/plugins/muc/register.lib.lua
+++ b/plugins/muc/register.lib.lua
@@ -56,6 +56,20 @@ local registration_form = dataforms.new {
{ name = "muc#register_roomnick", type = "text-single", required = true, label = "Nickname"},
};
+module:handle_items("muc-registration-field", function (event)
+ module:log("debug", "Adding MUC registration form field: %s", event.item.name);
+ table.insert(registration_form, event.item);
+end, function (event)
+ module:log("debug", "Removing MUC registration form field: %s", event.item.name);
+ local removed_field_name = event.item.name;
+ for i, field in ipairs(registration_form) do
+ if field.name == removed_field_name then
+ table.remove(registration_form, i);
+ break;
+ end
+ end
+end);
+
local function enforce_nick_policy(event)
local origin, stanza = event.origin, event.stanza;
local room = assert(event.room); -- FIXME
@@ -114,6 +128,8 @@ local function handle_register_iq(room, origin, stanza)
if stanza.attr.type == "get" then
reply:query("jabber:iq:register");
if registered_nick then
+ -- I find it strange, but XEP-0045 says not to include
+ -- the current registration data (only the registered name)
reply:tag("registered"):up();
reply:tag("username"):text(registered_nick);
origin.send(reply);
@@ -183,6 +199,13 @@ local function handle_register_iq(room, origin, stanza)
-- Checks passed, save the registration
if registered_nick ~= desired_nick then
local registration_data = { reserved_nickname = desired_nick };
+ module:fire_event("muc-registration-submitted", {
+ room = room;
+ origin = origin;
+ stanza = stanza;
+ submitted_data = reg_data;
+ affiliation_data = registration_data;
+ });
local ok, err_type, err_condition = room:set_affiliation(true, user_jid, affiliation or "member", nil, registration_data);
if not ok then
origin.send(st.error_reply(stanza, err_type, err_condition));