Comparison

core/usermanager.lua @ 3992:73075b004e77

usermanager: Have methods not implemented in the active provider fall back to the null provider (later we can add support for chains of providers)
author Matthew Wild <mwild1@gmail.com>
date Tue, 04 Jan 2011 17:11:37 +0000
parent 3991:2b86d7705f4e
child 3993:b71e5ecc694b
comparison
equal deleted inserted replaced
3991:2b86d7705f4e 3992:73075b004e77
29 return setmetatable({name = "null", get_sasl_handler = dummy_get_sasl_handler}, { 29 return setmetatable({name = "null", get_sasl_handler = dummy_get_sasl_handler}, {
30 __index = function(self, method) return dummy; end 30 __index = function(self, method) return dummy; end
31 }); 31 });
32 end 32 end
33 33
34 local provider_mt = { __index = new_null_provider() };
35
34 function initialize_host(host) 36 function initialize_host(host)
35 local host_session = hosts[host]; 37 local host_session = hosts[host];
36 if host_session.type ~= "local" then return; end 38 if host_session.type ~= "local" then return; end
37 39
38 host_session.events.add_handler("item-added/auth-provider", function (event) 40 host_session.events.add_handler("item-added/auth-provider", function (event)
39 local provider = event.item; 41 local provider = event.item;
40 local auth_provider = config.get(host, "core", "authentication") or default_provider; 42 local auth_provider = config.get(host, "core", "authentication") or default_provider;
41 if config.get(host, "core", "anonymous_login") then auth_provider = "anonymous"; end -- COMPAT 0.7 43 if config.get(host, "core", "anonymous_login") then auth_provider = "anonymous"; end -- COMPAT 0.7
42 if provider.name == auth_provider then 44 if provider.name == auth_provider then
43 host_session.users = provider; 45 host_session.users = setmetatable(provider, provider_mt);
44 end 46 end
45 if host_session.users ~= nil and host_session.users.name ~= nil then 47 if host_session.users ~= nil and host_session.users.name ~= nil then
46 log("debug", "host '%s' now set to use user provider '%s'", host, host_session.users.name); 48 log("debug", "host '%s' now set to use user provider '%s'", host, host_session.users.name);
47 end 49 end
48 end); 50 end);