comparison mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 110:e02281edc273

mod_adhoc_cmd_admin: Add Change User Password command
author Florian Zeitz <florob@babelmonkeys.de>
date Thu, 10 Dec 2009 21:23:52 +0100
parents 9b63fd1196c0
children a9898f13c89e
comparison
equal deleted inserted replaced
109:9b63fd1196c0 110:e02281edc273
28 28
29 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; 29 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
30 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" }; 30 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" };
31 { name = "password", type = "text-private", label = "The password for this account" }; 31 { name = "password", type = "text-private", label = "The password for this account" };
32 { name = "password-verify", type = "text-private", label = "Retype password" }; 32 { name = "password-verify", type = "text-private", label = "Retype password" };
33 };
34
35 local change_user_password_layout = dataforms_new{
36 title = "Changing a User Password";
37 instructions = "Fill out this form to change a user's password.";
38
39 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
40 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for this account" };
41 { name = "password", type = "text-private", required = true, label = "The password for this account" };
33 }; 42 };
34 43
35 local delete_user_layout = dataforms_new{ 44 local delete_user_layout = dataforms_new{
36 title = "Deleting a User"; 45 title = "Deleting a User";
37 instructions = "Fill out this form to delete a user."; 46 instructions = "Fill out this form to delete a user.";
114 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(add_user_layout:form()))); 123 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(add_user_layout:form())));
115 end 124 end
116 return true; 125 return true;
117 end 126 end
118 127
128 function change_user_password_command_handler(item, origin, stanza)
129 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then
130 if stanza.tags[1].attr.action == "cancel" then
131 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)));
132 sessions[stanza.tags[1].attr.sessionid] = nil;
133 return true;
134 end
135 local form = stanza.tags[1]:child_with_ns("jabber:x:data");
136 local fields = change_user_password_layout:data(form);
137 local username, host, resource = jid.split(fields.accountjid);
138 if usermanager_user_exists(username, host) and usermanager_create_user(username, fields.password, host) then
139 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", stanza.tags[1].attr.sessionid)
140 :tag("note", {type="info"})
141 :text("Password successfully changed")));
142 else
143 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "User does not exist")
144 :add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)
145 :tag("note", {type="error"}):text("User does not exist")));
146 end
147 sessions[stanza.tags[1].attr.sessionid] = nil;
148 return true;
149 else
150 local sessionid=uuid.generate();
151 sessions[sessionid] = "executing";
152 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(change_user_password_layout:form())));
153 end
154 return true;
155 end
156
119 function delete_user_command_handler(item, origin, stanza) 157 function delete_user_command_handler(item, origin, stanza)
120 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then 158 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then
121 if stanza.tags[1].attr.action == "cancel" then 159 if stanza.tags[1].attr.action == "cancel" then
122 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid))); 160 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)));
123 sessions[stanza.tags[1].attr.sessionid] = nil; 161 sessions[stanza.tags[1].attr.sessionid] = nil;
266 304
267 return true; 305 return true;
268 end 306 end
269 307
270 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); 308 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
309 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin");
271 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin"); 310 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
272 local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin"); 311 local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
273 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin"); 312 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin");
274 local announce_desc = adhoc_new("Send Announcement to Online Users", "http://jabber.org/protocol/admin#announce", announce_handler, "admin"); 313 local announce_desc = adhoc_new("Send Announcement to Online Users", "http://jabber.org/protocol/admin#announce", announce_handler, "admin");
275 314
276 module:add_item("adhoc", add_user_desc); 315 module:add_item("adhoc", add_user_desc);
316 module:add_item("adhoc", change_user_password_desc);
277 module:add_item("adhoc", delete_user_desc); 317 module:add_item("adhoc", delete_user_desc);
278 module:add_item("adhoc", get_user_password_desc); 318 module:add_item("adhoc", get_user_password_desc);
279 module:add_item("adhoc", get_online_users_desc); 319 module:add_item("adhoc", get_online_users_desc);
280 module:add_item("adhoc", announce_desc); 320 module:add_item("adhoc", announce_desc);