Comparison

plugins/muc/register.lib.lua @ 10448:cbe524ed1a6a

MUC: Indicate origin of registration related errors
author Kim Alvefur <zash@zash.se>
date Mon, 25 Nov 2019 23:51:41 +0100
parent 10373:51ea82f55322
child 10794:4585fe53e21f
comparison
equal deleted inserted replaced
10447:b5fd1637f15c 10448:cbe524ed1a6a
64 -- Check if the chosen nickname is reserved 64 -- Check if the chosen nickname is reserved
65 local requested_nick = jid_resource(stanza.attr.to); 65 local requested_nick = jid_resource(stanza.attr.to);
66 local reserved_by = get_registered_jid(room, requested_nick); 66 local reserved_by = get_registered_jid(room, requested_nick);
67 if reserved_by and reserved_by ~= jid_bare(stanza.attr.from) then 67 if reserved_by and reserved_by ~= jid_bare(stanza.attr.from) then
68 module:log("debug", "%s attempted to use nick %s reserved by %s", stanza.attr.from, requested_nick, reserved_by); 68 module:log("debug", "%s attempted to use nick %s reserved by %s", stanza.attr.from, requested_nick, reserved_by);
69 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); 69 local reply = st.error_reply(stanza, "cancel", "conflict", nil, room.jid):up();
70 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); 70 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
71 return true; 71 return true;
72 end 72 end
73 73
74 -- Check if the occupant has a reservation they must use 74 -- Check if the occupant has a reservation they must use
77 if nick then 77 if nick then
78 if event.occupant then 78 if event.occupant then
79 event.occupant.nick = jid_bare(event.occupant.nick) .. "/" .. nick; 79 event.occupant.nick = jid_bare(event.occupant.nick) .. "/" .. nick;
80 elseif event.dest_occupant.nick ~= jid_bare(event.dest_occupant.nick) .. "/" .. nick then 80 elseif event.dest_occupant.nick ~= jid_bare(event.dest_occupant.nick) .. "/" .. nick then
81 module:log("debug", "Attempt by %s to join as %s, but their reserved nick is %s", stanza.attr.from, requested_nick, nick); 81 module:log("debug", "Attempt by %s to join as %s, but their reserved nick is %s", stanza.attr.from, requested_nick, nick);
82 local reply = st.error_reply(stanza, "cancel", "not-acceptable"):up(); 82 local reply = st.error_reply(stanza, "cancel", "not-acceptable", nil, room.jid):up();
83 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); 83 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
84 return true; 84 return true;
85 end 85 end
86 end 86 end
87 end 87 end
101 101
102 local function handle_register_iq(room, origin, stanza) 102 local function handle_register_iq(room, origin, stanza)
103 local user_jid = jid_bare(stanza.attr.from) 103 local user_jid = jid_bare(stanza.attr.from)
104 local affiliation = room:get_affiliation(user_jid); 104 local affiliation = room:get_affiliation(user_jid);
105 if affiliation == "outcast" then 105 if affiliation == "outcast" then
106 origin.send(st.error_reply(stanza, "auth", "forbidden")); 106 origin.send(st.error_reply(stanza, "auth", "forbidden", room.jid));
107 return true; 107 return true;
108 elseif not (affiliation or allow_unaffiliated) then 108 elseif not (affiliation or allow_unaffiliated) then
109 origin.send(st.error_reply(stanza, "auth", "registration-required")); 109 origin.send(st.error_reply(stanza, "auth", "registration-required"));
110 return true; 110 return true;
111 end 111 end