Browse Source

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.
master
damencho 4 years ago
parent
commit
0354dbe889
1 changed files with 9 additions and 3 deletions
  1. 9
    3
      resources/prosody-plugins/mod_token_verification.lua

+ 9
- 3
resources/prosody-plugins/mod_token_verification.lua View File

@@ -40,6 +40,7 @@ local function load_config()
40 40
 end
41 41
 load_config();
42 42
 
43
+-- verify user and whether he is allowed to join a room based on the token information
43 44
 local function verify_user(session, stanza)
44 45
 	log("debug", "Session token: %s, session room: %s",
45 46
 		tostring(session.auth_token),
@@ -49,7 +50,7 @@ local function verify_user(session, stanza)
49 50
 	local user_jid = stanza.attr.from;
50 51
 	if is_admin(user_jid) then
51 52
 		log("debug", "Token not required from admin user: %s", user_jid);
52
-		return nil;
53
+		return true;
53 54
 	end
54 55
 
55 56
     log("debug",
@@ -64,18 +65,23 @@ local function verify_user(session, stanza)
64 65
     end
65 66
 	log("debug",
66 67
         "allowed: %s to enter/create room: %s", user_jid, stanza.attr.to);
68
+    return true;
67 69
 end
68 70
 
69 71
 module:hook("muc-room-pre-create", function(event)
70 72
 	local origin, stanza = event.origin, event.stanza;
71 73
 	log("debug", "pre create: %s %s", tostring(origin), tostring(stanza));
72
-	return verify_user(origin, stanza);
74
+    if not verify_user(origin, stanza) then
75
+        return true; -- Returning any value other than nil will halt processing of the event
76
+    end
73 77
 end);
74 78
 
75 79
 module:hook("muc-occupant-pre-join", function(event)
76 80
 	local origin, room, stanza = event.origin, event.room, event.stanza;
77 81
 	log("debug", "pre join: %s %s", tostring(room), tostring(stanza));
78
-	return verify_user(origin, stanza);
82
+    if not verify_user(origin, stanza) then
83
+        return true; -- Returning any value other than nil will halt processing of the event
84
+    end
79 85
 end);
80 86
 
81 87
 for event_name, method in pairs {

Loading…
Cancel
Save