Software / code / prosody
Comparison
plugins/mod_register.lua @ 3996:7f35b292531b
mod_register: Change to use new delete_user auth provider method
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 04 Jan 2011 17:19:39 +0000 |
| parent | 3995:e504b06492c6 |
| child | 3997:678e0688c18c |
comparison
equal
deleted
inserted
replaced
| 3995:e504b06492c6 | 3996:7f35b292531b |
|---|---|
| 11 local st = require "util.stanza"; | 11 local st = require "util.stanza"; |
| 12 local datamanager = require "util.datamanager"; | 12 local datamanager = require "util.datamanager"; |
| 13 local usermanager_user_exists = require "core.usermanager".user_exists; | 13 local usermanager_user_exists = require "core.usermanager".user_exists; |
| 14 local usermanager_create_user = require "core.usermanager".create_user; | 14 local usermanager_create_user = require "core.usermanager".create_user; |
| 15 local usermanager_set_password = require "core.usermanager".set_password; | 15 local usermanager_set_password = require "core.usermanager".set_password; |
| 16 local usermanager_delete_user = require "core.usermanager".delete_user; | |
| 16 local os_time = os.time; | 17 local os_time = os.time; |
| 17 local nodeprep = require "util.encodings".stringprep.nodeprep; | 18 local nodeprep = require "util.encodings".stringprep.nodeprep; |
| 18 local jid_bare = require "util.jid".bare; | 19 local jid_bare = require "util.jid".bare; |
| 19 | 20 |
| 20 local compat = module:get_option_boolean("registration_compat", true); | 21 local compat = module:get_option_boolean("registration_compat", true); |
| 34 session.send(reply); | 35 session.send(reply); |
| 35 else -- stanza.attr.type == "set" | 36 else -- stanza.attr.type == "set" |
| 36 if query.tags[1] and query.tags[1].name == "remove" then | 37 if query.tags[1] and query.tags[1].name == "remove" then |
| 37 -- TODO delete user auth data, send iq response, kick all user resources with a <not-authorized/>, delete all user data | 38 -- TODO delete user auth data, send iq response, kick all user resources with a <not-authorized/>, delete all user data |
| 38 local username, host = session.username, session.host; | 39 local username, host = session.username, session.host; |
| 39 --session.send(st.error_reply(stanza, "cancel", "not-allowed")); | 40 |
| 40 --return; | 41 local ok, err = usermanager_delete_user(username, host); |
| 41 usermanager_set_password(username, nil, host); -- Disable account | 42 |
| 42 -- FIXME the disabling currently allows a different user to recreate the account | 43 if not ok then |
| 43 -- we should add an in-memory account block mode when we have threading | 44 module:log("debug", "Removing user account %s@%s failed: %s", username, host, err); |
| 45 session.send(st.error_reply(stanza, "cancel", "service-unavailable", err)); | |
| 46 return true; | |
| 47 end | |
| 48 | |
| 44 session.send(st.reply(stanza)); | 49 session.send(st.reply(stanza)); |
| 45 local roster = session.roster; | 50 local roster = session.roster; |
| 46 for _, session in pairs(hosts[host].sessions[username].sessions) do -- disconnect all resources | 51 for _, session in pairs(hosts[host].sessions[username].sessions) do -- disconnect all resources |
| 47 session:close({condition = "not-authorized", text = "Account deleted"}); | 52 session:close({condition = "not-authorized", text = "Account deleted"}); |
| 48 end | 53 end |
| 61 end | 66 end |
| 62 end | 67 end |
| 63 end | 68 end |
| 64 datamanager.store(username, host, "roster", nil); | 69 datamanager.store(username, host, "roster", nil); |
| 65 datamanager.store(username, host, "privacy", nil); | 70 datamanager.store(username, host, "privacy", nil); |
| 66 datamanager.store(username, host, "accounts", nil); -- delete accounts datastore at the end | |
| 67 module:log("info", "User removed their account: %s@%s", username, host); | 71 module:log("info", "User removed their account: %s@%s", username, host); |
| 68 module:fire_event("user-deregistered", { username = username, host = host, source = "mod_register", session = session }); | 72 module:fire_event("user-deregistered", { username = username, host = host, source = "mod_register", session = session }); |
| 69 else | 73 else |
| 70 local username = query:child_with_name("username"); | 74 local username = query:child_with_name("username"); |
| 71 local password = query:child_with_name("password"); | 75 local password = query:child_with_name("password"); |
| 178 end | 182 end |
| 179 end | 183 end |
| 180 end | 184 end |
| 181 return true; | 185 return true; |
| 182 end); | 186 end); |
| 183 |