comparison mod_audit_user_accounts/mod_audit_user_accounts.lua @ 5745:628952e4ff47

mod_audit_user_accounts: Renamed from mod_audit_register
author Matthew Wild <mwild1@gmail.com>
date Thu, 30 Nov 2023 17:59:08 +0000
parents mod_audit_register/mod_audit_register.lua@b4607c5dfcac
children
comparison
equal deleted inserted replaced
5744:b4607c5dfcac 5745:628952e4ff47
1 module:depends("audit");
2 -- luacheck: read globals module.audit
3
4 local dt = require "util.datetime";
5 local jid = require "util.jid";
6 local st = require "util.stanza";
7
8 local function audit_basic_event(name, custom_handler)
9 module:hook(name, function (event)
10 local custom;
11 if custom_handler then
12 custom = custom_handler(event);
13 end
14 module:audit(jid.join(event.username, module.host), name, {
15 session = event.session;
16 custom = custom;
17 });
18 end);
19 end
20
21 audit_basic_event("user-registered", function (event)
22 local invite = event.validated_invite or (event.session and event.session.validated_invite);
23 if not invite then return; end
24 return {
25 st.stanza(
26 "invite-used",
27 {
28 xmlns = "xmpp:prosody.im/audit",
29 token = invite.token,
30 }
31 );
32 };
33 end);
34
35 audit_basic_event("user-deregistered-pending");
36 audit_basic_event("user-deregistered");
37
38 audit_basic_event("user-enabled");
39 audit_basic_event("user-disabled", function (event)
40 local meta = event.meta;
41 if not meta then return end
42
43 local meta_st = st.stanza("disabled", {
44 xmlns = "xmpp:prosody.im/audit";
45 reason = meta.reason;
46 when = meta.when and dt.datetime(meta.when) or nil;
47 });
48 if meta.comment then
49 meta_st:text_tag("comment", meta.comment);
50 end
51
52 return { meta_st };
53 end);