Mercurial > prosody-modules
diff mod_auth_external/mod_auth_external.lua @ 816:960007b0901e
mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 13 Sep 2012 00:17:42 +0500 |
parents | 881ec9919144 |
children | 5ddc43ce8993 |
line wrap: on
line diff
--- a/mod_auth_external/mod_auth_external.lua Wed Sep 12 19:15:45 2012 +0000 +++ b/mod_auth_external/mod_auth_external.lua Thu Sep 13 00:17:42 2012 +0500 @@ -93,53 +93,50 @@ end end -function new_external_provider(host) - local provider = {}; - - function provider.test_password(username, password) - return do_query("auth", username, password); - end +local host = module.host; +local provider = {}; - function provider.set_password(username, password) - return do_query("setpass", username, password); - end - - function provider.user_exists(username) - return do_query("isuser", username); - end +function provider.test_password(username, password) + return do_query("auth", username, password); +end - function provider.create_user(username, password) return nil, "Account creation/modification not available."; end - - function provider.get_sasl_handler() - local testpass_authentication_profile = { - plain_test = function(sasl, username, password, realm) - local prepped_username = nodeprep(username); - if not prepped_username then - log("debug", "NODEprep failed on username: %s", username); - return "", nil; - end - return usermanager.test_password(prepped_username, realm, password), true; - end, - }; - return new_sasl(module.host, testpass_authentication_profile); - end +function provider.set_password(username, password) + return do_query("setpass", username, password); +end - function provider.is_admin(jid) - local admins = config.get(host, "core", "admins"); - if admins ~= config.get("*", "core", "admins") then - if type(admins) == "table" then - jid = jid_bare(jid); - for _,admin in ipairs(admins) do - if admin == jid then return true; end - end - elseif admins then - log("error", "Option 'admins' for host '%s' is not a table", host); - end - end - return usermanager.is_admin(jid); -- Test whether it's a global admin instead - end - - return provider; +function provider.user_exists(username) + return do_query("isuser", username); end -module:provides("auth", new_external_provider(module.host)); +function provider.create_user(username, password) return nil, "Account creation/modification not available."; end + +function provider.get_sasl_handler() + local testpass_authentication_profile = { + plain_test = function(sasl, username, password, realm) + local prepped_username = nodeprep(username); + if not prepped_username then + log("debug", "NODEprep failed on username: %s", username); + return "", nil; + end + return usermanager.test_password(prepped_username, realm, password), true; + end, + }; + return new_sasl(host, testpass_authentication_profile); +end + +function provider.is_admin(jid) + local admins = config.get(host, "core", "admins"); + if admins ~= config.get("*", "core", "admins") then + if type(admins) == "table" then + jid = jid_bare(jid); + for _,admin in ipairs(admins) do + if admin == jid then return true; end + end + elseif admins then + log("error", "Option 'admins' for host '%s' is not a table", host); + end + end + return usermanager.is_admin(jid); -- Test whether it's a global admin instead +end + +module:provides("auth", provider);