Software /
code /
prosody
Comparison
plugins/mod_register.lua @ 386:a47b6e8e133e
Account deletion support
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 23 Nov 2008 03:31:03 +0500 |
parent | 311:513bd52e8e19 |
child | 421:63be85693710 |
comparison
equal
deleted
inserted
replaced
385:c064117c9357 | 386:a47b6e8e133e |
---|---|
1 | 1 |
2 local st = require "util.stanza"; | 2 local st = require "util.stanza"; |
3 local usermanager_user_exists = require "core.usermanager".user_exists; | 3 local usermanager_user_exists = require "core.usermanager".user_exists; |
4 local usermanager_create_user = require "core.usermanager".create_user; | 4 local usermanager_create_user = require "core.usermanager".create_user; |
5 local datamanager_store = require "util.datamanager".store; | |
5 | 6 |
6 add_iq_handler("c2s", "jabber:iq:register", function (session, stanza) | 7 add_iq_handler("c2s", "jabber:iq:register", function (session, stanza) |
7 if stanza.tags[1].name == "query" then | 8 if stanza.tags[1].name == "query" then |
8 local query = stanza.tags[1]; | 9 local query = stanza.tags[1]; |
9 if stanza.attr.type == "get" then | 10 if stanza.attr.type == "get" then |
14 :tag("password"):up(); | 15 :tag("password"):up(); |
15 session.send(reply); | 16 session.send(reply); |
16 elseif stanza.attr.type == "set" then | 17 elseif stanza.attr.type == "set" then |
17 if query.tags[1] and query.tags[1].name == "remove" then | 18 if query.tags[1] and query.tags[1].name == "remove" then |
18 -- TODO delete user auth data, send iq response, kick all user resources with a <not-authorized/>, delete all user data | 19 -- TODO delete user auth data, send iq response, kick all user resources with a <not-authorized/>, delete all user data |
19 session.send(st.error_reply(stanza, "cancel", "not-allowed")); | 20 --session.send(st.error_reply(stanza, "cancel", "not-allowed")); |
21 --return; | |
22 usermanager_create_user(session.username, nil, session.host); -- Disable account | |
23 -- FIXME the disabling currently allows a different user to recreate the account | |
24 -- we should add an in-memory account block mode when we have threading | |
25 session.send(st.reply(stanza)); | |
26 local roster = session.roster; | |
27 for _, session in pairs(hosts[session.host].sessions[session.username].sessions) do -- disconnect all resources | |
28 session:disconnect({condition = "not-authorized", text = "Account deleted"}); | |
29 end | |
30 -- TODO datamanager should be able to delete all user data itself | |
31 datamanager.store(session.username, session.host, "roster", nil); | |
32 datamanager.store(session.username, session.host, "vCard", nil); | |
33 datamanager.store(session.username, session.host, "private", nil); | |
34 datamanager.store(session.username, session.host, "offline", nil); | |
35 local bare = session.username.."@"..session.host; | |
36 for jid, item in pairs(roster) do | |
37 if jid ~= "pending" then | |
38 if item.subscription == "both" or item.subscription == "to" then | |
39 -- TODO unsubscribe | |
40 end | |
41 if item.subscription == "both" or item.subscription == "from" then | |
42 -- TODO unsubscribe | |
43 end | |
44 end | |
45 end | |
46 datamanager.store(session.username, session.host, "accounts", nil); -- delete accounts datastore at the end | |
20 else | 47 else |
21 local username = query:child_with_name("username"); | 48 local username = query:child_with_name("username"); |
22 local password = query:child_with_name("password"); | 49 local password = query:child_with_name("password"); |
23 if username and password then | 50 if username and password then |
24 -- FIXME shouldn't use table.concat | 51 -- FIXME shouldn't use table.concat |