-function end_user_session_handler(self, data, state)
- local end_user_session_layout = dataforms_new{
- title = "Ending a User Session";
- instructions = "Fill out this form to end a user's session.";
-
- { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
- { name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) for which to end sessions" };
- };
-
- if state then
- if data.action == "cancel" then
- return { status = "canceled" };
- end
-
- local fields, err = end_user_session_layout:data(data.form);
- if err then
- return generate_error_message(err);
- end
- local failed = {};
- local succeeded = {};
- for _, aJID in ipairs(fields.accountjids) do
- local username, host, resource = jid.split(aJID);
- if (host == data.to) and usermanager_user_exists(username, host) and disconnect_user(aJID) then
- succeeded[#succeeded+1] = aJID;
- else
- failed[#failed+1] = aJID;
- end
- end
- return {status = "completed", info = (#succeeded ~= 0 and
- "The following accounts were successfully disconnected:\n"..t_concat(succeeded, "\n").."\n" or "")..
- (#failed ~= 0 and
- "The following accounts could not be disconnected:\n"..t_concat(failed, "\n") or "") };
- else
- return { status = "executing", form = end_user_session_layout }, "executing";
- end
-end
-