Software /
code /
prosody
Comparison
plugins/mod_register.lua @ 5096:50a64fd79c07
mod_register: Remove all account cleanup
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 25 Aug 2012 01:27:23 +0200 |
parent | 5014:b2006c1cfa85 |
child | 5098:fca8b5946f6f |
comparison
equal
deleted
inserted
replaced
5095:dddbcd62183a | 5096:50a64fd79c07 |
---|---|
93 :tag("username"):text(session.username):up() | 93 :tag("username"):text(session.username):up() |
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 -- TODO delete user auth data, send iq response, kick all user resources with a <not-authorized/>, delete all user data | |
99 local username, host = session.username, session.host; | 98 local username, host = session.username, session.host; |
100 | 99 |
101 local ok, err = usermanager_delete_user(username, host); | 100 local ok, err = usermanager_delete_user(username, host); |
102 | 101 |
103 if not ok then | 102 if not ok then |
105 session.send(st.error_reply(stanza, "cancel", "service-unavailable", err)); | 104 session.send(st.error_reply(stanza, "cancel", "service-unavailable", err)); |
106 return true; | 105 return true; |
107 end | 106 end |
108 | 107 |
109 session.send(st.reply(stanza)); | 108 session.send(st.reply(stanza)); |
110 local roster = session.roster; | |
111 for _, session in pairs(hosts[host].sessions[username].sessions) do -- disconnect all resources | |
112 session:close({condition = "not-authorized", text = "Account deleted"}); | |
113 end | |
114 -- TODO datamanager should be able to delete all user data itself | |
115 datamanager.store(username, host, "vcard", nil); | |
116 datamanager.store(username, host, "private", nil); | |
117 datamanager.store(username, host, "account_details", nil); | |
118 datamanager.list_store(username, host, "offline", nil); | |
119 local bare = username.."@"..host; | |
120 for jid, item in pairs(roster) do | |
121 if jid and jid ~= "pending" then | |
122 if item.subscription == "both" or item.subscription == "from" or (roster.pending and roster.pending[jid]) then | |
123 module:send(st.presence({type="unsubscribed", from=bare, to=jid})); | |
124 end | |
125 if item.subscription == "both" or item.subscription == "to" or item.ask then | |
126 module:send(st.presence({type="unsubscribe", from=bare, to=jid})); | |
127 end | |
128 end | |
129 end | |
130 datamanager.store(username, host, "roster", nil); | |
131 datamanager.store(username, host, "privacy", nil); | |
132 module:log("info", "User removed their account: %s@%s", username, host); | 109 module:log("info", "User removed their account: %s@%s", username, host); |
133 module:fire_event("user-deregistered", { username = username, host = host, source = "mod_register", session = session }); | 110 module:fire_event("user-deregistered", { username = username, host = host, source = "mod_register", session = session }); |
134 else | 111 else |
135 local username = nodeprep(query:get_child("username"):get_text()); | 112 local username = nodeprep(query:get_child("username"):get_text()); |
136 local password = query:get_child("password"):get_text(); | 113 local password = query:get_child("password"):get_text(); |