mod_c2s: Disconnect user sessions on a role change event

The overlapping logic for deletion and password changed has been merged into
a single function.
This commit is contained in:
Matthew Wild 2021-11-12 13:26:05 +00:00
parent 3315a2f616
commit 1a64d5d876

View file

@ -239,27 +239,25 @@ local function session_close(session, reason)
end end
end end
module:hook_global("user-deleted", function(event) -- Close all user sessions with the specified reason. If leave_resource is
local username, host = event.username, event.host; -- true, the resource named by event.resource will not be closed.
local user = hosts[host].sessions[username]; local function disconnect_user_sessions(reason, leave_resource)
if user and user.sessions then return function (event)
for _, session in pairs(user.sessions) do local username, host, resource = event.username, event.host, event.resource;
session:close{ condition = "not-authorized", text = "Account deleted" }; local user = hosts[host].sessions[username];
end if user and user.sessions then
end for r, session in pairs(user.sessions) do
end, 200); if not leave_resource or r ~= resource then
session:close(reason);
module:hook_global("user-password-changed", function(event) end
local username, host, resource = event.username, event.host, event.resource;
local user = hosts[host].sessions[username];
if user and user.sessions then
for r, session in pairs(user.sessions) do
if r ~= resource then
session:close{ condition = "reset", text = "Password changed" };
end end
end end
end end
end, 200); end
module:hook_global("user-password-changed", disconnect_user_sessions({ condition = "reset", text = "Password changed" }, true), 200);
module:hook_global("user-roles-changed", disconnect_user_sessions({ condition = "reset", text = "Roles changed" }), 200);
module:hook_global("user-deleted", disconnect_user_sessions({ condition = "not-authorized", text = "Account deleted" }), 200);
function runner_callbacks:ready() function runner_callbacks:ready()
if self.data.conn then if self.data.conn then