aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_telnet.lua15
-rw-r--r--plugins/mod_storage_internal.lua4
-rw-r--r--plugins/mod_storage_sql.lua17
3 files changed, 22 insertions, 14 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua
index bdd6e87e..62fb10a0 100644
--- a/plugins/mod_admin_telnet.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -227,7 +227,7 @@ function commands.help(session, data)
elseif section == "user" then
print [[user:create(jid, password) - Create the specified user account]]
print [[user:password(jid, password) - Set the password for the specified user account]]
- print [[user:delete(jid, password) - Permanently remove the specified user account]]
+ print [[user:delete(jid) - Permanently remove the specified user account]]
elseif section == "server" then
print [[server:version() - Show the server's version number]]
print [[server:uptime() - Show how long the server has been running]]
@@ -915,6 +915,9 @@ local um = require"core.usermanager";
def_env.user = {};
function def_env.user:create(jid, password)
local username, host = jid_split(jid);
+ if um.user_exists(username, host) then
+ return nil, "User exists";
+ end
local ok, err = um.create_user(username, password, host);
if ok then
return true, "User created";
@@ -925,6 +928,9 @@ end
function def_env.user:delete(jid)
local username, host = jid_split(jid);
+ if not um.user_exists(username, host) then
+ return nil, "No such user";
+ end
local ok, err = um.delete_user(username, host);
if ok then
return true, "User deleted";
@@ -933,11 +939,14 @@ function def_env.user:delete(jid)
end
end
-function def_env.user:passwd(jid, password)
+function def_env.user:password(jid, password)
local username, host = jid_split(jid);
+ if not um.user_exists(username, host) then
+ return nil, "No such user";
+ end
local ok, err = um.set_password(username, password, host);
if ok then
- return true, "User created";
+ return true, "User password changed";
else
return nil, "Could not change password for user: "..err;
end
diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua
index 75f6ec4e..039202dd 100644
--- a/plugins/mod_storage_internal.lua
+++ b/plugins/mod_storage_internal.lua
@@ -16,8 +16,8 @@ function driver:set(user, data)
return datamanager.store(user, host, self.store, data);
end
-function driver:list_stores(username)
- return datamanager.list_stores(username, host);
+function driver:stores(username)
+ return datamanager.stores(username, host);
end
function driver:purge(user)
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index ebc337bf..c9a45fca 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -374,10 +374,9 @@ function driver:open(store, typ)
return nil, "unsupported-store";
end
-function driver:list_stores(username) -- Not to be confused with the list store type
- local sql = (username == true
- and "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`!=?"
- or "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`=?");
+function driver:stores(username)
+ local sql = "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`" ..
+ (username == true and "!=?" or "=?");
if username == true or not username then
username = "";
end
@@ -385,11 +384,11 @@ function driver:list_stores(username) -- Not to be confused with the list store
if not stmt then
return rollback(nil, err);
end
- local stores = {};
- for row in stmt:rows() do
- stores[#stores+1] = row[1];
- end
- return commit(stores);
+ local next = stmt:rows();
+ return commit(function()
+ local row = next();
+ return row and row[1];
+ end);
end
function driver:purge(username)