Comparison

core/usermanager.lua @ 5042:ce823b32225e

usermanager: Add method for deleting a user
author Kim Alvefur <zash@zash.se>
date Sat, 28 Jul 2012 21:55:05 +0200
parent 4943:50f63f07245f
child 5094:e646c849d72f
comparison
equal deleted inserted replaced
5041:be204204cc5f 5042:ce823b32225e
8 8
9 local modulemanager = require "core.modulemanager"; 9 local modulemanager = require "core.modulemanager";
10 local log = require "util.logger".init("usermanager"); 10 local log = require "util.logger".init("usermanager");
11 local type = type; 11 local type = type;
12 local ipairs = ipairs; 12 local ipairs = ipairs;
13 local pairs = pairs;
13 local jid_bare = require "util.jid".bare; 14 local jid_bare = require "util.jid".bare;
14 local jid_prep = require "util.jid".prep; 15 local jid_prep = require "util.jid".prep;
15 local config = require "core.configmanager"; 16 local config = require "core.configmanager";
16 local hosts = hosts; 17 local hosts = hosts;
17 local sasl_new = require "util.sasl".new; 18 local sasl_new = require "util.sasl".new;
19 local storagemanager = require "core.storagemanager";
18 20
19 local prosody = _G.prosody; 21 local prosody = _G.prosody;
20 22
21 local setmetatable = setmetatable; 23 local setmetatable = setmetatable;
22 24
86 function create_user(username, password, host) 88 function create_user(username, password, host)
87 return hosts[host].users.create_user(username, password); 89 return hosts[host].users.create_user(username, password);
88 end 90 end
89 91
90 function delete_user(username, host) 92 function delete_user(username, host)
91 return hosts[host].users.delete_user(username); 93 local user = hosts[host].sessions[username];
94 if user and user.sessions then
95 for jid, session in pairs(user.sessions) do
96 session:close{ condition = "not-authorized", text = "Account deleted" };
97 end
98 end
99 local ok, err = hosts[host].users.delete_user(username);
100 if not ok then return nil, err; end
101 return storagemanager.get_driver(host):purge(username);
92 end 102 end
93 103
94 function get_sasl_handler(host, session) 104 function get_sasl_handler(host, session)
95 return hosts[host].users.get_sasl_handler(session); 105 return hosts[host].users.get_sasl_handler(session);
96 end 106 end