mod_component: Remove unused variable
[prosody.git] / core / usermanager.lua
index 2b060cc09b0df0c2ed2d9360fad0376a32a2d69e..9e5a016c5c0fa75640bfe60c87eb7a20f9d98c4e 100644 (file)
@@ -11,6 +11,7 @@ local log = require "util.logger".init("usermanager");
 local type = type;
 local ipairs = ipairs;
 local jid_bare = require "util.jid".bare;
+local jid_prep = require "util.jid".prep;
 local config = require "core.configmanager";
 local hosts = hosts;
 local sasl_new = require "util.sasl".new;
@@ -31,6 +32,8 @@ function new_null_provider()
        });
 end
 
+local provider_mt = { __index = new_null_provider() };
+
 function initialize_host(host)
        local host_session = hosts[host];
        if host_session.type ~= "local" then return; end
@@ -40,7 +43,7 @@ function initialize_host(host)
                local auth_provider = config.get(host, "core", "authentication") or default_provider;
                if config.get(host, "core", "anonymous_login") then auth_provider = "anonymous"; end -- COMPAT 0.7
                if provider.name == auth_provider then
-                       host_session.users = provider;
+                       host_session.users = setmetatable(provider, provider_mt);
                end
                if host_session.users ~= nil and host_session.users.name ~= nil then
                        log("debug", "host '%s' now set to use user provider '%s'", host, host_session.users.name);
@@ -81,6 +84,10 @@ function create_user(username, password, host)
        return hosts[host].users.create_user(username, password);
 end
 
+function delete_user(username, host)
+       return hosts[host].users.delete_user(username);
+end
+
 function get_sasl_handler(host)
        return hosts[host].users.get_sasl_handler();
 end
@@ -90,6 +97,9 @@ function get_provider(host)
 end
 
 function is_admin(jid, host)
+       if host and not hosts[host] then return false; end
+       if type(jid) ~= "string" then return false; end
+
        local is_admin;
        jid = jid_bare(jid);
        host = host or "*";
@@ -100,7 +110,7 @@ function is_admin(jid, host)
        if host_admins and host_admins ~= global_admins then
                if type(host_admins) == "table" then
                        for _,admin in ipairs(host_admins) do
-                               if admin == jid then
+                               if jid_prep(admin) == jid then
                                        is_admin = true;
                                        break;
                                end
@@ -113,7 +123,7 @@ function is_admin(jid, host)
        if not is_admin and global_admins then
                if type(global_admins) == "table" then
                        for _,admin in ipairs(global_admins) do
-                               if admin == jid then
+                               if jid_prep(admin) == jid then
                                        is_admin = true;
                                        break;
                                end