10 local hosts = _G.hosts; |
10 local hosts = _G.hosts; |
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 datamanager_store = require "util.datamanager".store; |
16 local datamanager_store = require "util.datamanager".store; |
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 |
19 |
19 module:add_feature("jabber:iq:register"); |
20 module:add_feature("jabber:iq:register"); |
32 if query.tags[1] and query.tags[1].name == "remove" then |
33 if query.tags[1] and query.tags[1].name == "remove" then |
33 -- TODO delete user auth data, send iq response, kick all user resources with a <not-authorized/>, delete all user data |
34 -- TODO delete user auth data, send iq response, kick all user resources with a <not-authorized/>, delete all user data |
34 local username, host = session.username, session.host; |
35 local username, host = session.username, session.host; |
35 --session.send(st.error_reply(stanza, "cancel", "not-allowed")); |
36 --session.send(st.error_reply(stanza, "cancel", "not-allowed")); |
36 --return; |
37 --return; |
37 usermanager_create_user(username, nil, host); -- Disable account |
38 usermanager_set_password(username, host, nil); -- Disable account |
38 -- FIXME the disabling currently allows a different user to recreate the account |
39 -- FIXME the disabling currently allows a different user to recreate the account |
39 -- we should add an in-memory account block mode when we have threading |
40 -- we should add an in-memory account block mode when we have threading |
40 session.send(st.reply(stanza)); |
41 session.send(st.reply(stanza)); |
41 local roster = session.roster; |
42 local roster = session.roster; |
42 for _, session in pairs(hosts[host].sessions[username].sessions) do -- disconnect all resources |
43 for _, session in pairs(hosts[host].sessions[username].sessions) do -- disconnect all resources |
67 if username and password then |
68 if username and password then |
68 -- FIXME shouldn't use table.concat |
69 -- FIXME shouldn't use table.concat |
69 username = nodeprep(table.concat(username)); |
70 username = nodeprep(table.concat(username)); |
70 password = table.concat(password); |
71 password = table.concat(password); |
71 if username == session.username then |
72 if username == session.username then |
72 if usermanager_create_user(username, password, session.host) then -- password change -- TODO is this the right way? |
73 if usermanager_set_password(username, session.host, password) then |
73 session.send(st.reply(stanza)); |
74 session.send(st.reply(stanza)); |
74 else |
75 else |
75 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
76 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
76 session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
77 session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
77 end |
78 end |