Mercurial > prosody-modules
comparison mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 169:b3a68e71b8a1
mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
author | Florian Zeitz < florob@babelmonkeys.de> |
---|---|
date | Thu, 10 Jun 2010 22:32:49 +0200 |
parents | 7a037cb5ab9e |
children | d15c7d86db11 |
comparison
equal
deleted
inserted
replaced
168:cd8492748985 | 169:b3a68e71b8a1 |
---|---|
1 -- Copyright (C) 2009 Florian Zeitz | 1 -- Copyright (C) 2009-2010 Florian Zeitz |
2 -- | 2 -- |
3 -- This file is MIT/X11 licensed. Please see the | 3 -- This file is MIT/X11 licensed. Please see the |
4 -- COPYING file in the source package for more information. | 4 -- COPYING file in the source package for more information. |
5 -- | 5 -- |
6 | 6 |
149 end | 149 end |
150 local fields = add_user_layout:data(data.form); | 150 local fields = add_user_layout:data(data.form); |
151 local username, host, resource = jid.split(fields.accountjid); | 151 local username, host, resource = jid.split(fields.accountjid); |
152 if (fields["password"] == fields["password-verify"]) and username and host and host == data.to then | 152 if (fields["password"] == fields["password-verify"]) and username and host and host == data.to then |
153 if usermanager_user_exists(username, host) then | 153 if usermanager_user_exists(username, host) then |
154 return { status = "error", error = { type = "cancel", condition = "conflict", message = "Account already exists" } }; | 154 return { status = "completed", error = { message = "Account already exists" } }; |
155 else | 155 else |
156 if usermanager_create_user(username, fields.password, host) then | 156 if usermanager_create_user(username, fields.password, host) then |
157 module:log("info", "Created new account " .. username.."@"..host); | 157 module:log("info", "Created new account " .. username.."@"..host); |
158 return { status = "completed", info = "Account successfully created" }; | 158 return { status = "completed", info = "Account successfully created" }; |
159 else | 159 else |
160 return { status = "error", error = { type = "wait", condition = "internal-server-error", | 160 return { status = "completed", error = { message = "Failed to write data to disk" } }; |
161 message = "Failed to write data to disk" } }; | |
162 end | 161 end |
163 end | 162 end |
164 else | 163 else |
165 module:log("debug", fields.accountjid .. " " .. fields.password .. " " .. fields["password-verify"]); | 164 module:log("debug", (fields.accountjid or "<nil>") .. " " .. (fields.password or "<nil>") .. " " |
166 return { status = "error", error = { type = "cancel", condition = "conflict", | 165 .. (fields["password-verify"] or "<nil>")); |
167 message = "Invalid data.\nPassword mismatch, or empty username" } }; | 166 return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } }; |
168 end | 167 end |
169 else | 168 else |
170 return { status = "executing", form = add_user_layout }, "executing"; | 169 return { status = "executing", form = add_user_layout }, "executing"; |
171 end | 170 end |
172 end | 171 end |
179 local fields = change_user_password_layout:data(data.form); | 178 local fields = change_user_password_layout:data(data.form); |
180 local username, host, resource = jid.split(fields.accountjid); | 179 local username, host, resource = jid.split(fields.accountjid); |
181 if usermanager_user_exists(username, host) and usermanager_set_password(username, host, fields.password) then | 180 if usermanager_user_exists(username, host) and usermanager_set_password(username, host, fields.password) then |
182 return { status = "completed", info = "Password successfully changed" }; | 181 return { status = "completed", info = "Password successfully changed" }; |
183 else | 182 else |
184 return { status = "error", error = { type = "cancel", condition = "item-not-found", message = "User does not exist" } }; | 183 return { status = "completed", error = { message = "User does not exist" } }; |
185 end | 184 end |
186 else | 185 else |
187 return { status = "executing", form = change_user_password_layout }, "executing"; | 186 return { status = "executing", form = change_user_password_layout }, "executing"; |
188 end | 187 end |
189 end | 188 end |
256 local password = ""; | 255 local password = ""; |
257 if usermanager_user_exists(user, host) then | 256 if usermanager_user_exists(user, host) then |
258 accountjid = fields.accountjid; | 257 accountjid = fields.accountjid; |
259 password = usermanager_get_password(user, host); | 258 password = usermanager_get_password(user, host); |
260 else | 259 else |
261 return { status = "error", error = { type = "cancel", condition = "item-not-found", message = "User does not exist" } }; | 260 return { status = "completed", error = { message = "User does not exist" } }; |
262 end | 261 end |
263 return { status = "completed", result = { layout = get_user_password_result_layout, data = {accountjid = accountjid, password = password} } }; | 262 return { status = "completed", result = { layout = get_user_password_result_layout, data = {accountjid = accountjid, password = password} } }; |
264 else | 263 else |
265 return { status = "executing", form = get_user_password_layout }, "executing"; | 264 return { status = "executing", form = get_user_password_layout }, "executing"; |
266 end | 265 end |
274 | 273 |
275 local fields = add_user_layout:data(data.form); | 274 local fields = add_user_layout:data(data.form); |
276 | 275 |
277 local user, host, resource = jid.split(fields.accountjid); | 276 local user, host, resource = jid.split(fields.accountjid); |
278 if not usermanager_user_exists(user, host) then | 277 if not usermanager_user_exists(user, host) then |
279 return { status = "error", error = { type = "cancel", condition = "item-not-found", message = "User does not exist" } }; | 278 return { status = "completed", error = { message = "User does not exist" } }; |
280 end | 279 end |
281 local roster = rm_load_roster(user, host); | 280 local roster = rm_load_roster(user, host); |
282 | 281 |
283 local query = st.stanza("query", { xmlns = "jabber:iq:roster" }); | 282 local query = st.stanza("query", { xmlns = "jabber:iq:roster" }); |
284 for jid in pairs(roster) do | 283 for jid in pairs(roster) do |
315 | 314 |
316 local fields = get_user_stats_layout:data(data.form); | 315 local fields = get_user_stats_layout:data(data.form); |
317 | 316 |
318 local user, host, resource = jid.split(fields.accountjid); | 317 local user, host, resource = jid.split(fields.accountjid); |
319 if not usermanager_user_exists(user, host) then | 318 if not usermanager_user_exists(user, host) then |
320 return { status = "error", error = { type = "cancel", condition = "item-not-found", message = "User does not exist" } }; | 319 return { status = "completed", error = { message = "User does not exist" } }; |
321 end | 320 end |
322 local roster = rm_load_roster(user, host); | 321 local roster = rm_load_roster(user, host); |
323 local rostersize = 0; | 322 local rostersize = 0; |
324 local IPs = ""; | 323 local IPs = ""; |
325 local resources = ""; | 324 local resources = ""; |