Mercurial > prosody-hg
comparison core/usermanager.lua @ 6779:6236668da30a
core.*: Remove use of module() function
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 21 Feb 2015 10:42:19 +0100 |
| parents | d3023dd07cb6 |
| children | 0ce2b400663b |
comparison
equal
deleted
inserted
replaced
| 6778:4009ae66e0f0 | 6779:6236668da30a |
|---|---|
| 21 | 21 |
| 22 local setmetatable = setmetatable; | 22 local setmetatable = setmetatable; |
| 23 | 23 |
| 24 local default_provider = "internal_plain"; | 24 local default_provider = "internal_plain"; |
| 25 | 25 |
| 26 module "usermanager" | 26 local _ENV = nil; |
| 27 | 27 |
| 28 function new_null_provider() | 28 local function new_null_provider() |
| 29 local function dummy() return nil, "method not implemented"; end; | 29 local function dummy() return nil, "method not implemented"; end; |
| 30 local function dummy_get_sasl_handler() return sasl_new(nil, {}); end | 30 local function dummy_get_sasl_handler() return sasl_new(nil, {}); end |
| 31 return setmetatable({name = "null", get_sasl_handler = dummy_get_sasl_handler}, { | 31 return setmetatable({name = "null", get_sasl_handler = dummy_get_sasl_handler}, { |
| 32 __index = function(self, method) return dummy; end --luacheck: ignore 212 | 32 __index = function(self, method) return dummy; end --luacheck: ignore 212 |
| 33 }); | 33 }); |
| 34 end | 34 end |
| 35 | 35 |
| 36 local provider_mt = { __index = new_null_provider() }; | 36 local provider_mt = { __index = new_null_provider() }; |
| 37 | 37 |
| 38 function initialize_host(host) | 38 local function initialize_host(host) |
| 39 local host_session = hosts[host]; | 39 local host_session = hosts[host]; |
| 40 if host_session.type ~= "local" then return; end | 40 if host_session.type ~= "local" then return; end |
| 41 | 41 |
| 42 host_session.events.add_handler("item-added/auth-provider", function (event) | 42 host_session.events.add_handler("item-added/auth-provider", function (event) |
| 43 local provider = event.item; | 43 local provider = event.item; |
| 66 modulemanager.load(host, "auth_"..auth_provider); | 66 modulemanager.load(host, "auth_"..auth_provider); |
| 67 end | 67 end |
| 68 end; | 68 end; |
| 69 prosody.events.add_handler("host-activated", initialize_host, 100); | 69 prosody.events.add_handler("host-activated", initialize_host, 100); |
| 70 | 70 |
| 71 function test_password(username, host, password) | 71 local function test_password(username, host, password) |
| 72 return hosts[host].users.test_password(username, password); | 72 return hosts[host].users.test_password(username, password); |
| 73 end | 73 end |
| 74 | 74 |
| 75 function get_password(username, host) | 75 local function get_password(username, host) |
| 76 return hosts[host].users.get_password(username); | 76 return hosts[host].users.get_password(username); |
| 77 end | 77 end |
| 78 | 78 |
| 79 function set_password(username, password, host) | 79 local function set_password(username, password, host) |
| 80 return hosts[host].users.set_password(username, password); | 80 return hosts[host].users.set_password(username, password); |
| 81 end | 81 end |
| 82 | 82 |
| 83 function user_exists(username, host) | 83 local function user_exists(username, host) |
| 84 return hosts[host].users.user_exists(username); | 84 return hosts[host].users.user_exists(username); |
| 85 end | 85 end |
| 86 | 86 |
| 87 function create_user(username, password, host) | 87 local function create_user(username, password, host) |
| 88 return hosts[host].users.create_user(username, password); | 88 return hosts[host].users.create_user(username, password); |
| 89 end | 89 end |
| 90 | 90 |
| 91 function delete_user(username, host) | 91 local function delete_user(username, host) |
| 92 local ok, err = hosts[host].users.delete_user(username); | 92 local ok, err = hosts[host].users.delete_user(username); |
| 93 if not ok then return nil, err; end | 93 if not ok then return nil, err; end |
| 94 prosody.events.fire_event("user-deleted", { username = username, host = host }); | 94 prosody.events.fire_event("user-deleted", { username = username, host = host }); |
| 95 return storagemanager.purge(username, host); | 95 return storagemanager.purge(username, host); |
| 96 end | 96 end |
| 97 | 97 |
| 98 function users(host) | 98 local function users(host) |
| 99 return hosts[host].users.users(); | 99 return hosts[host].users.users(); |
| 100 end | 100 end |
| 101 | 101 |
| 102 function get_sasl_handler(host, session) | 102 local function get_sasl_handler(host, session) |
| 103 return hosts[host].users.get_sasl_handler(session); | 103 return hosts[host].users.get_sasl_handler(session); |
| 104 end | 104 end |
| 105 | 105 |
| 106 function get_provider(host) | 106 local function get_provider(host) |
| 107 return hosts[host].users; | 107 return hosts[host].users; |
| 108 end | 108 end |
| 109 | 109 |
| 110 function is_admin(jid, host) | 110 local function is_admin(jid, host) |
| 111 if host and not hosts[host] then return false; end | 111 if host and not hosts[host] then return false; end |
| 112 if type(jid) ~= "string" then return false; end | 112 if type(jid) ~= "string" then return false; end |
| 113 | 113 |
| 114 local is_admin; | 114 local is_admin; |
| 115 jid = jid_bare(jid); | 115 jid = jid_bare(jid); |
| 149 is_admin = hosts[host].users.is_admin(jid); | 149 is_admin = hosts[host].users.is_admin(jid); |
| 150 end | 150 end |
| 151 return is_admin or false; | 151 return is_admin or false; |
| 152 end | 152 end |
| 153 | 153 |
| 154 return _M; | 154 return { |
| 155 new_null_provider = new_null_provider; | |
| 156 initialize_host = initialize_host; | |
| 157 test_password = test_password; | |
| 158 get_password = get_password; | |
| 159 set_password = set_password; | |
| 160 user_exists = user_exists; | |
| 161 create_user = create_user; | |
| 162 delete_user = delete_user; | |
| 163 users = users; | |
| 164 get_sasl_handler = get_sasl_handler; | |
| 165 get_provider = get_provider; | |
| 166 is_admin = is_admin; | |
| 167 }; |
