Mercurial > prosody-hg
comparison util/prosodyctl.lua @ 3294:89dd67cc3689
util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 29 Jun 2010 19:18:07 +0100 |
| parents | 692b3c6c5bd2 |
| children | 3d7acda82eed |
comparison
equal
deleted
inserted
replaced
| 3293:4ce9d569a99c | 3294:89dd67cc3689 |
|---|---|
| 19 local io, os = io, os; | 19 local io, os = io, os; |
| 20 local tostring, tonumber = tostring, tonumber; | 20 local tostring, tonumber = tostring, tonumber; |
| 21 | 21 |
| 22 local CFG_SOURCEDIR = _G.CFG_SOURCEDIR; | 22 local CFG_SOURCEDIR = _G.CFG_SOURCEDIR; |
| 23 | 23 |
| 24 local prosody = prosody; | |
| 25 | |
| 24 module "prosodyctl" | 26 module "prosodyctl" |
| 25 | 27 |
| 26 function adduser(params) | 28 function adduser(params) |
| 27 local user, host, password = nodeprep(params.user), nameprep(params.host), params.password; | 29 local user, host, password = nodeprep(params.user), nameprep(params.host), params.password; |
| 28 if not user then | 30 if not user then |
| 29 return false, "invalid-username"; | 31 return false, "invalid-username"; |
| 30 elseif not host then | 32 elseif not host then |
| 31 return false, "invalid-hostname"; | 33 return false, "invalid-hostname"; |
| 34 end | |
| 35 | |
| 36 local provider = prosody.hosts[host].users; | |
| 37 if not(provider) or provider.name == "null" then | |
| 38 usermanager.initialize_host(host); | |
| 32 end | 39 end |
| 33 | 40 |
| 34 local ok = usermanager.create_user(user, password, host); | 41 local ok = usermanager.create_user(user, password, host); |
| 35 if not ok then | 42 if not ok then |
| 36 return false, "unable-to-save-data"; | 43 return false, "unable-to-save-data"; |
| 37 end | 44 end |
| 38 return true; | 45 return true; |
| 39 end | 46 end |
| 40 | 47 |
| 41 function user_exists(params) | 48 function user_exists(params) |
| 49 local provider = prosody.hosts[host].users; | |
| 50 if not(provider) or provider.name == "null" then | |
| 51 usermanager.initialize_host(host); | |
| 52 end | |
| 53 | |
| 42 return usermanager.user_exists(params.user, params.host); | 54 return usermanager.user_exists(params.user, params.host); |
| 43 end | 55 end |
| 44 | 56 |
| 45 function passwd(params) | 57 function passwd(params) |
| 46 if not _M.user_exists(params) then | 58 if not _M.user_exists(params) then |
