6 -- COPYING file in the source package for more information. |
6 -- COPYING file in the source package for more information. |
7 -- |
7 -- |
8 |
8 |
9 |
9 |
10 local st = require "util.stanza"; |
10 local st = require "util.stanza"; |
11 local datamanager = require "util.datamanager"; |
|
12 local dataform_new = require "util.dataforms".new; |
11 local dataform_new = require "util.dataforms".new; |
13 local usermanager_user_exists = require "core.usermanager".user_exists; |
12 local usermanager_user_exists = require "core.usermanager".user_exists; |
14 local usermanager_create_user = require "core.usermanager".create_user; |
13 local usermanager_create_user = require "core.usermanager".create_user; |
15 local usermanager_set_password = require "core.usermanager".set_password; |
14 local usermanager_set_password = require "core.usermanager".set_password; |
16 local usermanager_delete_user = require "core.usermanager".delete_user; |
15 local usermanager_delete_user = require "core.usermanager".delete_user; |
19 local jid_bare = require "util.jid".bare; |
18 local jid_bare = require "util.jid".bare; |
20 |
19 |
21 local compat = module:get_option_boolean("registration_compat", true); |
20 local compat = module:get_option_boolean("registration_compat", true); |
22 local allow_registration = module:get_option_boolean("allow_registration", false); |
21 local allow_registration = module:get_option_boolean("allow_registration", false); |
23 local additional_fields = module:get_option("additional_registration_fields", {}); |
22 local additional_fields = module:get_option("additional_registration_fields", {}); |
|
23 |
|
24 local account_details = module:open_store("account_details"); |
24 |
25 |
25 local field_map = { |
26 local field_map = { |
26 username = { name = "username", type = "text-single", label = "Username", required = true }; |
27 username = { name = "username", type = "text-single", label = "Username", required = true }; |
27 password = { name = "password", type = "text-private", label = "Password", required = true }; |
28 password = { name = "password", type = "text-private", label = "Password", required = true }; |
28 nick = { name = "nick", type = "text-single", label = "Nickname" }; |
29 nick = { name = "nick", type = "text-single", label = "Nickname" }; |
232 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists.")); |
233 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists.")); |
233 else |
234 else |
234 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
235 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
235 local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk."); |
236 local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk."); |
236 if usermanager_create_user(username, password, host) then |
237 if usermanager_create_user(username, password, host) then |
237 if next(data) and not datamanager.store(username, host, "account_details", data) then |
238 if next(data) and not account_details:set(username, data) then |
238 usermanager_delete_user(username, host); |
239 usermanager_delete_user(username, host); |
239 session.send(error_reply); |
240 session.send(error_reply); |
240 return true; |
241 return true; |
241 end |
242 end |
242 session.send(st.reply(stanza)); -- user created! |
243 session.send(st.reply(stanza)); -- user created! |