fix: Updates docs and verification to halt joining process.

When returning the error and showing to user not allowed screen we were not completely halting the prejoin operation when token verification fails on room join and the token is valid in general.
This commit is contained in:
damencho 2020-09-10 10:07:30 -05:00
parent 7cafa205ee
commit 0354dbe889
1 changed files with 9 additions and 3 deletions

View File

@ -40,6 +40,7 @@ local function load_config()
end end
load_config(); load_config();
-- verify user and whether he is allowed to join a room based on the token information
local function verify_user(session, stanza) local function verify_user(session, stanza)
log("debug", "Session token: %s, session room: %s", log("debug", "Session token: %s, session room: %s",
tostring(session.auth_token), tostring(session.auth_token),
@ -49,7 +50,7 @@ local function verify_user(session, stanza)
local user_jid = stanza.attr.from; local user_jid = stanza.attr.from;
if is_admin(user_jid) then if is_admin(user_jid) then
log("debug", "Token not required from admin user: %s", user_jid); log("debug", "Token not required from admin user: %s", user_jid);
return nil; return true;
end end
log("debug", log("debug",
@ -64,18 +65,23 @@ local function verify_user(session, stanza)
end end
log("debug", log("debug",
"allowed: %s to enter/create room: %s", user_jid, stanza.attr.to); "allowed: %s to enter/create room: %s", user_jid, stanza.attr.to);
return true;
end end
module:hook("muc-room-pre-create", function(event) module:hook("muc-room-pre-create", function(event)
local origin, stanza = event.origin, event.stanza; local origin, stanza = event.origin, event.stanza;
log("debug", "pre create: %s %s", tostring(origin), tostring(stanza)); log("debug", "pre create: %s %s", tostring(origin), tostring(stanza));
return verify_user(origin, stanza); if not verify_user(origin, stanza) then
return true; -- Returning any value other than nil will halt processing of the event
end
end); end);
module:hook("muc-occupant-pre-join", function(event) module:hook("muc-occupant-pre-join", function(event)
local origin, room, stanza = event.origin, event.room, event.stanza; local origin, room, stanza = event.origin, event.room, event.stanza;
log("debug", "pre join: %s %s", tostring(room), tostring(stanza)); log("debug", "pre join: %s %s", tostring(room), tostring(stanza));
return verify_user(origin, stanza); if not verify_user(origin, stanza) then
return true; -- Returning any value other than nil will halt processing of the event
end
end); end);
for event_name, method in pairs { for event_name, method in pairs {