Comparison

mod_auth_any/mod_auth_any.lua @ 2438:a528627e45ab

mod_auth_any: Remove provider constructor, it's only called once anyways
author Kim Alvefur <zash@zash.se>
date Sun, 08 Jan 2017 11:27:01 +0100
parent 2437:75be377b74ea
child 2439:1f7820f68868
comparison
equal deleted inserted replaced
2437:75be377b74ea 2438:a528627e45ab
20 local nodeprep = require "util.encodings".stringprep.nodeprep; 20 local nodeprep = require "util.encodings".stringprep.nodeprep;
21 local hosts = hosts; 21 local hosts = hosts;
22 22
23 local prosody = _G.prosody; 23 local prosody = _G.prosody;
24 24
25 function new_default_provider(host) 25 local host = module.host;
26 local provider = { name = "any" }; 26 local provider = { name = "any" };
27 log("debug", "initializing default authentication provider for host '%s'", host);
28 27
29 function provider.test_password(username, password) 28 function provider.test_password(username, password)
30 return true; 29 return true;
31 end
32
33 function provider.set_password(username, password)
34 local account = datamanager.load(username, host, "accounts");
35 if account then
36 account.password = password;
37 return datamanager.store(username, host, "accounts", account);
38 end
39 return nil, "Account not available.";
40 end
41
42 function provider.user_exists(username)
43 return true;
44 end
45
46 function provider.create_user(username, password)
47 return datamanager.store(username, host, "accounts", {password = password});
48 end
49
50 function provider.delete_user(username)
51 return datamanager.store(username, host, "accounts", nil);
52 end
53
54 function provider.get_sasl_handler()
55 local getpass_authentication_profile = {
56 plain_test = function(sasl, username, password, realm)
57 return true, true;
58 end
59 };
60 return new_sasl(module.host, getpass_authentication_profile);
61 end
62
63 return provider;
64 end 30 end
65 31
66 module:add_item("auth-provider", new_default_provider(module.host)); 32 function provider.set_password(username, password)
33 local account = datamanager.load(username, host, "accounts");
34 if account then
35 account.password = password;
36 return datamanager.store(username, host, "accounts", account);
37 end
38 return nil, "Account not available.";
39 end
67 40
41 function provider.user_exists(username)
42 return true;
43 end
44
45 function provider.create_user(username, password)
46 return datamanager.store(username, host, "accounts", {password = password});
47 end
48
49 function provider.delete_user(username)
50 return datamanager.store(username, host, "accounts", nil);
51 end
52
53 function provider.get_sasl_handler()
54 local getpass_authentication_profile = {
55 plain_test = function(sasl, username, password, realm)
56 return true, true;
57 end
58 };
59 return new_sasl(module.host, getpass_authentication_profile);
60 end
61
62 module:add_item("auth-provider", provider);
63