Software /
code /
prosody
Comparison
plugins/mod_register.lua @ 5098:fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 25 Aug 2012 01:29:38 +0200 |
parent | 5096:50a64fd79c07 |
child | 5165:39bb9344f194 |
comparison
equal
deleted
inserted
replaced
5097:6c52a7a881cc | 5098:fca8b5946f6f |
---|---|
94 :tag("password"):up(); | 94 :tag("password"):up(); |
95 session.send(reply); | 95 session.send(reply); |
96 else -- stanza.attr.type == "set" | 96 else -- stanza.attr.type == "set" |
97 if query.tags[1] and query.tags[1].name == "remove" then | 97 if query.tags[1] and query.tags[1].name == "remove" then |
98 local username, host = session.username, session.host; | 98 local username, host = session.username, session.host; |
99 | |
100 local old_session_close = session.close; | |
101 session.close = function(session, ...) | |
102 session.send(st.reply(stanza)); | |
103 return old_session_close(session, ...); | |
104 end | |
99 | 105 |
100 local ok, err = usermanager_delete_user(username, host); | 106 local ok, err = usermanager_delete_user(username, host); |
101 | 107 |
102 if not ok then | 108 if not ok then |
103 module:log("debug", "Removing user account %s@%s failed: %s", username, host, err); | 109 module:log("debug", "Removing user account %s@%s failed: %s", username, host, err); |
110 session.close = old_session_close; | |
104 session.send(st.error_reply(stanza, "cancel", "service-unavailable", err)); | 111 session.send(st.error_reply(stanza, "cancel", "service-unavailable", err)); |
105 return true; | 112 return true; |
106 end | 113 end |
107 | 114 |
108 session.send(st.reply(stanza)); | |
109 module:log("info", "User removed their account: %s@%s", username, host); | 115 module:log("info", "User removed their account: %s@%s", username, host); |
110 module:fire_event("user-deregistered", { username = username, host = host, source = "mod_register", session = session }); | 116 module:fire_event("user-deregistered", { username = username, host = host, source = "mod_register", session = session }); |
111 else | 117 else |
112 local username = nodeprep(query:get_child("username"):get_text()); | 118 local username = nodeprep(query:get_child("username"):get_text()); |
113 local password = query:get_child("password"):get_text(); | 119 local password = query:get_child("password"):get_text(); |