Mercurial > prosody-hg
comparison core/usermanager.lua @ 3030:2be7801474fb
usermanager: Fix for is_admin to work with the new auth provider architecture
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 07 May 2010 21:42:45 +0100 |
| parents | 9a8f942433c4 |
| children | 421890f3f247 |
comparison
equal
deleted
inserted
replaced
| 3029:0c7beabfed5b | 3030:2be7801474fb |
|---|---|
| 81 function provider.get_supported_methods() | 81 function provider.get_supported_methods() |
| 82 return {["PLAIN"] = true, ["DIGEST-MD5"] = true}; -- TODO this should be taken from the config | 82 return {["PLAIN"] = true, ["DIGEST-MD5"] = true}; -- TODO this should be taken from the config |
| 83 end | 83 end |
| 84 | 84 |
| 85 function provider.is_admin(jid) | 85 function provider.is_admin(jid) |
| 86 host = host or "*"; | |
| 87 local admins = config.get(host, "core", "admins"); | 86 local admins = config.get(host, "core", "admins"); |
| 88 if host ~= "*" and admins == config.get("*", "core", "admins") then | 87 if admins ~= config.get("*", "core", "admins") and type(admins) == "table" then |
| 89 return nil; | |
| 90 end | |
| 91 if type(admins) == "table" then | |
| 92 jid = jid_bare(jid); | 88 jid = jid_bare(jid); |
| 93 for _,admin in ipairs(admins) do | 89 for _,admin in ipairs(admins) do |
| 94 if admin == jid then return true; end | 90 if admin == jid then return true; end |
| 95 end | 91 end |
| 96 elseif admins then | 92 elseif admins then |
| 97 log("warn", "Option 'admins' for host '%s' is not a table", host); | 93 log("warn", "Option 'admins' for host '%s' is not a table", host); |
| 98 end | 94 end |
| 99 return nil; | 95 return is_admin(jid); -- Test whether it's a global admin instead |
| 100 end | 96 end |
| 101 return provider; | 97 return provider; |
| 102 end | 98 end |
| 103 | 99 |
| 104 function validate_credentials(host, username, password, method) | 100 function validate_credentials(host, username, password, method) |
| 124 function get_supported_methods(host) | 120 function get_supported_methods(host) |
| 125 return hosts[host].users.get_supported_methods(); | 121 return hosts[host].users.get_supported_methods(); |
| 126 end | 122 end |
| 127 | 123 |
| 128 function is_admin(jid, host) | 124 function is_admin(jid, host) |
| 129 return hosts[host].users.is_admin(jid); | 125 if host and host ~= "*" then |
| 126 return hosts[host].users.is_admin(jid); | |
| 127 else -- Test only whether this JID is a global admin | |
| 128 local admins = config.get("*", "core", "admins"); | |
| 129 if type(admins) == "table" then | |
| 130 jid = jid_bare(jid); | |
| 131 for _,admin in ipairs(admins) do | |
| 132 if admin == jid then return true; end | |
| 133 end | |
| 134 elseif admins then | |
| 135 log("warn", "Option 'admins' for host '%s' is not a table", host); | |
| 136 end | |
| 137 return nil; | |
| 138 end | |
| 130 end | 139 end |
| 131 | 140 |
| 132 return _M; | 141 return _M; |
